You are on page 1of 7

CONFIDENTIAL CS/AUG2021/

CSC128/FINALTEST

UNIVERSITI TEKNOLOGI MARA


FINAL TEST

COURSE : FUNDAMENTALS OF COMPUTER PROBLEM SOLVING


COURSE CODE : CSC128
SEMESTER : 7 AUGUST 2021
TIME : 3 HOURS

INSTRUCTIONS TO CANDIDATES

1. This question paper consists of two (2) parts :


PART A (7 Questions)
PART B (1 Question)
2. Answer ALL questions :
3 All answers must be handwritten.
4. Do not contact anyone during the test.

Name : _________________________________________________
UiTM Student’s Id Number : _________________________________________________
Lecturer’s Name : _________________________________________________
Group : _________________________________________________

Part Total Marks Marks

A 55

B 15

Total 70

DO NOT TURN THIS PAGE UNTIL YOU ARE TOLD TO DO SO


This examination paper consists of 7 printed pages

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

Given the following program fragment:

if (value1 < 20)


if (value2 > 20)
cout << “FIRST” << endl;
else
cout << “SECOND” << endl;
cout << “THIRD” << endl;

a) Determine the output for each of the following samples of input.


i. value1 = 15 and value2 = 30
ii. value1 = 19 and value2 = 20
(4 marks)
b) Assume value1 = 23 and value2 = 25, the following output is produced:
THIRD
Modify and rewrite the above program fragment to produce the output shown. You need
to use proper indentation techniques and you may not make any changes other than
inserting braces.
(4 marks)

QUESTION 3

Given the following pseudocode, write a complete program using a switch-case


statement to calculate a new salary of an employee after the increment based on his/her
category:

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;

DISPLAY basic salary, increment, new salary


END

(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:

First number must be less than second number


Enter first number: 1
Enter second number: 10

Odd numbers Even numbers


1 2
3 4
5 6
7 8
9 10

Sum odd numbers between first number and second number:25


Sum even numbers between first number and second number:30

(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:

Enter ten positive integer numbers between 1 to 50:


1) 32
2) 5
3) 56
ERROR INPUT!! NUMBER MUST BE BETWEEN 1 TO 50, ENTER AGAIN : 3) 42
4) 12
5) 7
6) 11
7) 234
ERROR INPUT!! NUMBER MUST BE BETWEEN 1 TO 50, ENTER AGAIN : 7) 31
8) 41
9) 21
10) 43
The lowest odd number is = 5

(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:

Enter a positive integer value (less than 20): 10


Enter an integer value to continue: 6
Enter an integer value to continue: 8
Enter an integer value to continue: 15

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

Write the function definition of the following functions:


a) Define a function named ticketPrice() that receives the number of adults and
children as integer parameters. The function will calculate and return the total ticket
price based on the following table.

Ticket Category Price/Ticket (RM)


Adult 35.00
Children 23.00

(3 marks)

b) Define a function named gradeStatus() that receives a score as float parameter.


The function will determine and return the grade based on the score stated in the
following table.

Score Grade
≥75 A
≥40 B
<40 C

(4 marks)

6
PART B

QUESTION 1

a) Write a function definition of wardedPatientCharge() which receives warded patient


type code and number of days warded. This function will then calculate and return total
charges. The charges are calculated based on the following table:

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)

You might also like