Professional Documents
Culture Documents
Lab 10: Functions: Task 1. Given The Following C++ Code
Lab 10: Functions: Task 1. Given The Following C++ Code
b) Determine the output from the program based on the following input.
a. 10 15 20
b. 4 5 3
Task 2.
As a stockiest of a supplement product GELHALAL, Ahmad wants to know the profit of selling this
product as a wholesale. The cost of the supplement product is RM30 per bottle. The following table
shows the selling price of stockiest to dealer.
a. Write the definition of function calcProfit (). This function receives the number of bottle
sold to the dealer through its parameter. This function then calculates and returns the profit
using the following formula:
üOtherwise:
1. Calculate the profit using the function calcProfit()
2. Display the profit
Task 3.
The government of Malaysia assigned you to write a program to advise all staff to determine what
retirement age to choose based on the criteria given by Body Mass Index (BMI) and Mortality
Predictor (MP) .
Weight (kg)
𝐵𝑀𝐼 =
𝐻𝑒𝑖𝑔ℎ𝑡 (𝑚) 𝑥 𝐻𝑒𝑖𝑔ℎ𝑡 (𝑚)
Only those who achieved ‘A’ or ‘B’ rating in their MP will be advised to choose to retire at 60, while
those who achieve ‘C’ must choose to retire at 55.
a. Write the definition of function calcBMI () that receives weight and height. This function
calculates and returns the BMI.
b. Write the definition of function calcMP() that receives BMI, age and gender. This function
determines and returns the MP code
c. Write a main program to do the following:
a. Get the input of weight, height, gender and age.
b. Calculate the BMI using the function calcBMI()//function call
c. Determine the MP code using the function calcMP() //function call
d. Display the message “Retire at 60” or “Retire at 55” based on the MP code.