lab session 5(Struct with function)

advertisement
1
QUESTION 1
Given a struct definition:
struct athleteRec
{
char name[30];
int age;
char IC_number[20];
int score_event1;
int score_event2;
int score_event3;
int totalScore;
}
2
QUESTION 1(CONTINUE)
1) Write a function definition that will :
a) inputData() //input a data and return by value
b) calcTotal() // calculate a total score and return through reference parameter
c) calcAverage() //calculate an average of total score and return by value
d) displayReport() // display a report as below:
*****************************
ATHLETE DATA:
Name : XXXXXXXXXXXX
IC Number : XXXXXX-XX-XXXX
Detail Score :
Event 1 : XXXX
Event 2 : XXXX
Event 3: XXXX
TOTAL SCORE : XXXXX
AVERAGE SCORE : XXXX
*****************************
3
QUESTION 2
Write a C++ program to help a local restaurant owner to automate his/her breakfast
billing system. The program should do the following tasks:
Show the customer the different breakfast items offered by the restaurant.
Allow the customer to select one item and the amount of item purchased from the menu.
Calculate and print the bill.
Assume that the restaurant offers the following breakfast items:
Items
Prices/Unit
Plain egg
RM1.50
Muffin
RM2.00
French toast
RM2.50
Fruit Basket
RM3.00
4
QUESTION 2(CONTINUE)
Your program must contain at least the following functions:
Function showMenu: this function shows the different items offered by the restaurant and
tells the user how to select the items.
Function CalculateTotal: this function calculates the total price to be paid by the customer. The
total price should include a 5% tax.
Function printCheck: this function prints the check.
Your program should use a structure to store information about the customer’s purchase:
menu item, item price, the amount of item, tax value and the total amount due.
A sample output is as follows:
Thanks for dining at Jonny’s Place
Plain egg
Tax
Amount Due
2
RM3.00
RM0.15
RM3.15
5
QUESTION 3(ASSIGNMENT 2)
Afiqah’s Company want to automate their parking system. For the prototype, your
program should input time in and time out for one car. The rate for the parking lot
is given below:
Detail
Charge
First 1 hour
RM 2.00
Next each 1 hour
RM 0.50
Maximum Charge
RM 10.00
Your program must use a struct to store a data and apply modular programming.
Sample of the output as below:
Time In: 14.15 pm
Time Out : 17.00 pm
Charge : RM 2.50
6
Download