Vous êtes sur la page 1sur 9

CONFIDENTIAL

CS/APR 2009/CSC125/ITC120

UNIVERSITI TEKNOLOGI MARA FINAL EXAMINATION

COURSE COURSE CODE EXAMINATION TIME

FUNDAMENTALS OF COMPUTER PROBLEM SOLVING CSC125/ITC120 APRIL 2009 3 HOURS

INSTRUCTIONS TO CANDIDATES 1. This question paper consists of two (2) parts : PART A (10 Questions) PART B (5 Questions) 2. Answer ALL questions from all two (2) parts. i) Answer PART A in the Objective Answer Sheet. ii) Answer PART B in the Answer Booklet. Start each answer on a new page. 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 an Objective Answer Sheet - provided by the Faculty

3.

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 2009/CSC125/ITC120

PART A (20 MARKS)

Answer ALL questions. Choose the correct answer.

1. Which of the following statements is FALSE? A. B. C. D. The process of designing and writing a program is called programming. A program in the form of a high-level language is called source code. A compiler is a program that translates the source code into machine language. The source code is also known as object code.

2. Which of the following program development life cycle phase is CORRECT? A. B. C. D. design -> coding -> testing -> evaluate -> maintenance analyze -> design -> coding -> testing -> maintenance design -> analyze -> testing -> evaluate -> maintenance design -> coding -> maintenance -> evaluate -> testing

3. Which of the following statements describe about a variable? I. II. III. IV. Every variable must be declared before it can be used in any programming language. The values stored in variables can change as the program executes Every variable has a name, type, size and a value. A variable name can be any meaningful identifier.

A. B. C. D.

I, II I, II, III I, II, III, IV None of the above

4. Evaluate the following statement. (Assume that all variables are integers: n = 9, m =16, a = 2 , c = 7) - m + sqrt A. 10 B. -10 ( n * n - a * m ) / 2 * a

C. 9
D. -8

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

CONFIDENTIAL

CS/APR 2009/CSC125/ITC120

5. Which of the following identifies the purpose of default in a s w i t c h statement? A. It terminates the s w i t c h statement. B. It identifies the values being compared. C. It executes only if the test value does not equal any of the other cases in the switch. D. It causes the compiler to skip the s w i t c h statement.

6. What is the result after the execution of the following code if p is 7, q is 10 and r is 15?
if { ( ( p > q) | | P = P + 1; q = p + 3; (p <= r))

} else r = r + 1;

A. B. C.
D.

p = 8,q = 11, r= 15 p = 7, q = 10, r= 16 p = 8, q = 10, r= 15


p = 7, q = 10, r = 15

7. Consider the program segment below: i n t b = 10; while ( b > 4 ) { cout b " "; b = b - 2; } cout b; What is the output of this program segment?

A. B. C. D.

10 10 10 10

9 8 8 9

8 7 6 5 4 6 4 6 8 7 6 5

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

CONFIDENTIAL

CS/APR 2009/CSC125/ITC120

8. What type of loop is used in the following program segment?

int count = 0; cin >> x; while ( x != -1) { count = count + 1; cin x; } cout << "count = " count << end;
A. B. C. D. A counter-controlled loop A flag-controlled loop A sentinel-controlled loop A nested loop

9. Which of the following statement is FALSE about a parameter of a function? A. B. C. D. The symbol ampersand (&) indicates the declaration of a reference parameter. Reference parameter is used to return more than one value from a function. All functions must have at least one parameter. The number of parameters in the function prototype must be the same as the number of parameters in the function call.

10. Which of the following is a valid function prototype for a C++ program that receives two integer values and returns an integer number? I. II. III. IV. A. B. C. D. int f8 (int, void f8 (int, void f8(int void f8(int, I I, IV I, III, IV II, III int); int & ); &, i n t &); int, int &);

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

CONFIDENTIAL

CS/APR 2009/CSC125/ITC120

PART B (80 MARKS) Answer ALL questions.

QUESTION 1 a) i. ii. Describe the following terms: Computer program Object code (4 marks)

b) List TWO (2) types of errors that can occur in the process of developing a program. (2 marks) c) Given the following declarations: const double pi = 3.142; int xyz = 4, abc = 5; Evaluate each the following C++ expression: . i. ii. v. v. cout cout cout cout cout 55 % xyz * 2 - 6 / xyz endl; 4 * xyz + piendl; 2 - (abc / 7) + 3endl; xyz % abcendl; "x + y = " xyz + abc e n d l ; (5 marks) d) Write a C++ assignment statement for each of the following arithmetic expressions.
( i

i.

V=

+ cd X 200

F = P 1+

5(x + y) x+3 z= 2mn .


IV

\lk-2h

.
+ / (4 marks) CONFIDENTIAL

- J=J

\2(k-h)
Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

CS/APR 2009/CSC125/ITC120

QUESTION 2

The National Earthquake Center has asked you to write a program implementing the following decision table to characterize an earthquake based on its Richter scale number. Richter Scale Number (n) n<5.0 5.0<n<5.5 5.5Sn<6.5 6.5<n<7.5 n>7.5 Characterization Little or no damage Some damage Serious damage: wall may crack or fall Disaster: houses and buildings may collapse Catastrophe: most buildings destroyed scale value and determines the earthquake

The program accepts the Richter characterization from the above table.

a) Draw a flowchart to solve the problem. (7 marks) b) Write a complete C++ program based on the above flowchart. (7 marks)

QUESTION 3

a) Write a C++ program based on the following pseudocode:

Set total to zero Set grade counter to one While grade counter is less than or equal Input the next grade Add the grade into the total Add one to the grade counter Set the average to the total Print the average divided by to ten

ten (5 marks)

b) Prompt the user to enter a positive number and store the value into variable n. Then calculate the total of the numbers from 1 until the value of n (1 + 2 +3 +...n). (5 marks)

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

CONFIDENTIAL

CS/APR 2009/CSC125/ITC120

c) Consider the following program: void main() { int i, j , x ,y; cout<<"\nEnter the first number between 1 - 20"; cinx; cout"\nEnter the second number between 1 - 20"; cin>>y; for (i=l; I <= y; i++) { for(j=l; j <= x; j++) cout"@"; cout"\n"; } } i. What output is produced if the value of x is 3 and y is 4? (4 marks) ii. Explain the purpose of the program. (2 marks)

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

CONFIDENTIAL

CS/APR 2009/CSC125/ITC120

QUESTION 4

a) Write the definition for each of the following C++ functions: i. Function C a l c u l a t e P e t r o l ( ) receives the amount in liters. Calculate and return the total cost of petrol. (2 marks) Function C a l c u l a t e D i e s e l ( ) receives the amount in liters. Calculate and return the total cost of diesel. (2 marks)

ii.

iii. Function c a l c u i a t e G a s ( ) receives the amount in the amount in liters. Calculate and return the total cost of gas. (2 marks) (NOTE: 1 liter of petrol: RM2.70, 1 liter of diesel: RM2.58, 1 liter of gas : RM0.68)

b) Write a main program that uses the above functions. The user will enter the amount of fuel in liters and selects the desired fuel type from the following menu:

CHOICE 1 2 3 4

FUEL TYPE Petrol Diesel Gas Exit

The user has to input the choice. The program will compute and display the total cost of fuel purchased. Display the appropriate message when the user enters any invalid choice. (9 marks)

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

CONFIDENTIAL

CS/APR 2009/CSC125/ITC120

QUESTION 5

DontMind Sdn Bhd offers weekly payment for its employees and the rate is as follows: Regular rate of RM4.00 per hour for the first 40 hours 1.5 times the regular rate for each hour over 40 through 50 Double the regular rate for each hour over 50

a)

Write a function that receives the hours worked for an employee and return its gross pay. For invalid inputs, display "invalid input" message. (7 marks) From the employee's gross pay, the following deductions are made: 8% for income tax deduction 10%forKWSP RM10.00 for the employee's union

b)

Write a function that receives employee's gross pay and return the total deductions. (5 marks) c) Write a main program that requires the user to enter the employee's id and hours worked per week. The program will calculate the gross pay, deduction and net pay for each employee by using the above functions. Print a slip for each employee that displays the employee id, gross pay, deduction and the net pay. This process will continue until the user requests to stop. The program will also calculate and print the total net pay for all employees in the company. (8 marks)

END OF QUESTION PAPER

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

Vous aimerez peut-être aussi