Sample Questions
Sample Questions
(20 marks)
1. Construct a C++ program that prompts the user to enter two values for hourly rate and hours
worked. Calculate the gross pay by multiplying the hourly rate and hours worked. Also
calculate and display net pay, which is gross pay minus withholding.
Withholding is calculated as 28 % of gross pay if gross pay is over $1000, 21% of gross pay
if gross pay is not over $1000 but is over $600, and 10% of gross pay if gross pay is not over
$600.
2. Create a C++ program to check whether the given two numbers are an amical number or not.
The amicable numbers are two different numbers (a pair of numbers) that the sum of the proper
divisors (excluding the number itself) of one of the numbers is equal to the other number. For
example, the smallest pair of amical numbers is (220, 284). The divisor of 220 are: 1, 2, 4, 5,
10, 11, 20, 22, 44, 55, and 110. The sum of divisor of 220 is 284. The divisor of 284 are: 1, 2,
4, 71 and 142. The sum of divisor of 284 is 220. (7 marks)
3. Define a structure called Student that stores name, roll no, gender, and major. Ask the user to
fill in this data in the student array, then display the detail information of the student according
to the user-entered major. (6 marks)
1. Implement a C++ program that finds the common elements between two arrays of integers.
Sample Output
Array1 Elements : 10 20 30 40 50
Array2 Elements : 10 30 50 70
Common Array Elements =10 30 50 (6 marks)
2. Construct a C++ program that accepts a name from a user as a C-String. And check whether
the first word of the name starts with “Ma” then replaces with “Ms.” or starts with “Mg” then
replaces with “Mr.” without changing the remaining words of the name.
(7 marks)
Sample Output
Enter a name: Ma July Moe
Updated Name: Ms. July Moe
3. Write a C++ function called checkEven() to check whether every digit of a given integer is
even. Return true if every digit is even otherwise false. Write a main () program that takes an
integer value from the user and checks it using this function.
Sample Output
Enter an integer: 2816
Whether every digit of the said integer is even or not! False (7 marks)
4. Define a C++ class Time that represents numerator and denominator. Overload the *
operator to multiply two time. In the main () function, we create two Fraction objects (t1
and t2) and perform multiplication, displaying the result.
(7 marks)