You are on page 1of 9

University of Bahrain College of Information Technology Department of Computer Science Semester I, 2011-2012 ITCS101/ITCS103 (Introduction to Computer Science &

IT/Computer Programming)

Final Exam
FORM A Date: 18/1/2012 Time: 11:30AM-1:30PM

STUDENT NAME STUDENT ID # SECTION #


NOTE: THERE ARE (9) PAGES IN THIS TEST WRITE ONLY ONE SOLUTION FOR EACH QUESTION QUESTION # 1 MARKS 15 COMMENTS

14

14

18

14 80

TOTAL

Page 1 of 9

Question 1 [15 Points]


1- What is the output of the following code? int x = 6; do { if ( x % 3 == 0) continue; else cout << x << "\t"; } while ( --x ); OUTPUT

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

Question 3 [14 Points]


Write a C++ program that asks the user to input a positive integer N and displays a shape consisting of * and # characters of N lines as shown below:
N=1 N=2 N=3 N=4

*#

**# *##

***# **## *###

****# ***## **### *####

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

Question 5 [18 Points]


Consider an existing file named data.txt containing unknown number of integers (maximum numbers in the file is 100). Write a program that reads all integers from the file and store them in an array. Your program should find the maximum number and the array index of the maximum number. Then the program should print all the numbers that comes after the maximum in the array (if any). Sample I/O is shown below. data.txt (Input file)
36 5 103 8 22 13 -5 .............

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

Question 6 [14 Points]


The rainfall figures in mm are available for each day of the past four weeks. Write a function generateReport() that displays the total rainfall for each week and the most wettest day. The function takes as parameter a two-dimensional array named, figures of size 4 x 7, that contains rainfall figures in which each row represent a week and each column represent a day. For example, if the array contains the following rainfall data: Days 3 4 7 8 0 0 0 0 0 0

Week 0 Week 1 Week 2 Week 3

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

The wettest day was day 6 in week 1.

Page 8 of 9

Page 9 of 9

You might also like