THE AMERICAN UNIVERSITY IN CAIRO COMPUTER SCIENCE AND ENGINEERING

PREFACE NORTH AMERICAN NUMBERING COUNCIL (NANC) FUNCTIONAL REQUIREMENTS SPECIFICATION
RESOLUTION  (A11) PAGE 3 OF 4 AMERICAN MEDICAL
RESOLUTION 904  (I06) PAGE 2 AMERICAN MEDICAL ASSOCIATION

0 COMITÉ INTERAMERICANO CONTRA EL TERRORISMO (CICTE)
0 ORGANIZACION DE LOS ESTADOS AMERICANOS CONSEJO
0 X II INTERAMERICAN CONFERENCE OF OEASERKXII121

First Mid-term

The American University in Cairo

Computer Science and Engineering Department

CSCE 106

Dr. Eman Nasr

EXAM-III

Fall 2007

Last Name : ...........................................................

ID: ...................................

First Name: ...........................................................


EXAMINATION INSTRUCTIONS

* Do not turn this page until asked to do so.

* Exam time is 75 minutes.

* Put the answers on the same question sheet, do not use any additional papers, even for scratch.

* Write your name, and ID in the indicated places.

* Calculators are not allowed.

* Read the honesty policy.

* Sign the following statement.


HONESTY POLICY

Cheating in Exams is a violation of the honesty policy of AUC. Whispering, talking, looking at someone else’s paper, or copying from any source is considered cheating. Any one who does any of these actions or her/his answers indicate that s/he did any of them, will receive a punishment ranging from zero in this exam to failing the course. If repeated, it may lead to dismissal from AUC.


I have read the honesty policy and exam instructions and I am presenting this exam as entirely my effort.


Signature : _______________

---------------------------------------------------------------------------------------------------------------------

DO NOT USE THIS SECTION


Question

Points

Grade

I

20


II

35


III

10


IV

25


Total

90


Question I (20 points)

One interesting application of computers is the drawing of graphs and bar charts (sometimes called “histograms”). Write a C++ modular program that uses an iterative structure to read ten numbers (each between 1 and 30) into an array. For each number read, your program should print a line containing the read number (on two positions), followed by a space and then that number of adjacent asterisks. For example, if your program inputs 5, 10, 2, 7, 7, 7, 9, 9, 3, and 12, it should print:


5 *****

10 **********

2 **

7 *******

7 *******

7 *******

9 *********

9 *********

3 ***

12 ************


Define a function drawline that takes as an input an integer number and prints out its line (the integer number itself on two positions, followed by a space and then its corresponding number of '*').

Question II (35 points)

Draw the necessary flowcharts and create a complete C++ modular program that contains the following:

a. Function swap that takes two integer numbers and swaps them (interchanges their values).

b. Function readPair that reads two integer numbers each of which should be greater than 0 and if the second integer is less than the first, the function swap is called to interchange the values of the two integers.

c. Function multiple that determines for a pair of integers whether the second integer is a multiple of the first. The function should take two integer arguments and return true if the second is a multiple of the first, false otherwise.

d. Function main that will test k pairs of integer numbers. For each pair, the function readPair is called first to enter values for the two integer numbers, then the function multiple is called to test the two numbers. The program should print out the values of the two integers together with a message notifying whether the second integer is multiple of the first, or not.




Question III (10 points)

Please show the contents of the array A after its initialization and then after executing the given code segment:


int A[8] = {75,70,70,85,55,80,80,65}

int T;

 


initial

 


final

int n = 5;

 

A

 

A

for (int j = 0; j < n; j++)

A[0]


 

 

if (A[j] > A[j+1])

A[1]


 

 

{

A[2]


 

 

T = A[j];

A[3]


 

 

A[j] = A[j+1];

A[4]


 

 

A[j+1] = T;

A[5]


 

 

}

A[6]


 

 

 

A[7]


 

 



Question IV (25 points)

Please show the output of the following C++ program segments. Please show all of the necessary tracing too.


Segment 1

int x = 1, y = 1;


do

{

y= y * x++;

cout<<"x = "<<setw(3)<<x<<y<<"y = "<<setw(3)<<y<<endl;

} while (x < 4)


Output


Segment 2

int main()

{

int d = 17, e = 21, f = 15, a = 16, b = 19;

test (d, e, f);

cout << "In the main program after the first call, ");

cout << "the variables are: " << setw(3) << e << setw(3) << d << setw(3) << f << endl;

cout << “------------------------------------------------------------------------------------“ << endl;

test (a, b, f);

cout << "In the main program after the second call, ");

cout << "the variables are: " << setw(3) << a << setw(3) << b << setw(3) << f << endl;

return 0;

}


void test(int t, int& s, int& x)

{

s = 4;

s -= 3;

x %= (++s + ++t);

t = 2 * ++s;

cout <<"Function test Output:"<<setw(3)<<s<<setw(3)<<t<<setw(3)<<x<<endl;

}


Output





















6



1 ORGANIZACION DE LOS ESTADOS AMERICANOS
15 C OMISIÓN INTERAMERICANA DE MUJERES COMITÉ
2 AGRES 2141 (XXXVO05) PROGRAMA INTERAMERICANO


Tags: american university, american, computer, science, cairo, university, engineering