You are on page 1of 9

CONFIDENTIAL

CS/APR 2010/CSC128/415

UNIVERSITI TEKNOLOGI MARA FINAL EXAMINATION

COURSE COURSE CODE EXAMINATION TIME

FUNDAMENTALS OF COMPUTER PROBLEM SOLVING CSC128/415 APRIL 2010 3 HOURS

INSTRUCTIONS TO CANDIDATES 1. This question paper consists of three (3) parts: PART A (10 Questions) PART B (5 Questions) PART C (2 Questions)

2.

Answer ALL questions from all three (3) parts: i) ii) Answer PART A in the Multiple Choice Answer Sheet. Answer PART B and C in the Answer Booklet. Start each answer on a new page.

3.

Do not bring any material into the examination room unless permission is given by the invigilator. Please check to make sure that this examination pack consists of: i) ii) iii) the Question Paper an Answer Booklet - provided by the Faculty Multiple Choice Answer Sheet - provided by the Faculty

4.

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


This examination paper consists of 9 printed pages
Hak Cipta Universiti Teknologi MARA CONFIDENTIAL

CONFIDENTIAL

CS/APR 2010/CSC128/415

PART A (20 MARKS)

1. Which of the following are type of errors? i. ii. iii. iv. A. B. C. D. Logic errors, Run-time errors, Semantic errors, Syntax errors. i and iv. i, ii and iv iii and iv All of the above

2. What is the value of variable x after the following program segment is executed? i n t x = 0; float m = 3.2; double n = 3.0; x = 15 - m * n ; A. B. C. D. 5 5.4 6 35.4

3. Which of the following is TRUE about variables in C++? i. ii. iii. iv. A. B. C. D. Variables are memory cells used to store a program's data, l M a l a y s i a is a valid variable name, NUM and num are considered as two different variables, Variables must be declared before they can be used. i, ii and iii. i, iii and iv. ii, iii and iv. All of the above.

4. Which of the following is NOT a logical operator in C++? A. && B. | | C. ! D. %

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

CONFIDENTIAL

CS/APR 2010/CSC128/415

5. Suppose that a and b are i n t variables. statement?

Which of the following is a valid input

A. B. C. D.

cin cin cin cin

<<

a a a a

<<

b; cin b; b; cin << b;

6. Given the following variables declaration: i n t w = 2 , x = - 4 , y = 2, z = 300; Which of the following Boolean expression is TRUE?
A. y > x & & y > z B. y = = w & & z < x

C. z > 100 | | w != y D. y * 200 < z 7. What is the final value of variable x when the following statement is executed? for ( i n t x = 0; x < 10; x++) c o u t << x ;

A. B. C. D.

10 9 1 0

8. Which of the following statements is FALSE about loop? A. B. C. D. It is possible that the statements in a w h i l e loop are never executed. A loop that continues to execute endlessly is called an infinite loop. It is an error to use the f o r statement in a w h i l e loop. A pre-test loop tests for a condition prior to execute a loop body .

9. The type of parameters listed in the function header is called the A. B. C. D. actual parameter formal parameter reference parameter value parameter

10. Which of the following is TRUE about an array? A. B. C. D. An array is a collection of different types of data. The first element of an array A is A [ l ] . The last element of an array A of size n is A [n] . The index value specifies the position of the element in the array.
CONFIDENTIAL

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

CS/APR 2010/CSC128/415

PART B (50 MARKS)

QUESTION 1 a) Write an appropriate declaration for each of the following: i) A character variable f i r s t .

ii) An 80-elements character array message. iii) A floating-point variable r o o t l . (3 marks) b) Write a C++ assignment statement for each of the following algebraic equation:

i.

E = MC2

a(rn -1) II. sum= r-1 iii. P = 4m-n


(3 marks) c) Variable x is declared as follows: i n t x = 2945; What is the value of each of the following expressions?
i. ii. (x/ioo) x % 10 % 10

iii.

(x/10)

% 10

(3 marks)

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

CONFIDENTIAL

CS/APR 2010/CSC128/415

QUESTION 2 a) Write an appropriate C++ i f . . e l s e statements for each of the following: i. If number is negative, add the number to
PSTF.
NEGT,

otherwise add the number to

ii.

If mark is more than 10, print a message "Very message "Good".

Good", otherwise print a (4 marks)

b) Pop-In Sdn Bhd runs a cybercafe and charge as follows: Time For the first 30 minutes For the next 30 minutes For every 30 minutes over one hour Charges Rate (RM) 1.00 2.00 1.50

A 10% discount will be given to the customer who spends more than 3 consecutive hours at the cybercafe. Write a C++ program segment that calculate the actual charge for a customer based on the number of hours spent. (6 marks)

QUESTION 3 Prof. Zoe has come up with a formula to calculate the Zfactorial of an integer. The symbol '#' (a hash mark) indicates a Zfactorial defined as follows:

[[n x (n -1) x {n - 2) x x 1] x n

ifn>0

Write a complete C++ program to input an integer n and compute its Zfactorial. Your program should check that the range of n is 0 < < 1 0 before the computation. If the value of n is not in the range, display an appropriate error message and input the value of n again until the user enter the valid value of n. (10 marks)

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

CONFIDENTIAL

CS/APR 2010/CSC128/415

QUESTION 4 a) Suppose l i s t _ a r r a y given below is an integer array of five elements. Write the output displayed by the following C++ program segment. i n t i = 0; while ( i < 5)
{

l i s t a r r a y f i ] = 2 * i + 5; i f (i % 2 == 0) l i s t a r r a y [ i ] = l i s t a r r a y f i ] -- 3 ; cout l i s t a r r a y [ i ] " "; i = i + 1;


}

(5 marks) b) The score and grade for 100 students are declared as follows: i n t score [100]; char g r a d e [ 1 0 0 ] ; Write a C++ program segment to assign the grades of the 100 students based on the score given in the following table. Then, find and display the frequency for each grade. Score 70-100 40-69 0-39 Grade A B C

(8 marks)

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

CONFIDENTIAL

CS/APR 2010/CSC128/415

QUESTION 5 a) What is the output of the following program? void fl(int&, int, int&); void main() { int a, b, c; a = 10; b = 20; c = 30; fl (a, b, c) ; cout a ' ' }

'

c;

void fl(int& x, int y, int& z) { cout x ' ' y ' x = 1; y = 2; z = 3; }

endl;

(3 marks) b) A function called t o t a l P r i c e () accepts three inputs from the user. The inputs are b u t t e r , eggs and f l o u r for the prices of butter, eggs and flour respectively. The function then calculates and returns the total price. Write the function definition. (5 marks)

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

CONFIDENTIAL

CS/APR 2010/CSC128/415

PART C (30 MARKS)

QUESTION 1 The table below shows the road tax payment charged by the government based on category of year registered and the engine capacity (cc) of the car: Category of the Car Year Registered Engine Capacity (cc) 1000 or less A 1995 or earlier 1001 - 2 0 0 0 More than 2000 B 1500 or less 1996 or later More than 1500 Road Tax (RM) 50.00 70.00 90.00 150.00 300.00

Write a complete C++ program to do the following: Read the category and cc of each car. Count and display the number of cars according to category and cc. Calculate and display the total payment of road tax made by each category and cc of the car. Repeat the process until the user enters 'X' for the category of a car. Your program should be able to detect any invalid input of category of a car by displaying an appropriate error message. (15 marks)

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

CONFIDENTIAL

CS/APR 2010/CSC128/415

QUESTION 2 a) Given the prototype of function l a r g e r () as follows:

int larger (int,

int);

The function receives two integer parameters and returns the larger value between these parameters. Write the function definition. (4 marks) b) Write a complete C++ program to do the following: Declare an integer array of 30 elements. Assuming the values read are less than 100, read all the elements into the array. Find the largest element of the array by calling the l a r g e r () function as defined in a) repeatedly. Assume d is an integer used to add to the largest element of the array so that it becomes 100. Calculated. Change the values of all the elements of the array by adding them with d. Display the array. (11 marks)

END OF QUESTION PAPER

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

You might also like