0% found this document useful (0 votes)
33 views

Assignment 6

The document describes 5 programming assignments involving: 1. A program to calculate the real roots of a quadratic equation based on the discriminant. 2. A program to calculate a person's training heart rate based on their gender, age, resting heart rate, and fitness level. 3. A program to calculate a person's body mass index based on their mass and height and classify them as underweight, normal, overweight, or obese. 4. A program to calculate the cost of a telephone call based on the time it was made and call duration according to a price schedule. 5. A program to calculate the cost of renting a car based on the type of car, number

Uploaded by

ILan Idzlan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Assignment 6

The document describes 5 programming assignments involving: 1. A program to calculate the real roots of a quadratic equation based on the discriminant. 2. A program to calculate a person's training heart rate based on their gender, age, resting heart rate, and fitness level. 3. A program to calculate a person's body mass index based on their mass and height and classify them as underweight, normal, overweight, or obese. 4. A program to calculate the cost of a telephone call based on the time it was made and call duration according to a price schedule. 5. A program to calculate the cost of renting a car based on the type of car, number

Uploaded by

ILan Idzlan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

ENG3202 Computer Programming

Assignment 6: Relational and Logical Functions


(If Structure and Switch/Case)

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,”

i) Create a Flowchart and Pseudocode for the program.


ii) Run the script file in the Command Windows three times to obtain solutions to the
following three equations:
a) 3𝑥 2 + 7𝑥 + 9 = 0
b) 12𝑥 − 4𝑥 2 − 9 = 0
c) 5𝑥 − 7𝑥 2 + 1 = 0

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

For women: THR = [(206 – 0.88 x 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.

i) Create a Flowchart and Pseudocode for the program.


ii) Use the program for determining the training heart rate for the following two
individuals.
a) A 21 years old male, resting heart rate of 62, and low fitness level.
b) A 19 years old female, resting heart rate of 67, and high fitness level.

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.

i) Create a Flowchart and Pseudocode for the program.


ii) Use the program for determining the obesity of the following two individuals:
a) A person 188 cm tall with a mass of 82 kg.
b) A person 155 cm tall with a mass of 68 kg.

4. Write a program in script file that calculates the cost of a telephone call according the
following price schedule:

Time the call Duration of call


made 1-10 min 10-30 min More than 30 min
Day: $0.10/min $1.00 + $2.60 + $0.06/min
8 AM to 6 PM $0.08/min for for additional min
additional min above 30.
above 10.
Evening: $0.07/min $0.70 + $1.70 + $0.04/min
6 PM to 12 AM $0.05/min for for additional min
additional min above 30.
above 10.
Night: $0.04/min $0.40 + $1.00 + $0.02/min
12 AM to 8 AM $0.03/min for for additional min
additional min above 30.
above 10.

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.

i) Create a Flowchart and Pseudocode for the program.


ii) Run the program three time for the following calls:
a) 8.3 min at 1:32 PM
b) 34.5 min at 8:00 PM
c) 29.6 min at 1:00 AM.

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:

Duration Sedan SUV


of rent Daily rate Free Cost of Daily rate Free Cost of
miles (per additional miles additional
day) mile (per day) mile
1-6 days RM75 50 RM0.59 RM95 50 RM0.79
7-29 days RM65 100 RM0.49 RM85 100 RM0.69
30 or RM55 150 RM0.39 RM75 150 RM0.59
more days

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.

i) Create a Flowchart and Pseudocode of the program.

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

You might also like