Professional Documents
Culture Documents
Final Exam
FORM A Date: 24/7/2011 Time: 11:30AM-1:30PM
NOTE: THERE ARE (8) PAGES IN THIS TEST WRITE ONLY ONE SOLUTION FOR EACH QUESTION
QUESTION # 1
MARKS 20
COMMENTS
14
16
16
14 80
TOTAL
Page 1 of 8
2- What is the output of the following code? OUTPUT int int for { } for(int j=3; j>0; j-=2) { cout << y[j] <<'\t'<< x[2*j] <<'\t'<< x[2*j+1]; cout << endl; } y[4],x[]={7,8,9,3,6,7,2,10}; n=0; (int k=0; k<8; k+=2) y[n]= x[k]- x[k+1]; n++;
3- What is the output of the following code? void doThat (int& x, int y) { y+=3; x+=5; } void main() { int n1=7, n2=1; cout<<n1<<"\t"<<n2<<endl; doThat(n1,n2) cout<<n1<<"\t" <<n2<<endl; }
OUTPUT
Page 2 of 8
4- What is the output of the following code? void XV(int x){ static int f=0; f+=pow(x,2); cout<<f<<endl; } void main(){ for (int i=1;i<=3;i++) XV(i); } 5- What is the output of the following code? cout<<fixed<<showpoint; cout<<setprecision(1); cout<<ceil(4.2)<<endl; cout<<floor(-3.4)<<endl; cout<<left<<setfill('#'); cout<<setw(8)<<sqrt(25.0); OUTPUT OUTPUT
6- What is the output of the following code? int y=5; void main() { cout<<y<<endl; int y=9; cout<<y<<endl; y+=3; cout<<y<<endl; } 7- What is the output of the following code? int Matrix[3][3]={ {1,2,-3},{4,5,6},{-7,8,9} }; int i,j,k; OUTPUT for (i=0; i<3;i++) for (j=0;j<3;j++) if (Matrix[i][j] < 0) Matrix [i][j] = 0; for (k=0;k<3;k++) cout << Matrix[k][3-k-1]<< endl; OUTPUT
Page 3 of 8
Page 4 of 8
PART B Write a main function that calls the function defined in PART A and prints the quality of the food.
Page 5 of 8
Screen Output
Average Cars Price = 3950.00 Cars with price less than the Average: Name Year colour Price Honda 2006 R 2150.00 Ford 2010 G 3750.00
Page 6 of 8
Then, the function should sum all the numbers around the array borders (see highlighted cells) and return the sum. In this example, the sum = 2+1+0+7+1+4+3+6+7+10+1+8+6+5= 61 Assume that the maximum number of columns in the array is 150.
Page 7 of 8
Page 8 of 8