Assignment 6
Assignment 6
1. Write a program in a script file that determines the real roots of a quadratic equation
𝑎𝑥 2 + 𝑏𝑥 + 𝑐 = 0. Name the file quadroots. When the file runs, it asks the user to
enter the values of the constants a, b, and c. To calculate the roots of the equation the
program calculates the discriminant D, given by:
𝐷 = 𝑏 2 − 4𝑎𝑐
If D > 0, the program displays message “The equation has two roots,” and the roots are
displayed in the next line.
If D = 0, the program displays message “The equation has one root,” and the root is
displayed in the next line.
If D < 0, the program displays message “The equation has no real root,”
2. The following are formulas for calculating the training heart rate (THR) for men and
women.
For men (Karvonen formula): THR = [(220 – AGE) – RHR] x INTEN + RHR
Where AGE is the person’s age, RHR the resting heart rate, and INTEN the fitness
level (0.55 for low, 0.65 for medium, and 0.8 for high fitness). Write a program in a
script file that determines the THR. The program asks users to enter gender (male or
female), age (number), resting heart rate (number), and fitness level (low, medium, or
high). The program then displays the training heart rate.
Page 1 of 3
3. Body Mass Index (BMI) is measure of obesity, In SI units it is calculated by the
formula
𝑚
𝐵𝑀𝐼 = 2
𝐻
where m is mass in kilograms, and H is height in meters. The obesity classification is:
BMI Classification
Below 18.5 Underweight
18.5 to 24.9 Normal
25 to 29.9 Overweight
30 and above Obese
Write a program in a script file that calculates the BMI of a person. The program asks
the person to enter his or her mass (kg) and height (m). The program displays the result
in a sentence that reads: “Your BMI value is XXX, which classifies you as SSSS,”
where XXX is the BMI value rounded to the nearest tenth, and SSSS is the
corresponding classification.
4. Write a program in script file that calculates the cost of a telephone call according the
following price schedule:
The program asks the users to enter the time the call is made (day, evening, or night)
and duration of the call (a number that can have one digit to the right of the decimal
point). If the duration of the call is not an integer, the program rounds up the duration
to the next integer. The program then displays the cost of the call.
Page 2 of 3
5. Write a program in a script file that calculate the cost of renting a car according to the
following price schedule:
The program asks the user to enter the type of car (Sedan or SUV), the number of days, and
the number of miles driven. The program then displays the cost (rounded to cents) for the
rent.
ii) Run the program three times for the following cases:
(a) Sedan, 10 days, 769 miles.
(b) SUV, 32 days, 4,056 miles.
(c) Sedan, 3 days, 511 miles.
Page 3 of 3