Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Test Februari 2022-1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

1

CONFIDENTIAL CS/JAN 2022/CSC126

UNIVERSITI TEKNOLOGI
MARA FINAL
EXAMINATION

COURSE : FUNDAMENTALS OF ALGORITHMS & COMPUTER


PROBLEM SOLVING
COURSE CODE : CSC126
EXAMINATION : JAN 2022
TIME : 2 HOURS

INSTRUCTIONS TO CANDIDATES

1. This question paper consists of three (3) parts: PART A (10 Questions)
PART B (4 Questions)
PART C (1 Question)

2. Answer ALL questions from all three (3) parts.

3. Answer ALL questions in English.


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

CONFIDENTIAL This examination paper consists of 15 printed pages CS/JAN 2022/CSC126


1
0
© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL

PART A (20 MARKS)

1. The control structure is used to make a choice during program execution.

A. sequential
B. selection
C. repetition
D. decision

2. Trace the output of the C++ program segment below.

int oxygen = 85;


if (oxygen < 85)
cout <<“Hypoxia III ”;
cout <<“ Hypoxia II ”;
cout <<“ Hypoxia I”;
A. Hypoxia III
B. Hypoxia II
C. Hypoxia II Hypoxia I
D. Hypoxia II
Hypoxia
I
3. Why does the following code segment always display "High" regardless of the value of
x?

if (x = ! 0) //Line 1
cout << "High";
else //Line 3
cout << "Low";

A. 0 in Line 1 should be enclosed in single quotations.


B. There is no semicolon at the end of Line 1.
C. There should be a semicolon at the end of Line 3.
D. Wrong operator is used in evaluating the condition in Line 1.
CONFIDENTIAL CS/JAN 2022/CSC126
1
0

4. Identify the number of times the body of loop being executed in the following nested
loop.

for(int x=10; x>=1; x-=2)


for(int y=1; y<=10; y+=2)
cout << x*y << endl;

A. 20
B. 25
C. 30
D. 35
5. Which of the following is the CORRECT syntax of a for loop?

A. for(int i=1, i<=10, i+=1)


B. for(int i=1; i<=10; i+=1)
C. for(i+=1; int i=1; i<=10)
D. for(i+=1, int i=1, i<=10)

6. Analyze the following program segment.

⑤>
int input, count = 0;

count
50
cin >> input;
while (input != -1)
{
if (input > 50)

:
count++;

cin >> input;


}

cout << count;

Choose the correct output if the user enters the following data:

42 88 13 10 91 89 90 54
-1

A. 5
© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL
B. 6
C. 8
D. 9
7. Select the FALSE statement about a for loop structure.

CONFIDENTIAL CS/JAN 2022/CSC126


1
A. The loop will continue until the condition is false.
B. The loop can be used as a counter-controlled loop
0
C. The loop can be used as a sentinel-controlled loop
D. The loop can have another loop

8. Which of the following statement is TRUE?

A. A value-returning function can return several values.


B. Every user-defined function must return a value.
C. The C++ system allows only user-defined functions.
D. When a function exits, the control goes back to the caller.
9. Identify the type of these functions.

cos(x)
exp(x)
fabs(x)
abs(x)

A. User-defined function
B. Pre-defined function
C. void function
D. Value returning function

10. Given the function prototype:

void guess(int&, int);

Which of the following function call statement is INVALID?

A. guess(6, 9);
B. guess(x, 9);
C. guess(x, x);
D. guess(x, y);

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL

CONFIDENTIAL CS/JAN 2022/CSC126


PART B 1
0
QUESTION 1
a) Predict the output for the program segment given below:
int no1, no2;
no1 = 10;
no2 = 7;

if (no1 != no2) 17
{
if (no2 == 13) 28
cout<<no2;
else
{
n01, n02
cout<<no1+no2<<endl;
cout<<no1*2;
}
}
cout<<"\nno1, no2";
(3 marks)

b) There are a few errors in the given code segment written in C++. Identify the errors, and
write the corrected code segment.

int boiling I== 100;


if(boiling >= 100); oxyan
cout<<"The water is boiling.";
else {
cout<<"The temperature has NOT reached the boiling point."<<endl;
X

3 cout<<’Keep on heating the water.’;


/

cout<<"\nThank you for using this program.";


return 0;

(2 marks)

QUESTION 2

a) Sekolah Menengah Ayer Keroh, Melaka will be


organizing a marching competition among uniform
bodies for secondary school students in Melaka. Write a
program segment to calculate and display the total charge
© Hakper groupTeknologi
Cipta Universiti basedMARAon the fee rates in the given table. The
CONFIDENTIAL
program will begin by prompting the user to enter the
category code. It will display an error message such as
“Error: Invalid Category”1 and exits the system
CONFIDENTIAL if the
CS/JAN 2022/CSC126
user enters a wrong code. 0

Additionally, if the group chooses to have breakfast


during the marching competition, they need to reply
“Yes” when asked by the program and enter the number
of students in the group. An additional RM1.50 will be
charged per student.

The fee rates per group for the competition are shown in
table given below:

Categor Fee per group


y (RM)
A 10
B1 5
B2 5
(5 marks)

b) Jungle Bee Sdn Bhd offers point rewards to customers


based on the average of weekly purchases for the past 3
weeks. Based on the calculated average weekly purchases
and several conditions, it then offers voucher points to its
customers as shown in the table given below:

Condition
Average s Vouche
weekly r
Purchase Points
Successfully Purchases made
rated a from
product Preferred
sellers
Less than 500 Y/N Y/N 0
More than or equal to
500 and less than 1000 Y Y 400
More than or equal to Y Y/N 900
1000

Write a complete program in C++ which is capable of


determining the voucher points rewarded to the user and
© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL
then display the customer ID, average weekly purchase
and the voucher points earned.
(5 marks)
CONFIDENTIAL CS/JAN 2022/CSC126
1
0

QUESTION 3
Write a main program that accepts a positive integer number from the user and displays all
the factors of that number. The program must also be able to count how many factors the
number has. Factors are the values that the number is divisible by without any remainder.

For example: number 77 has 4 factors which are 1, 7, 11 and 77.


(5 marks)

QUESTION 4

a) calcArea() is a function that is responsible in calculating the area of a triangle. Write


its definition given that this function will receive TWO (2) parameters; height and
base of the triangle and then, return the calculated area of the triangle. Formula to
calculate the area of a triangle is given as below:

𝐴𝑟𝑒𝑎 of 𝑡𝑟𝑡i𝑎𝑛𝑔𝑙𝑒 = 𝑥 ℎ𝑒𝑡𝑡𝑔ℎ𝑡 𝑥 𝑏𝑎𝑠𝑒


1

2
(3 marks)

b) Using the above function in (a), write a main program that requires user to input value
of x and y, then calculate and display area of the shaded region in given figure below.

(7 marks)

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL

PART C (20 MARKS)


CONFIDENTIAL
1 CS/JAN 2022/CSC126

Bukit Gambang Water Theme Park is built on a natural hilly


terrain in Kuantan, Pahang. Since the Prime Minister of
Malaysia has allowed interstate travels for those who have
been fully vaccinated against Covid-19, this water theme
park is now re-opened.

Write a complete C++ program that will calculate the total


fees charged to the paying visitor and generate the receipt.
The program should receive the name of the payer, his/her
contact number and the number of tickets needed.

A visitor is allowed to purchase multiple tickets within one


receipt. For each ticket, the age and type of citizenship
should be specified. The following table shows the
admission fee for all age categories. The fees stated in the
table is only applied for Malaysian citizens. Additional 15%
will be charged for foreigners.

Categor Fee
y (RM)
Child (4-12 years old) 23
Adult (13-59 years old) 33
Senior citizen (60 years and above) 20

Visitors are also allowed to rent facilities if they are


interested. The number of facilities to be rented is
determined by the visitor (as long as he or she enters ‘Y’ for
“Yes”). The list of the rental items and price per unit is
shown in the following table:

Item (per unit) Rental


(RM)
Single tube (ST) 15
Double tube (DT) 20
Locker (LC) 25
© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL
Children life vest (LV) 20
Beach volleyball (BV) 12

The total fees calculated is subjected to 6% tax. The receipt


CONFIDENTIAL CS/JAN 2022/CSC126
1 given, where the
should follow the output format RM values
0
are displayed in 2 decimal places. Below is a sample input
and output for this program, where the shaded text represents
the input.

Payer's name: Alice Tan


Payer's contact number: +60139872376
Number of tickets needed: 5

Enter age for visitor [1]: 10


Citizenship [M-Malaysian | F-Foreigner]: M
Enter age for visitor [2]: 8
Citizenship [M-Malaysian | F-Foreigner]: M
Enter age for visitor [3]: 12
Citizenship [M-Malaysian | F-Foreigner]: F
Enter age for visitor [4]: 29
Citizenship [M-Malaysian | F-Foreigner]: F
Enter age for visitor [5]: 32
Citizenship [M-Malaysian | F-Foreigner]: M

Do you want to rent any facility? [Y-Yes | N-No]: Y


Enter item id: DT
Enter quantity: 2
Do you want to rent other facility? [Y-Yes | N-No]: Y
Enter item id: LV
Enter quantity: 3
Do you want to rent other facility? [Y-Yes | N-No]: Y
Enter item id: BV
Enter quantity: 1
Do you want to rent other facility? [Y-Yes | N-No]: N

Receipt Name : Alice


Tan
Contact number : +60139872376
Number of tickets : 5
Number of child : 3
Number of adult : 2
Number of senior citizen: 0
Total admission fee :RM
143.40 Total rental fee :RM
112.00
Total Fee :RM 255.40
Tax :RM 15.32
Amount Due :RM 270.7

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL

CONFIDENTIAL CS/JAN 2022/CSC126


1
END OF QUESTION
0

You might also like