Midterm 3
Midterm 3
TION INSTRUCTIONS
DO tum this page until asked to do so.
Examtime 75 minutes.
• Put the answerson the same question sheet.do use any additionalpapers.even for scratch,
Wntc your name. ID. no. •n thc indicated places.
• Readthc examinstructions.
Read the honestypolicy.
Sign the follow•ng statement.
Academic Integrity Policy
Cheating in Exams is a Oolation of the Acadcmjc Integritypolicy of AUC. Whispering. talking. looking at someone else's
paper. or copymgfrom any source is consideredcheating. Any one who does any of these actions or her/his answers
indicatesthat shemcdid any of them.will receivea punishmentrangingfrom zero in this exam to failing the course. If
repeated. 't may lead to disnussal from AUC.
I have read the honesty policy and exam instructions and I am presenting this exam as entirely my effort.
Signature:
3 20
4 20 20
5 20 + 10
Total 100 + 10
ruestion 1 (20 points)
start index
1. Complete the followingC++ recursive functionSUM that takes as inputthe array A, through
ss, and end index ee to compute and returnthe sum ofÅy+6f all the elements
the indices from ss to ee (inclusive).
if (
rc%r..a...ALea... //stopping case
else
y.. T)Ccgn( \
03.
2
Question 2 20 oints
1.write a C++ function
SINGLE DIGIT" if the
that takes a positive
integer
"THREE BIG DIGITS". number has only one digit, numberand returnsback the message "ONE
if the number "TWO BIG DIGITS" if the number has two digits.
has three digits, or "MORE AND MORE DIGITS", if the number
(n < 10)
.01) 6L (n <toc
2. Write a C++ function Zero that takes a positive integer number and returns true if the number
contains at least one Zero digit, and false otherwise. Write both the iterative and recursive definitions
of the function Zero.
Iterative Version Recursive V sion
.14 fro).
6
..rv.;o/..d.Q..'p..
rtÅy.r.4...4.Q(Q.'»..
auk
3
s io oi s
Show the out t of each of the followi ram se ments:
jnt (1. int DOD (int, int);
do
3
int main ()
( X = 24. Y = 18; end';
B(k) = B(k-ll + B(k-2); cout "Result = " DoD(X. Y)
) while ( < 13 y; return O;
//end main function
for ( int c = O;c < k; c++ )
cout setw(4) c setw(4) B[cl endl; int DOD ( int A, int B)
if ( 0)
return B;
else
return (B, A%B);
return true;
//end function validateB
Output: Output:
4
question 4 20 point') code with a user
1. Show the content ot screen output and the file out.dat after executing the following "Zenaib"
Dr. in ut 4 for the vanable n and the the students' names: "Mariam"."Karim". "Amr- and
typedef stnng• strPtr. Screen output Content o! tile eu!.éa!
void lunS( string (l, int z em,b
void tunW ( string&, string&);
jnt main()
strPtr A;
int n; // user Input variable
ofstream out;
out.openCout.dat')•,
if ( out.tail())
( cout 'Error to open tile"";
exit(l)•.
delete 0 A;
out.close();
system ("pause");
return O;
int size)
void funs (string Btl,
r++ )
for ( int r = 1; r < size;
size - r, c++ )
for ( intc = O;c < )
it ( > B[cl *esc'.
funw (B[cl, B(C+II);
) // end sort functiona, string& b)
void funW (string& a;
string temp =
b = temp;
code:
ut of the followin Output:
2. Show the out
typedef int• intPtr;
intPtr A;
int n 4;
c;
A = new int[nl;
n; c++ )
for ( int c = O:c <
A(cl = c + 1; AIC);
cout << setw(3)
cout endl;
Delete O A; 5
oints
estion5 20
Sum
G.;.C4+)
'SLIP(r)
e-or(itu C3 "5urm
o/ << H
6 7
11 12 13 14 15
16 17 18 19 20
2. Write only the code to create the above integer2-D array. use only nested loops and their
counters to initialize the arrav with the shown data. No variables other than the loops counters
and no input from the keyboard.
.[c.JCc.J.r- C.85'0 10
C)
GoodLuck
6