(CSC415) Final Assessment July 2022
(CSC415) Final Assessment July 2022
INSTRUCTIONS TO CANDIDATES
a. Explain the difference of Pre-Test and Post-Test repetition control structures. Give ONE
example for each.
(5 marks)
b. Show the output of the following program segment. Then, rewrite the program segment
by using the while loop structure.
int main()
{ int x = 5;
for (int a = x; a > 0; a--)
cout << a * 5 << “ “;
return 0;
}
(5 marks)
c. Eric opened the savings account at PC Bank in January 2022 with the first savings is RM
10,000. If the yearly interest is 10%, in what year the total savings in the account will be
exceeding RM 1 million. Write a program segment to calculate and display the year and
the total savings.
(5 marks)
a. Assuming an array named Player_ID and Point are initialized as shown in Figure 2.
Figure 2
ii) Declare one-dimensional arrays to store Point data. Point array is a floating-type
array. Initialize all elements to the respective arrays.
(3 marks)
ii) The highest point together with the Player_ID who gets the highest point.
(7 marks)
int main()
{
float taxRate = 0.06;
float price, taxAmt;
char type;
return 0;
}
Based on the code fragment, write the function prototype to declare function
calcTax(). Then, write the complete definition for function calcTax(). This function
calculates the amount of goods and service tax, then returns the tax amount to caller
function.
Tax is imposed on all types of products except product with type ‘F’. If the product code
is ‘F’, the tax amount is zero.
b. Write the functions definitions for function OddEven() that takes one argument of type
integer. The function returns the character value ‘O’ if its argument is an odd number and
returns ‘E’ if its argument is an even number.
(4 marks)
#include <iostream>
using namespace std;
(5 marks)
ii) Based on bookBorrowers.txt, read the input data calculate the penalty
payment that should be paid by each borrower. The rate of overdue penalty
for each book is based on book category as shown in the following table
Then, calculate the total payment from all students. The output for overpayment
is as follows :
(6 marks)
b) The program read data from drinks.txt, which consists of the list of drinks and
Coffee152
Tea 120
Juice 335
Espresso 113
Write C++ statements to read all data from drinks.txt and display the total sales
for all the drinks.
(6 marks)
QUESTION 1
FGH Healthcare Sdn Bhd is a COVID-19 Antigen Test Kit whole seller in Kuala Lumpur. The
management wants to develop a simple program to help its distributors to calculate the
wholesale price. The table below depicts the details of the products offered.
a. Prompt the user to enter the product code and quantity. Display an error message if the
user entered an invalid code or if the quantity fails to meet the minimum number of orders.
b. Calculate the current order sales and print the receipt using the following example:
Total : RM XX.XX
c. The process will continue until the user enters 'N' to stop.
d. At the end of the process, print the summary report including tax. Your answer should be
display in two decimal places.
(20 marks)
QUESTION 2
Cuci-Cuci Service Sdn Bhd offer weekly payment for its employees with the regular rate is
RM15.00 and the rate is as follows:
Hours Rate
The first 20 hours Regular Rate (RM 15.00)
For next 20 hours 1.5 times the regular rate for each hour over 20 through 40
For over 40 Double the regular rate for each over 40
a. Write the definition of function void getData(). This function will read the employee's
name and the number of hours worked. This function then returns both data through its
reference parameters.
b. Write the definition of function calcGrossPay(). This function receives the number of
hours worked through its parameter. This function then calculates and returns the gross
pay.
c. From the employee’s gross pay, the following deductions are made:
• Write the statement to call function getData() with appropriate actual parameters
provided.
• Calculate the gross pay and deductions for each employee by calling function
calcGrossPay() and calcDeduction()
• Calculate the net pay for each employee:
• Display a slip for each employee that display the employee id, gross pay , deduction
and net pay.
• Calculate and display the total net pay for all employees in the company.
• This process will continue until the user requests to stop.
(20 marks)