Lab 2
Lab 2
Popular IDE's include Code: Blocks, Eclipse, and Visual Studio. These are all free, and they
can be used to both edit and debug C++ code.
C++ Variables
In programming, a variable is a container (storage area) to hold data.
To indicate the storage area, each variable should be given a unique name (identifier)
int Integer 2 or 4
float Floating-point 4
char Character 1
Code Snippet 1:
Execute the following to print the statement :
int main() {
// prints the string enclosed in double quotes
cout << "This is C++ Programming";
return 0;
}
Code Snippet 2:
int main() {
int num1 = 70;
double num2 = 256.783;
char ch = 'A';
C++ Input
In C++, cin takes formatted input from standard input devices such as the keyboard. We use
the cin object along with the >> operator for taking input.
int main() {
int num;
cout << "Enter an integer: ";
cin >> num; // Taking input
cout << "The number is: " << num;
return 0;
}
Code Snippet 4:
int main() {
char a;
int num;
return 0;
}
Lab Tasks:
1. Store two integers in two variables x and y. Print the sum of the two.
2. Write a C++ program to take two integer inputs from user and print sum and product of
them.
3. Write a program to take input of length and breadth of a rectangle from the user and
print its area. (Area of rectangle=length× breadth)
4. Write a C++ program to calculate the area of a circle given its radius by using the
formulae:(Area=π×radius2)