Professional Documents
Culture Documents
CSC128/FINALTEST
INSTRUCTIONS TO CANDIDATES
Name : _________________________________________________
UiTM Student’s Id Number : _________________________________________________
Lecturer’s Name : _________________________________________________
Group : _________________________________________________
A 55
B 15
Total 70
1
PART A
QUESTION 1
Write a program segment for the following flowchart. Use if-else to write the codes:
(8 marks)
2
QUESTION 2
QUESTION 3
START
PROMPT
P - Permanent worker
C - Contract worker
Choose your category:
GET category
PROMPT Enter basic salary:
GET basic salary
CASE „P‟:
3
CASE ‘p’:
increase = 5%
CASE „C‟:
CASE „c‟:
increase = 2.5%
DEFAULT :
DISPLAY Please enter the correct category
CALCULATE
increment = basic salary * increase;
new salary = basic salary + increment;
(8 marks)
QUESTION 4
Write a complete program that uses for-loops to perform the following steps:
a. Prompt the user to input two integers: firstNum and secondNum (firstNum must
be less than secondNum).
b. Output all odd numbers between firstNum and secondNum.
c. Output all even numbers between firstNum and secondNum.
d. Output the sum of all odd numbers between firstNum and secondNum.
e. Output the sum of all even numbers between firstNum and secondNum.
Output Sample:
(8 marks)
4
QUESTION 5
Write a complete program using while-loop to display the lowest odd number among ten
positive integer numbers between 1 to 50 entered by the user. The user needs to reenter
for every invalid input range. Given is the sample output screen:
Sample Output:
(8 marks)
QUESTION 6
Write a complete C++ program that accepts positive integer numbers less than 20 by using
do-while loop. The program will display the numbers that are divisible by 3 and 5. The
program will also display the square root of total entered values. Note that the output is in
three decimal places.
Output Sample:
5
Enter an integer value to continue: 12
Enter an integer value to continue: 21
Number of integer value divisible by 3 = 3
Number of integer value divisible by 5 = 2
S/root of summation values = 7.141
(8 marks)
QUESTION 7
(3 marks)
Score Grade
≥75 A
≥40 B
<40 C
(4 marks)
6
PART B
QUESTION 1
Warded Patient Category Warded Patient Type Code Charge Per Day (RM)
Surgery 001 300.00
Orthopedic 002 250.00
Medical 003 200.00
(5 marks)
b) Based on the function defined in (a), write a main() program that fulfill the following
tasks:
Prompt user to enter patient’s name, IC number, warded patient type code, category
(use character code to indicate Child (C) or Adult (A)) and the number of days
warded.
Call function wardedPatientCharge() in the main() program.
If patient’s category is a Child, a discount of 20% will be given. If patient is an Adult,
only 5% discount will be given.
Display the patient details include patient’s name, IC number, patient category,
number of days and total charge after discount.
The process will continue until the user enters ‘N’ to stop.
(10 marks)