You are on page 1of 4

SULIT PEPERIKSAAN AKHIR SEMESTER 1 SESI 2005/2006 KNL 1353 PEMPROGRAMAN BERSTURUKTUR 08 NOVEMBER 2005 ____________________________________________________________________________________________________________

Part I [ 20 marks ] Answer true or false. Each question carries 1 mark. 1. 2. 3. 4. The name of primary function of a C++ program must be Main. By default, any C++ statement is location sensitive. The statement cout << setw(5) | setfill ( & ) << X; displays &&123. The statement cout << c1 ; causes the character assigned to c1 to be printed to the screen. We need the ofstream header to write output to an external file. You must create link between an external disk file and an ifstream object before you can read your input data. A switch statement can be replaced by if-else-if control structure. Given x=200 and y= -400, determine whether each of these logical expression is true or false. ( x < y && x ! = y ) In a for loop expression, the starting counter value must be smaller than the ending counter value.

5. 6.

7. 8.

9.

10. In C++, day * = 5 may used as a third expression in for loop. 11. It is permissible to use constant in the argument list to call an overloaded function. 12. If there is ambiguity in a function call, the program will not compile. 13. Constructor functions cannot return values. 14. A function name is the only identifier that can be followed by parentheses. 15. We can use global variables to size arrays that are members of classes. 16. We cannot modify const type data in programs. 17. A partial filled multidimensional array has all its filled memory positions together at the beginning of the reserved block of memory. 18. To efficiently work with a multidimensional array, it is necessary to pass the filled size of the array as separate arguments in a function call.

________________________________________________________________________
Cik Rohana Binti Sapawi 1/4 SULIT

SULIT PEPERIKSAAN AKHIR SEMESTER 1 SESI 2005/2006 KNL 1353 PEMPROGRAMAN BERSTURUKTUR 08 NOVEMBER 2005 ____________________________________________________________________________________________________________

19. Brackets can immediately follow a pointer variable name in an executable statement. 20. No space is allowed between the * operator and the data type in a declaration.

Part II Answer ALL questions. Question 1 [ 10 marks ] Debug the progam until it produced the following output. This program has a large number of errors. Use the method we described to fix it. As the program more and more, you will get better at debugging. /*********************************************** ** Put a banner on your programs ************************************************ #include (iostream) using namespace std void <main>void [ cout<<" This program has a \n large number of errors.\n ; cout<<"\nUse the method we \ described to fix it."; cot (As you program more and more, you will \\ get better at debugging.) ] [10 marks] Question 2 [12 marks] In this section, examine the C++ statement carefully and write whether they are valid or invalid. If valid, write the word VALID and explain the expected output. However if invalid, write the word INVALID and state why it is invalid and correct it. i) Assume a is int and a=1, a. while ( a<5 ) { cout <<a= << a ; a-- ; } [3 marks] b. Do ( cout << a= << a; a++) while (a<5): [3 marks] ii) for (day=1, day<3, day ++) [3 marks]

________________________________________________________________________
Cik Rohana Binti Sapawi 2/4 SULIT

SULIT PEPERIKSAAN AKHIR SEMESTER 1 SESI 2005/2006 KNL 1353 PEMPROGRAMAN BERSTURUKTUR 08 NOVEMBER 2005 ____________________________________________________________________________________________________________

iii)

float a23b[99]; 1xy[66]; [3 marks]

Question 3 [ 6 marks] Consider the following expression int a = ++ x int b = x ++ How would the first expression differ compared with the second expression? What is the value of a, b and x if initially x is 5? [6 marks] Question 4 [ 32 marks] Write the expected output for the following C++ statement below. a) #include <iostream> using namespace std; int main ( ) { int a=4, b=-2, c=0, x; if ( a ) cout<<"a="<<a<<", !a="<<!a<<endl; if ( b ) cout<<"b="<<b<<", !b="<<!b<<endl; if ( c ) cout<<"Never gets printed"<<endl; else cout<<"c="<<c<<", !c="<<!c<<endl; if ( a>b || b>c && a==b ) cout<<"Answer is TRUE\n"; else cout<<"Answer is FALSE\n"; x= a>b || b>c && a==b; cout<<"x="<<x<<", !x="<<!x<<endl; } [10 marks] b) #include <iostream> using namespace std; int days_in_month = 31; void april( ); int main( ) { int friends_birthdays=0; cout<<Before call to april( )<<endl; cout<<days_in_month = <<days_in_month<<endl <<friends_birthdays =<<friends_birthdays<<endl<<endl; ________________________________________________________________________
Cik Rohana Binti Sapawi 3/4 SULIT

SULIT PEPERIKSAAN AKHIR SEMESTER 1 SESI 2005/2006 KNL 1353 PEMPROGRAMAN BERSTURUKTUR 08 NOVEMBER 2005 ____________________________________________________________________________________________________________

april( ); cout<<After call to april( )<<endl; cout<<days_in_month = <<days_in_month<<endl <<friends_birthdays =<<friends_birthdays<<endl<<endl; } void april( ) { int friends_birthdays=2; days_in_month=30; } [10 marks] c) #include <iostream> using namespace std; int main ( ) { int i, j, k, m; for (i=1; i<=5; i+=2) { for (j=1; j<=4; j++) { k = i+j; cout<<"i= "<<i<<", j= "<<j<<", k= <<k<<endl; } m=k+i; } [12 marks] Question 5 [20 marks] The grading structure for a class is the following: 90-100 A 80-89 B 70-79 C 60-69 D <60 F Write a program that prints the grades for 10 different numerical scores. As input, the program is to read the 10 scores (all integer) from the data file GRADE.DAT. The content are line 1 score1 score2 score3.. score10. Print the result to file GRADE.OUT in the following table: Numerical score . . Grade .. ..

[20 marks]

________________________________________________________________________
Cik Rohana Binti Sapawi 4/4 SULIT

You might also like