FP in C++ Lab Excercise 1
FP in C++ Lab Excercise 1
Faculty of Informatics
1
Sample Output:
Display the operation of pre and post increment and decrement:
--------------------------------------------------------------------
The number is: 57
After post increment by 1 the number is: 58
After pre increment by 1 the number is: 59
After increasing by 1 the number is: 60
After post decrement by 1 the number is: 59
After pre decrement by 1 the number is: 58
After decreasing by 1 the number is: 57
6. Write a C++ program to add two numbers and accept them from the keyboard.
Sample Output:
Sum of two numbers:
-------------------------
Input 1st number: 25
Input 2nd number: 39
The sum of the numbers is: 64
7. Write a C++ program that swaps two numbers.
Sample Output:
Swap two numbers:
-----------------------
Input 1st number: 25
Input 2nd number: 39
After swapping the 1st number is: 39
After swapping the 2nd number is: 25
8. Write a C++ program that calculates the volume of a sphere, cube and cylinder. (hint: volsp =
4/3r3, Volcube = a*a*a=a3, Volcy = π*r2*height)
Sample Output:
Calculate the volume of a sphere, cube and cylinder:
---------------------------------------
Input the radius of a sphere: 6
2
Input the side of a cube: 5
Input the radius of the cylinder: 6
Input the height of the cylinder: 8
The volume of a sphere is: 904.32
The volume of a cube is: 125
The volume of a cylinder is: 904.32
9. Write a C++ program to compute the total and average of four numbers.
Sample Output:
Compute the total and average of four numbers:
----------------------------------------------------
Input 1st two numbers (separated by space): 25 20
Input last two numbers (separated by space): 15 25
The total of four numbers is: 85
The average of four numbers is: 21.25
10. Write a C++ program that accepts the user's first and last name and prints them in reverse order
with a space between them.
Sample Output:
Print the name in reverse where last name comes first:
-----------------------------------------------------------
Input First Name: Haileselassie
Input Last Name: Abdissa
Name in reverse is: Abdissa Haileselassie
11. Write a program to check whether the given number is positive or negative (using? : ternary
operator )?
12. Write a program to check whether the given number is even or odd (using ternary operator)?
13. Write a program to display the following output using a single cout statement.
Subject Marks
Mathematics 90
Computer 77
Chemistry 69