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

. Do ( cout << “a=” << a. i) Assume a is int and a=1. /*********************************************** ** Put a banner on your programs ************************************************ #include (iostream) using namespace std void <main>void [ cout<<" This program has a \n large number of errors. write the word “VALID” and explain the expected output. a. However if invalid. Part II Answer ALL questions. a++) while (a<5): [3 marks] ii) for (day=1. you will \\ get better at debugging. Brackets can immediately follow a pointer variable name in an executable statement. write the word “INVALID” and state why it is invalid and correct it. day<3. No space is allowed between the * operator and the data type in a declaration. day ++) [3 marks] ________________________________________________________________________ Cik Rohana Binti Sapawi 2/4 SULIT .\n’ . a-. If valid.) ] [10 marks] Question 2 [12 marks] In this section.". Question 1 [ 10 marks ] Debug the progam until it produced the following output. cot (As you program more and more. while ( a<5 ) { cout <<”a=” << a .SULIT PEPERIKSAAN AKHIR SEMESTER 1 SESI 2005/2006 KNL 1353 PEMPROGRAMAN BERSTURUKTUR 08 NOVEMBER 2005 ____________________________________________________________________________________________________________ 19. } [3 marks] b. As the program more and more. cout<<"\nUse the method we \ described to fix it. 20. Use the method we described to fix it. This program has a large number of errors. you will get better at debugging. examine the C++ statement carefully and write whether they are valid or invalid.

c=0. !x="<<!x<<endl.SULIT PEPERIKSAAN AKHIR SEMESTER 1 SESI 2005/2006 KNL 1353 PEMPROGRAMAN BERSTURUKTUR 08 NOVEMBER 2005 ____________________________________________________________________________________________________________ iii) float a23b[99]. !b="<<!b<<endl. cout<<”Before call to april( )”<<endl. if ( c ) cout<<"Never gets printed"<<endl. !c="<<!c<<endl. b and x if initially x is 5? [6 marks] Question 4 [ 32 marks] Write the expected output for the following C++ statement below. int main( ) { int friends_birthdays=0. cout<<"x="<<x<<". cout<<”days_in_month = “<<days_in_month<<endl <<”friends_birthdays =“<<friends_birthdays<<endl<<endl. x= a>b || b>c && a==b. else cout<<"c="<<c<<". [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. 1xy[66]. else cout<<"Answer is FALSE\n". int days_in_month = 31. int main ( ) { int a=4. x. b=-2. if ( a ) cout<<"a="<<a<<". a) #include <iostream> using namespace std. } [10 marks] b) #include <iostream> using namespace std. !a="<<!a<<endl. if ( b ) cout<<"b="<<b<<". void april( ). ________________________________________________________________________ Cik Rohana Binti Sapawi 3/4 SULIT . if ( a>b || b>c && a==b ) cout<<"Answer is TRUE\n".

The content are line 1 score1 score2 score3…. Print the result to file GRADE. i<=5. Grade …. i+=2) { for (j=1.SULIT PEPERIKSAAN AKHIR SEMESTER 1 SESI 2005/2006 KNL 1353 PEMPROGRAMAN BERSTURUKTUR 08 NOVEMBER 2005 ____________________________________________________________________________________________________________ april( ). int main ( ) { int i.OUT in the following table: Numerical score ……. m. } [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. j. } m=k+i. j= "<<j<<". cout<<"i= "<<i<<". j<=4. for (i=1. j++) { k = i+j. ….. k. …….DAT. cout<<”After call to april( )”<<endl. score10. the program is to read the 10 scores (all integer) from the data file GRADE. days_in_month=30. [20 marks] ________________________________________________________________________ Cik Rohana Binti Sapawi 4/4 SULIT . k= <<k<<endl. } void april( ) { int friends_birthdays=2. } [10 marks] c) #include <iostream> using namespace std.. As input. cout<<”days_in_month = “<<days_in_month<<endl <<”friends_birthdays =“<<friends_birthdays<<endl<<endl..

Sign up to vote on this title
UsefulNot useful