Professional Documents
Culture Documents
TIME : 2 HOURS
LECTURER : ……………………………………………………..
PART A / 10
PART B / 25
PART C / 15
TOTAL / 50
PERCENTAGE / 10%
1. The user has keyed-in the wrong data type during the execution of the program. This
type of error is called ______________.
A. syntax error
B. logic error
C. semantic error
D. runtime error
2. Which of the following program translates the source code into machine code?
A. Linker
B. Compiler
C. Operating System
D. Editor
int x = 5, y = 7;
cin >> z;
cout << (x % y + y * z * z % 5);
A. 8
B. 9
C. 12
D. 13
A. i and ii
B. i and iii
C. i, ii and iii
D. All of the above
1
CS/FEB 2017/CSC128
i. Count_number
ii. Net salary
iii. countryName
iv. tax6%
A. i and ii
B. i and iii
C. i, ii and iii
D. All of the above
6. Program Development Life Cycle (PDLC) consists of five phases. Which one is the
correct order of PDLC?
A. !
B. ||
C. ==
D. &&
int y = 15;
if (y < 15)
cout << "hai ";
cout << "hello ";
cout << "bye";
A. hai
B. hai hello
C. hello bye
D. hai hello bye
2
CS/FEB 2017/CSC128
9. If the variable has_membership are declared to store an input from user which is
expected to store either ‘Y’, ‘y’, ‘N’ or ‘n’. What is the suitable data type to be used for
variable declaration?
A. double
B. float
C. int
D. char
if (a > b)
if (b > c)
cout << ”Have a Nice Day”;
3
CS/FEB 2017/CSC128
Answers:
2.
3.
4.
5.
6.
7.
8.
9.
10.
4
CS/FEB 2017/CSC128
Question 1
1. Start
2. Display
“Choose movie based on menu:
[1] Resident Evil: The Final Chapter (3D)
[2] The Great Wall”
[3] xXx: The Return Of Xander Cage
And enter the total number of ticket:”
3. Input movie, totTicket
4. If movie == 1
Price = 20.00
5. Else if movie == 2
Price = 15.00
6. Else if movie == 3
Price = 10.00
7. totPrice = totTicket x Price
8. Display “The total price is RM”, totPrice
9. End
(4 marks)
5
CS/FEB 2017/CSC128
b. Sunway Pyramid Ice is the first world class ice sports entertainment in Malaysia. The
table below shows the admission rates for ice skating in Sunway Pyramid Ice.
Given the daily schedule, number of adult and child as user input, draw a flowchart to
calculate the total charge a customer should pay and display the amount in the screen
as output. Your flow chart should display appropriate message when invalid input is
entered.
(4 marks)
6
CS/FEB 2017/CSC128
7
CS/FEB 2017/CSC128
Question 2
float x = 1.5;
int y = 3, z = 7;
i. int t = y * z + z * (6 – y);
cout << t;
(1 mark)
ii. int u = (y + z) % 3 + 12 / y + 6;
cout << u;
(1 mark)
iii. float v = z / x + 1;
cout << v;
(1 mark)
iv. float w = z / y + y;
cout << w;
(1 mark)
8
CS/FEB 2017/CSC128
v. float x = ( x + z )* 2
cout << x;
(1 mark)
4+3𝑥 9−𝑥
i. 𝑍 = 𝑔𝑡2+ ( )−( )
6−𝑦 2+𝑦
(2 marks)
𝐿+ 𝑀3 + 5𝑅𝐵
ii. 𝐾=
3𝐹𝐶2
(2 marks)
9
CS/FEB 2017/CSC128
Question 3
i.
int first = 25, second;
second = first % 7;
second = second / 2 / 2;
ii.
if (60 < 12 * 5)
cout << "I am feeling";
cout << "happy";
(4 marks)
b. Write C++ statements that uses switch structure to perform the following conditions:
i. Assign “low” if the value for temperature is 19 and 20 Celsius degree, and assign
“high” if the value for temperature is 25 and 26 Celsius degree.
(2 marks)
10
CS/FEB 2017/CSC128
ii. Using the condition when n is less or equal to 2, display “Draw” if the value of n
equals to 0, display “Win” if the value of n equals to 1, and display “Lose” if the
value of n is 2.
(2 marks)
11
CS/FEB 2017/CSC128
Write a complete C++ program to calculate and print the bill for Johor Electricity Berhad. The
program should ask the user to enter their name, premise code and the amount of electricity
usage (in kwj). Appropriate message should be displayed if an invalid premise code is
entered. The calculation for the electricity bill is based on the following information:
The calculation for the electricity bill should be displayed in 2 decimal points.
Also, the program should follow the following display format:
12
CS/FEB 2017/CSC128
13
CS/FEB 2017/CSC128
14
CS/FEB 2017/CSC128
15