Professional Documents
Culture Documents
IT/Computer Programming)
Final Exam
FORM A Date: 18/1/2012 Time: 11:30AM-1:30PM
14
14
18
14 80
TOTAL
Page 1 of 9
2- What is the output of the following code? int x[3]= {630,8,3}, y[3]= {196,4}; int z[3], i; for(i=0;i<3;i++){ z[i]= x[i]; x[i]= y[i]; y[i]= z[i]; cout<<x[i]<<" "<<y[i]<<" "<<z[i]<<endl; }
OUTPUT
3- What is the output of the following code? int getMe(int x){ static int m=2; m+=x%3; cout<<m<<endl; return m; } void main(){ int s=0; for (int i=1;i<=3;++i) s+=getMe(i); cout<<s; } OUTPUT
Page 2 of 9
4- What is the output of the following code? int k=7, y=5; void lookup(int y, int& x, int z=2) { x+=k; cout<<y<<"\t"<<x<<"\t"<<z<<endl; } void main(){ int k=3,m=1; cout<<k<<"\t"<<y<<"\t"<<m<<endl; lookup(10,m); cout<<k<<"\t"<<y<<"\t"<<m<<endl; } OUTPUT
Page 3 of 9
Question 2 [5 Points]
Identify the Input, Output variables and their most applicable data types for the following problem: A car rental company has 5 categories of cars for rentals (economy, sport, SUV, 7Seaters and Luxury). The company wants to generate a weekly report showing the total number of cars rented for each category during a week, the name of the highest rented car category, the name of the least car rented category and the average car rented per week for each category.
Page 4 of 9
*#
**# *##
Page 5 of 9
Question 4 [7 + 7 = 14 Points]
A) Write a function that accepts a train code of type character (lower or uppercase) and returns the corresponding train type according to the following table: Train Code S or s D or d E or e Others Train Type Steam Diesel Electric Invalid
B) Write a program that prompts the user to enter 10 train codes (char) and displays their corresponding train types by using the function defined in Part A. The Input/output of the program should be displayed as follows:
Enter 10 train codes: S This code represents Steam Train Type M This code represents Invalid Train Type d This code represents Diesel Train Type .
Page 6 of 9
Screen Output
Maximum is 103 and it is found at index 2 All numbers that the maximum are: 8 22 13 -5 comes after
Page 7 of 9
0 3 0 9 0
1 0 1 6 0
2 0 1 7 0
5 21 0 0 0
6 0 4 0 1
Then the output of the function should be displayed as follows: Week 1 2 3 4 Rainfall data 3 0 0 7 8 21 0 1 1 0 0 0 9 6 7 0 0 0 0 0 0 0 0 0 Total 39 6 22 1
0 4 0 1
Page 8 of 9
Page 9 of 9