Anda di halaman 1dari 11

CONFIDENTIAL

CS/OCT 2010/CSC316/425

UNIVERSITI TEKNOLOGI MARA FINAL EXAMINATION

COURSE COURSE CODE EXAMINATION TIME

: : : :

STRUCTURED PROGRAMMING / INTRODUCTION TO COMPUTER PROGRAMMING CSC316/425 OCTOBER 2010 3 HOURS

INSTRUCTIONS TO CANDIDATES 1. This question paper consists of three (3) parts : PART A (15 Questions) PART B (4 Questions) PART C (1 Question) Answer ALL questions from all three (3) parts : i) ii) Answer PART A in the Objective Answer Sheet. Answer PART B and PART C in the Answer Booklet. Start each answer on a new page.

2.

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 an Objective Answer Sheet - provided by the Faculty

4.

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


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

CONFIDENTIAL PART A (30 MARKS) Answer ALL questions.

CS/OCT 2010/CSC316/425

1. Choose the CORRECT sequence of Problem Development Life Cycle (PDLC): A. B. C. D. Analysis -> Implementation -> Design -> Testing -> Maintenance Design -> Analysis -> Implementation -> Testing -> Maintenance Analysis -> Design -> Implementation -> Testing -> Maintenance Analysis -> Design -> Testing -> Implementation -> Maintenance

2. Symbol below illustrate the

A. B. C. D.

Input/Output Process Begin/End Condition

in the flowchart.

3. Suppose that x = l a n d y = o, the statement r e s u l t = x / y ; A. B. C. D. Logic Error Syntax Error Run Time Error No Error

produce

4.

The process of translating the high level source code into machine code requires A. B. C. D. Assembler Compiler Preprocessor directive Linker

5. Choose a VALID C++ identifier.

A. B. C. D.

GPA 2Barang My Name Is X-Ray

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

CONFIDENTIAL

CS/OCT 2010/CSC316/425

6. Suppose that x = 5 and y = 6. Select the CORRECT output of the following C++ statement: cout<<"Sum of "<<x<<" and "<<y<<" = "<<x+y<<endl;

A. Sum of 5 and 6 = 11 B. Sum of x and y = 11

C. D.

Sum of x and y = x+y Sum of 5 and 6 = x+y

7. Calculate the value of the expression 46 + A. B. 51.0 51.5 C. D.

1 5 . 0 / 2 - 1 52.5 61.0

8. Consider the following declaration char statements stores "Blue s k y " into s t r ? A. B. C. D. str = "Blue Sky"; str[15] = "Blue Sky"; strcpy(str, "Blue Sky"); strcpy("Blue Sky");

s t r [ i 5 ] ; . Identify which of the following

9. Produce the output of the C++ code below: int x = 3 5; int y = 45; int z; if(x > y) z = x + y; else z = y - x; cout << X << " " << y << " " << z <<endl;

A. B.

35 45 80 35 45 10

C. D.

35 45 - 1 0 35 45 0

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

CONFIDENTIAL

CS/OCT 2010/CSC316/425

10. Analyze the C++ codes below and select the CORRECT output. void main() int number = 2; if (number == 2) number = number if (number == 3) number = number if (number == 4) number = number if (number == 5) number = number cout << number;

+ 2; - 2; * 2; / 2;

}
A. B. 6 7 C. D. 8 9

11. Determine the output of the following program fragment. void main 0

{
int y = 8, number = 0; whil e (y < 10)

{
number = number + l; y--;

}
cout << number }

}
A. B. C. D. 2 0 The program has a problem of infinite loop. The program has syntax error.

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

CONFIDENTIAL

CS/OCT 2010/CSC316/425

12. Given the declaration below, i n t gamma int j ; [50];

Which of the following for loops produce the index of gamma out of bounds? A. f o r ( j = 0 ; j <= 4 9 ; j++) c o u t < < g a m m a [ j ] < < " "; B. f o r ( j = 1 ; j < 5 0 ; j++) cout<<gamma[j]<<" " ; C. f o r ( j = 0; j <= 5 0 ; j++) cout<<gamma[j] <<" "; D. for(j = 0; j <= 48; j++) cout < <gamma[j]< <" ";

13. Given the function prototype v o i d m y s t e r y ( i n t l i s t [] , i n t s i z e ) ; declaration i n t a l p h a [50] ;, select a VALID call to the function mystery? A. mystery(alpha[50] ) ; B. mystery(alpha[],50); C. mystery(alpha,50); D. mystery(alpha{50});

and the

14. Suppose that p r i n t H e a d i n g is a function without any parameters. Select a VALID function heading from the following C++ statements. A. B. C. D. void void void void printHeading() printHeading(noParameters) printHeading(); printHeading(void);

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

CONFIDENTIAL

CS/OCT 2010/CSC316/425

15. Determine the output from the following program fragment.


void functl(int,int); void funct2(int, int&); void main()

{
int x = 4, y = 6; functl(x,y); funct2(x,y); cout << y << setw(3)<< x;

}
v o i d f u n c t l ( i n t a, i n t b) {
b = a + b;

} v o i d f u n c t 2 ( i n t p , int& q) { q = q - p;

_J
A.
B.

-2
4

4
-2

C.
D.

4
2

2
4

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

CONFIDENTIAL

CS/OCT 2010/CSC316/425

PART B (50 MARKS)

QUESTION 1 Four workers were responsible to pluck oranges. The owner of the orange farm will be given 40% of the oranges. The workers share equally the balance of the oranges. Calculate and print the amount of oranges that were received by the owner and each of the workers. a) Identify the input, process and output from the above problem. (4 marks) b) Write a pseudo code to represent the steps to solve the problem. (7 marks) c) Illustrate the solution using a flowchart. (7 marks)

QUESTION 2 Write C++ statements to accomplish each of the following tasks. a) Calculate the remainder of q divided by p and assign the result to q . (1 mark) b) Determined whether a person's age equal to 30 and his or her height is taller than 6 feet. (1 mark) c) Declare a variable name to be type of string that can store 20 characters. Assign "Mohd Azmi Hassan" to variable name . (2 marks) d) Add variable num to variable sum and assign the result to variable sum. (1 mark) e) Assign commission as 15% if t o t a l _ s a l e s exceed RM1000.00 (2 marks)

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

CONFIDENTIAL QUESTION 3

CS/OCT 2010/CSC316/425

a) Trace and determine the output of each the following program fragment.

i .

void

main()

{
int x = 3 ; int y = 9; int z = 77; if ( x == ( y / 3 ) ) cout << "H"; if ( z != 77 ) cout << "q"; if ( z == 77 ) cout << "e"; if ( z * y + x < 0 ) cout << "g" ; if ( y == ( x * x ) ) COUt << "11"; cout << "o!" << endl;

}
(2 marks)

ii. v o i d main()

{ int a; cin >> a; //the value entered is 30

if (a % 2 == 0) cout << "\n Divided by 2"; if (a % 3 == 0) cout << "\n Divided by 3"; if (a% 4 == 0) cout << "\n Divided by 4";

}
(2 marks)

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

CONFIDENTIAL

CS/OCT 2010/CSC316/425

void drawSomething(int) ; void main() { i n t x;

cin >> x; //the value entered is 3 drawSomething(x);

}
void drawSomething(int i) { for (int x=l;x<=i;x++) { for ( i n t y=l;y<=x;y++) {
COUt << "*";

} cout<<"\n" ; } } (2 marks)

iv.

void main( { i n t x [3] ; x[0]=4, x[l]=-3,x[2]=7; x[0]=x[0]+x[l] ; i n t sum = x [0]+x [1]+x [2] ; c o u t << sum; (2 marks)

b) Five thousand ringgit is deposited into a savings account in year 2010 and an additional RM1000 is deposited at the end of each year. If the money earns interest at the rate of 8 percent, how long will it take before the account contains at least one million ringgit? Write a program by using do...while loop statement to solve the problem. (10 marks)

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

CONFIDENTIAL QUESTION 4 a) Given the declaration as follows:

10

CS/OCT 2010/CSC316/425

const int ARRAYSIZE = 5; float alpha[ARRAYSIZE]; i) How many elements are in alpha array? (1 mark) ii) Using a f o r statement, write a program to assign the value of 1.2, 1.7, 2.3, 9.1 and 1.6 from user input to the a l p h a array. (2 marks) iii) Based on the question (b), what is the value of y after the following statement is executed? y = int(alpha[1]) + alpha[4] / alpha[3] * pow(alpha[2],3); (2 marks) b) Write a fragment of codes to find and display the minimum and maximum of data in a r r a y A using a w h i l e loop. Array a r r a y A has the following details: float arrayA[10] = {12.1, 10.6, 23.7, 9 . 1 , 15.9, 20.3, 30.7, 2.4, 6.8, 7.1}; (6 marks)

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

CONFIDENTIAL PART C (16 MARKS)

11

CS/OCT 2010/CSC316/425

QUESTION 1 a) Write a function definition to calculate how much Malaysian Ringgit would be required to exchange either into US Dollar, European Euro or UK GBP. The function has the following prototype: double buy_currency(int, double); The first parameter is for the type of currency where the numbers 1, 2, 3 would be used to represent the Dollar, Euro and GBP respectively. The second parameter would be the amount of money to be exchanged. The function would return the amount of Malaysian Ringgit. You are given the following exchange rate: (Dollar) $1 (Euro)1 (GBP)1 = RM3.25. = RM4.78 = RM4.94 (8 marks) b) Write another function definition to display the amount in Malaysian Ringgit and the amount of the exchanged currency. This function will accept two parameters which are the amount of Malaysian Ringgit and the amount of the exchanged currency. The function has the following prototype:

void display_currency(double,

double);
(3 marks)

c) Write a main program that will input the type of currency and the amount of money. The program would display (5 marks)

END OF QUESTION PAPER

Hak Cipta Universiti Teknologi MARA

CONFIDENTIAL

Anda mungkin juga menyukai