You are on page 1of 16

CONFIDENTIAL CS/FEB 2017/CSC128

UNIVERSITI TEKNOLOGI MARA


TEST 1

COURSE : FUNDAMENTALS OF COMPUTER PROBLEM


SOLVING
COURSE CODE : CSC128

DATE : 10 FEBRUARY 2017

TIME : 2 HOURS

STUDENT NAME : ……………………………………………………...

UiTM ID NO. : …………….............. GROUP : …………….

LECTURER : ……………………………………………………..

PART A / 10

PART B / 25

PART C / 15

TOTAL / 50

PERCENTAGE / 10%

This question paper consists of 15 printed pages

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CS/FEB 2017/CSC128

PART A (10 Marks)


Choose the best answer.

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

3. What is the output of the following program segment if the input is 3?

int x = 5, y = 7;
cin >> z;
cout << (x % y + y * z * z % 5);

A. 8
B. 9
C. 12
D. 13

4. Which of the following statements are TRUE?

i. All variables must be declared before they are used


ii. Comments cause the computer to print the text after the // on screen when the
program is executed
iii. The modulus operator can be used only with integer operands
iv. C++ considers the variable price and Price to be identical

A. i and ii
B. i and iii
C. i, ii and iii
D. All of the above

1
CS/FEB 2017/CSC128

5. Which of the following identifiers are VALID?

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. Analysis, Design, Testing, Coding, Maintenance


B. Design, Analysis, Testing, Coding, Maintenance
C. Analysis, Design, Coding, Testing, Maintenance
D. Design, Analysis, Coding, Testing, Maintenance

7. Which of the following is NOT a logical operator in C++?

A. !
B. ||
C. ==
D. &&

8. What is the output for the following C++ fragment?

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

10. Given the following program segment.

if (a > b)
if (b > c)
cout << ”Have a Nice Day”;

The above program segment can be simplified into:

A. if (a > b && b > c)


cout << ”Have a Nice Day”;
B. if (a > b || b > c)
cout << ”Have a Nice Day”;
C. if (a <= b && b <= c)
cout << ”Have a Nice Day”;
D. if (!(a > b) && b > c)
cout << ”Have a Nice Day”;

3
CS/FEB 2017/CSC128

Answers:

Question Number Answer


1.

2.

3.

4.

5.

6.

7.

8.

9.

10.

4
CS/FEB 2017/CSC128

PART B (25 Marks)

Question 1

a. Convert the following pseudocode to a C++ program.

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.

Daily Schedule Adult Child


Weekday RM 30.00 RM 25.00
Weekend RM 35.00 RM 30.00

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

a. Given the following variable initializations:

float x = 1.5;
int y = 3, z = 7;

Determine the output for the following statements:

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)

b. Write a C++ assignment statement for the following algebraic equations:

4+3𝑥 9−𝑥
i. 𝑍 = 𝑔𝑡2+ ( )−( )
6−𝑦 2+𝑦

(2 marks)

𝐿+ 𝑀3 + 5𝑅𝐵
ii. 𝐾=
3𝐹𝐶2
(2 marks)

9
CS/FEB 2017/CSC128

Question 3

a. Trace the output of the following program fragments:

i.
int first = 25, second;

second = first % 7;
second = second / 2 / 2;

if ((second == 0) || (second == 1))


if (first == (6 * 4))
cout << "@@@";
else
cout << "$$$";

cout << "\n!!!";

ii.
if (60 < 12 * 5)
cout << "I am feeling";
cout << "happy";

if (23 <= 23)


cout << 16 - 9 * 2 / 3 % 3 << endl;
cout << "\t***";

(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

PART C (15 Marks)

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:

1. Residential Houses (Premise code - RH):


a. Monthly fee: RM 2.00
b. Electricity charge (based on the table below):

USAGE (kwj) CHARGE


The first 150 kwj 15 cents per kwj
The next 150 kwj 35 cents per kwj
Over 300 kwj 60 cents per kwj

The minimum monthly charge is RM 7.00

2. Industrial Premises (Premise code - IP):


a. Monthly fee: RM 7.50
b. Electricity charge (based on the table below):

USAGE (kwj) CHARGE


At most 500 kwj Free of charge
More than 500 kwj 50 cents per kwj

The minimum monthly charge is RM 10.30

Calculation for payment:

Payment = fee + electricityCharge

The calculation for the electricity bill should be displayed in 2 decimal points.
Also, the program should follow the following display format:

WELCOME TO JOHOR ELECTRICITY BERHAD


Enter your name: RC JAMES
Enter the category (RH-RESIDENTIAL / IP-INDUSTRIAL): RH
Enter amount of electricity (kwj): 430

JOHOR ELECTRICITY BERHAD


NAME : RC JAMES
CATEGORY : RESIDENTIAL HOUSES
USAGE : 430 kwj
PAYMENT : RM 170.00

Figure 1: Sample input and output


(15 Marks)

12
CS/FEB 2017/CSC128

13
CS/FEB 2017/CSC128

14
CS/FEB 2017/CSC128

15

You might also like