Tut 5 CSC425
Tut 5 CSC425
Tut 5 CSC425
Grade
F
D
C
B
A
1|Page
4. Write two functions named CalculateBMI and BMILevel. Your program must enter the
weight and height in the main program and send both parameters to a function named
CalculateBMI. The second function named BMILevel will determine the BMI level of
the person based on the calculated BMI from the first function. The following is the
formula to calculate the BMI.
BMI = weight / (height * height)
The following is the table of BMI Level.
BMI Range
< 15
15.01 25.00
> 25.01
Level
Normal
Obese
5. Explain the difference of passing parameter by reference and by value. Given example
for each concept.
6. Explain the following terminologies.
a) Global variable and local variable
b) Actual parameter and formal parameter
c) Function prototype and function definition
7. Write the function definition for each of the following:
a) Function ConvertToinches () that receives a measurement in feet and inches as
parameters. Convert it to the equivalent inches, and return the value in inches.
( HINT : 1 FOOT = 12 INCHES )
b) Function printEven () that will print all the even numbers within the two integer
parameters in ascending order. For example, if the parameters are 2 and 9
respectively, the function prints:
The even numbers are: 4 6 8
If the parameters are 12 and 1 respectively, the function prints:
The even numbers are: 2 4 6 8 10
8. Write a function sumOfNumbers () that calculates and returns the sum of the numbers
from 1 to n (where n is a parameter). For example, if the value of n is 5, the function will
return 15 since 1 + 2 + 3 + 4 + 5=15.
2|Page
Write a complete C++ program for WorldParking Sdn Bhd. to perform the following:
a)
Write a return-value function named calccharges () to calculate and return the
parking charges for the customers. The company charges a RM1.00 minimum fee
to park for up to one hour. An additional RM0.50 will be charged for each hour
exceeding the first one hour. The maximum charge for any given 24-hour period is
RM10.00. Assume that no car parks for longer than 24 hours at a time. Use the
appropriate parameters to pass values in and out of the function.
b)
Write a void function named calcTotal () to calculate the total charges for all the
customers. Use the appropriate parameters to pass values in and out of the
function.
c)
Write the main program that allows the user to input number of customers and the
ours parked for the customers. The program should use the function calccharges()
above to calculate and print the parking charges for each customer and function
calcTotal() above to calculate and print the total charges for all the customers.
3|Page