Uploaded by mikefelix744

C++ exercise

advertisement
1. Write a program that accepts the coordinates of two points, point(x1,y1) and point (x2,y2),
then compute and display the distance between the points given that;
2. Body Mass Index (BMI) is a measure of health based on height and weight. It can be
calculated by taking your weight in kilograms and dividing it by the square of your height
in meters. The interpretation of BMI for people 20 years or older is as follows:
BMI
Interpretation
BMI < 18.5
Underweight
18.5 ≤ BMI < 25.0
Normal
25.0 ≤ BMI < 30.0
Overweight
30.0 ≤ BMI
Obese
Write a program that prompts the user to enter a weight in pounds and height in inches and
displays the BMI. Note that one pound is 0.45359237 kilograms and one inch is 0.0254
meters.
3. Suppose you want to develop a program to play lottery. The program randomly generates
a lottery of a two-digit number, prompts the user to enter a two-digit number, and
determines whether the user wins according to the following rules:
o If the user input matches the lottery number in the exact order, the award is KSh.
10,000.
o If all digits in the user input match all digits in the lottery number, the award is
KSh. 3,000.
o If one digit in the user input matches a digit in the lottery number, the award is KSh.
1,000.
Write a program implementing this requirement.
4. Write a program that prompts the user to enter the month and year and displays the number
of days in the month. For example, if the user entered month 2 and year 2012, the program
should display that February 2012 had 29 days. If the user entered month 3 and year 2015,
the program should display that March 2015 had 31 days.
5. Suppose that the tuition for a university is KSh. 10,000 this year and tuition increases
7% every year. In how many years will the tuition be doubled? Write a program that
accepts the tuition fee and the increment percent per year, then determine the number of
years needed before it is doubled.
6. Write a program that prints a 7 by 7 multiplication table in a suitable format using
 do…while
 while
 for loops
7. Suppose you save $100 each month into a savings account with the annual interest rate
5%. So, the monthly interest rate is 0.05 / 12 = 0.00417. After the first month, the value
in the account becomes100 * (1 + 0.00417) = 100.417. After the second month, the value
in the account becomes (100 + 100.417) * (1 + 0.00417) = 201.252. After the third
month, the value in the account becomes (100 + 201.252) * (1 + 0.00417) = 302.507 and
so on. Write a program that prompts the user to enter an amount (e.g., 100), the annual
interest rate (e.g., 5), and the number of months (e.g., 6) and displays the amount in the
savings account after the given month.
8. Write a program that assist a grade 1 pupil practice addition. The program should
generate 2 integer values made up of one digit each, then ask the pupil to enter the sum. If
the answer given is correct, the program should display “Correct”. If wrong, the program
should display “Try again”. If the number of trials exceed 5, the program displays the
correct answer to the pupil.
9. Personal income tax is calculated based on filing status and taxable income earned as
shown in the table below. There are three filing statuses: single filers, married filing jointly
or qualified widow(er) and married filing separately. If you are, say, single with a taxable
income of $10,000, the first $8,350 is taxed at 10% and the other $1,650 is taxed at 15%,
so, your total tax is $1,082.50.
Write a program to compute personal income tax. Your program should prompt the user to
enter the filing status (Using switch…case structure, enter 0 for single filers, 1 for married
filing jointly or qualified widow(er), 2 for married filing separately) and taxable then
compute personal income and display necessary details in a suitable format
Download