Practice Exercises For C++
Practice Exercises For C++
Task#1:
Write a C++ program, which ask for actual speed and speed limit of a car from user, and calculate the
over limit. Over limit should meet the following condition. Also draw a flowchart of the program as well.
If over limit greater than or equal to 25, then charge a fine of $215.
If over limit is less than 25 but not 0, then there is no charge for that.
Task#2:
Write a C++ Program, which takes the basic salary of an employee as input, and calculate the allowance,
house rent and gross salary. And display the gross salary of the employee by meeting following
conditions. Also draw flowchart of the program as well.
If the basic salary is greater than or equal to $4500, employee will get 15% allowance of the basic
salary and 12% house rent of the basic salary.
If the basic salary is less than $4500 but greater than $1500, employee will get 10% allowance of
the basic salary and 5% house rent of the basic salary.
If the basic salary is less than $1500, employee won’t get any allowance or house rent
.
PART#2 (LOOPING)
1 + 3 + 5 = 9 = 32
1 + 3 + 5 + 7 = 16 = 42
1 + 3 + 5 + 7 + 9 = 25 = 52
Task##4
Write a program segment (including a while loop) that reads one number into a variable named n and
reads another number into a variable called maxPower. Then your statements should raise n to each
power 0, 1, 2, ..., maxPower, and print a table like the following (suppose n is 2 and maxPower is 4)
SSSSS*
SSSS**
SSS***
SS****
S*****
PART#3 (ARRAY-ONE DIMENSIONAL)
Write a program that finds the total expenses for a week. There can be multiple items for a single day and
the numbers of items are unknown. The inner loop should iterate for the number of items for each day and
should terminate when there are no more items for that day. The outer loop should execute for the number
of days in a week. Take the item cost as input from the user and calculate the total after each day. Display
this total. Repeat this process for all week days. Calculate the weekly expenditure and display the week
total at the end. Output screen is shown below.
Write a program to enter three integers and output the smallest integer using Array. Output Screen is
shown below.
Task#8
C++ program ask to the user to enter the array size, then ask to enter the element of the
array to store the elements in the array, then finally display the array element on the screen:
Task#9
Read N One Dimensional Array Elements, and calculate the Sum and Product of all
elements and print the sum and product.
Task#10
read 10 elements of integer type using One Dimensional Array and replace all EVEN
elements by 0 and ODD by 1.
Task#11
read Two One Dimensional Array of same data type (integer type) and merge them into
another One Dimensional Array of same type.
Task#12
read two One Dimensional Array and create third One Dimensional Array by adding and
subtracting elements of inputted two One Dimensional Array elements.
Task#13
Write a c++ program to find a number from array elements.
Task#14
Write a C++ program to swap adjacent elements of one dimensional array.
Task#15
Write a c++ program to find occurrence of an element in one dimensional
array.
Task#16
Write a c++ program to delete given element from one dimensional array.
Task#17
Part(4)
TASK#18:
A Fibonacci number is a set in which each number is the sum of the previous two
numbers. The
series begins
0, 1, 1, 2, 3, 5, 8, 13, 21, ---
Write a C++ program that calculates and prints the next three numbers of this
series. Use only three
TASK#19:
Write a program using Switch that prepares marks sheet of a student. Take the
marks of five subjects as
input and find the total marks, percentage and the grade. Display all the
information. Follow the following
Less than 60 F
TASK#20:
Make a four function calculator using SWITCH statement. Read in two numbers
and a mathematical
operator. Add the two numbers if the operator ‘+’ is entered. Subtract the two
numbers if operator ‘-‘ is
entered and so on. Display the calculated result. If any character other than + , - ,
*, / is entered, display
proper error
message.
TASK#21:
Write a program to find the grace marks for a student USING SWITCH. The user
should enter the class
obtained by the student and the number of subjects he has failed in.
than 3, then
he does not get any grace. If the number of subjects he failed in is less than or
equal to 3
then he does not get any grace. If the number of subjects he failed in is less than
or equal to
he does not get any grace. If the number of subjects he failed in is equal to 1 then
the grace