Fundamentals of Programming: Lab Practical Week 1 Objective
Fundamentals of Programming: Lab Practical Week 1 Objective
Fundamentals of Programming
Lab Practical week 1
Objective:
The install IDE and compile your first program.
First Program:
“Hello World”
Click on the File tab in top left corner and create new Source file.
Write the following code (always keep in mind that C++ is case-sensitive language, for
example if you typed Include instead of include the compiler will report error)
//HelloWorld.cpp
/* This is my first C++ program.
*/
#include <iostream>
using namespace std;
int main()
{
cout<<"Hello World";
}// End of Program
When you are done with code writing, compile and run the file by pressing F11.
A window will pop up, asking you to select place to save the file and give it name,
remember give name keeping in mind the working of program and add extension .cpp at
the end of program name. Click save and you will see the following
Exercise:
1. Try printing the following strings, what do they do?
1. "Hello \t World"
2. "Hello \n World"
Arithematic Operators
Arithmetic operators are the symbols that represent arithmetic math operations.
Examples include + (addition operator), - (subtraction operator), * (multiplication
operator), / (division operator) and %(remainder operator).
Program:
Program:
Result:
For taking input from user, first we declare variable(int a;) and then following command
takes input from user
cin>>a;
Exercise:
1. Make calculator performing addition, subtraction, multiplication, division and finding
remainder taking inputs from user.
2. Develop a temperature conversion program taking temperature in Fahrenheit and
converting it into Celsius.
++ (Increment)
-- (Decrement)
+= (Increment Assignment)
-= (Decrement Assignment)
*= (Multiplication Assignment)
/= (Division Assignment)
%= (Remainder Assignment)
Increment and Decrement operators can be used in two ways, i.e.
i) Prefix
ii) Postfix
Program
Relational Operators
A relational operator compares two values. Comparisons involved in relation operators
can be
i) < Less than
ii) > Greater than
iii) == Equals to
iv) != Not equals
v) <= Less than or equals
vi) >= Greater than or equals
The result of comparison is either True or False. If a comparison provides 1, it
means True and if it provides 0, it means False.
Program: