Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

The American University in Cairo

Computer Science Engineering Department


CSCE 1001-03809
Midterm Exam Il Fall 2019
Dr. KHALIL
ID: {284
First Name:
Form Il Section No. )
Last Name:
E.vamInstructions
Do not turn this page until asked to do so.
Exam time is 75 minutes.
papers. even for scratch.
Put the answers on the same question sheet, do not use any additional
Write your name, ID. section no. in the indicated places.
Read the exam instructions.
Read the honesty policy.
Sign the following statement.
Academic Integrity Policy
Whispering. talking, looking at someone else's
Cheating in Exams is a violation of the Academic Integrity policy of AUC.
of these actions or her/his answers
paper. or copying from any source is consideredcheating. Any one who does any
zero in this exam to failing the course. If
indicates that she/he did any of them, will receive a punishment ranging from
repeated, it may lead to dismissal from AUC.
as entirely my effort.
I have read the honesty policy and exam instructions and I am presenting this exam
Signature:

DO NOT USE Tills SECTION

Question Points Grade


1 20

2 20 20
3 20

4 20
20
5 20 20
Total 100 100

1
the out ut
of each of the followin
ro ram se ments:
for ( int C = 1; C
switch ( R % 3 ) ) bool bob( int
int main ()
{ case 1'
{ int num(10J= {1001, , 102. 101.1011}:
case 2: for ( int k = O, k < 3; k++ )
cout setW(2) if
break; cout setw(3) k
default' setw(3) num(kJ end}.
return O.
cout setw(2) } // end function main
cout bool bob ( int n )
endl; { while(n 0)
if (n % 10 > 1)
return false.
else

return true.
// end function bob
——4oof

void swapN(string&, string&);


int dod (int. int, int);
void swapG(double&, double&);
int main ()
int main() {int a = 80.9. b: 55.5. c = 66.6;
cout •Result = • setw(4) dod(a. b. c)
string name(10) = {"Deena"."Alf. "Ahmed"): endl;
doublegpa [101= {3.4. 2.4, 3.7}. n = 3; systemCpause');
for ( int r retumO:
for ( int c = O; c < n - r; c++ ) ) l/ end functionmain
if ( name(c+l) < name(c))
{ swapN(name(c), name(c+l)); int dod( int x, int y. int z)
gpa(c+l));
{ intm;
if (x > y)
cout "The New List: " endl;
for ( int k = O; k < n; k++ ) else
cout setw(8) name(k) setw(4) gpa(k) endl;
return O;
} // end main function
void swapN(string& a, string& b)
{ string TS = a; retumm;
) Il end functiondod

void swapG(double& x, double& y)


{ double T = x;

—Ahr-tcl___

2
estion 2 20 oints
rite only the C++ loop to generate each of the followingsequences:

7 14 21 28 35 49 56 63 70 77 91 98

C.; .45. Z .<.4003.044)


(C O).
7..i'. G

(DC.(.9 c.f d J C Z.(QQ.:, .C.4.4.)


LC.C .e.

question 3 (20 points)


sumOdd that takes a Write a C++ functionExists that takes a big
Write a C++ function a single digit to
the positivie integer number and
positivie integer number to return back exist in the
return true if the single digit does
a). .. big number and false, otherwise.
Lß....sum()
.;nl..tt...)...

...Sum.+...?.... else
.u.C.n..sum.'.
use
estion 4 (20 points)
Write the nested C++ loops to
producethe followingpatterns:

2 3
c <q c.fö
2 3 4 5
I keg c 3
(C 0/02
2 3 4 5 6 7

2 3 4 5 6 7 8 9

It)

2. Write only the C++ code to performthe following:


Create the shown array.
• Populate only the shaded cells with the shown symbols.

..sæ.

10
otion 5 (20 points) students in a test. The
followingIncompleC++ programtakes and stores_nameand score of each of n is an integer
(inclusive) and each score
umberof students (n) is a positive integer number between 10 and 50 order
between 0 and 100 (inclusive). The program rearranges the list of the students in an ascending
formats.
'lumber
the ordered list in proper
according to the score value using bubble sorting. Last, the program displays
and executed.
Complete the missing parts of the program in order to be correctly compiled

#include <iomanip> #include <string> #include <iostream>


using namespace std;
s4n'

.MÆ.I....5Q4f.Sr.acø..Cjtal&
int main()
{ Il Declaration
e Il an array to store names of students
students
.;ru 'Gre //an array to store scores of
Il the number of students
Il Input the number of students
and 50: "
cout << "Enter the number of students n between 10
cin n;
) // validating n

.p.{.-h.lcr
.

Il Input, validate and store data of the n students


for ( int c = .a. .Æ..<.O...' ...Z,å+

"
cout << "Enter name of a student:
cin >> ..onme.(.4.a..'
"
cout << "Enter student score between O and 100:
cin >>
while( ) li validating entered score

cout << "Invalid score, Reenter:

5
4/ processing —rearr e list of stydents
us)ng-Bubble Sorting
for

//Output the sorted list

for( ....la, ...C..G.Q..'. ...C...<.YW '

cout << setw(10) << name. setw(10) << score.. .4; endl;
system ("pause");
return O;

} Il end function main

l/ Definition of function swapNames


..VD' .. swapNames( V..n2.

...n.l..%..n.Å.'a

//Defi ition of function swapScores


swapScores( ..iu..sd....,...u..ü.... )

GoodCuce
6

You might also like