C++ Questions Tutorial 2
C++ Questions Tutorial 2
Tutorial II
Prepared by: Showayb Zahda
Solve the following problems:
1. Calculator, make your own calculator that does the four basic arithmetic operations i.e. +, -, *, /.
using switch
using if statements
using if else statements.
(Note: use functions for the arithmetic operations)
2. Consider a brick that is dropped from a tower. The distance the brick falls depends on the the
time since it was released.
d = (1/2) g t2
Here d is the distance in feet, t is the time in seconds, and g is 32.174. Write a program that asks
the user for the number of seconds and then prints out the distance.
Enter the number of seconds
5.4
Distance: 469.092 feet
4. Quadratic Equation, write a programme that finds the roots of a quadratic equation.
Ax2 + Bx + C = 0
5. Animal insurance
Write a program that prints the insurance fee to pay for a pet according to the following rules:
• A dog that has been neutered costs $50.
• A dog that has not been neutered costs $80.
• A cat that has been neutered costs $40.
• A cat that has not been neutered costs $60.
• A bird or reptile costs nothing.
• Any other animal generates an error message.
The program should prompt the user for the appropriate information, using a code to determine
the kind of animal (i.e. D or d represents a dog, C or c represents a cat, B or b represents a bird,
R or r represents a reptile, and anything else represents some other kind of animal).
After printing the insurance fee, the program should ask the user if (s)he wants to insure another
animal.
6. KICT has a new marking scheme which is
1. 2 quizzes each carries 5 %.
2. 3 assignments each carries 10 %
3. Mid-term carries 20 %
4. mini project carries 10 %
5. final exam carries 30 %
you are asked to develop a system that reads the marks from the keyboard and computes
the grade out of 100 %. Then the system shall output the letter corresponds to the mark
based on the following table
Mark letter
Above 85 A
75 – 84 A-
70 – 74 B+
65 – 69 B
60 – 64 B-
55 – 59 C+
50 – 54 C
Below 49 D
Hint: use if – else statements and use functions when appropriate