0% found this document useful (0 votes)
53 views6 pages

Midterm 3

This document contains instructions for a midterm exam in computer science including an honesty policy statement to sign, questions to answer, and sample code segments. The exam covers topics like recursion, arrays, sorting, and file input/output and requires completing functions, writing code, and showing output. Students must show their work, write their name, and sign the honesty policy to complete the exam.

Uploaded by

Shady Maged
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views6 pages

Midterm 3

This document contains instructions for a midterm exam in computer science including an honesty policy statement to sign, questions to answer, and sample code segments. The exam covers topics like recursion, arrays, sorting, and file input/output and requires completing functions, writing code, and showing output. Students must show their work, write their name, and sign the honesty policy to complete the exam.

Uploaded by

Shady Maged
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

The American University in Cairo

De rtmento Com uter Science En ineerin


MidtermExam Ill Fall 2019
Dr. KHALIL - CSCE 1001
First Name: ID:..q.oo.(qd23/q

Last Name: Form —I Section No. (0 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:

DO VOT USE rms SECTION


Question Points Grade
1 20
20
2 20

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

} //end SUM function


computes
creates and initializes the following array B,
2. Write only the C++ main functionthat above recursive function
SUM
and displays the sum of its elementsusing the

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

hquo T5J& PLCTTS.

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);

// end DOD function


Output• Output:

boolv date I int ECT (int);


int main() int main()
( int num(10J = {1001, 120, 103, 101, 100};
int s = O;
for ( int k = O; k < 3; k++) for ( int F = O; F < 4; F++ )
if( ) s = s + FCT(F);
cout << num[kl << endl; cout << "Final Result = " s << endl;
return O; return O;
) // end function main ) // end main function

bool validateB ( int n ) int ECT ( int n)


{ const int ten = 10; { intf=l;
while ( n O) for ( int c = 2; c n;
if (n % ten > 1)
return false; return f;
else ) // end FCT function
n = n/ ten;

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)•.

cin >> n; // enter value for the variable n


A = newstring(nl;
for ( int c = O; c < n; c++)
cin A(cl;
for ( int c = O; c < n; c++ )
cout Atcl endl;
tuns ( A, n
for ( int c = O; c < n; c++ )
out A(C) endl•,

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

1. Write only the C++ main


a. Create the above function to perform the following:
array and populateonly
function main does not its shaded cells with the shown data. The
b. Compute and display take any inputfrom the keybo d.
the sum of each row.

Sum
G.;.C4+)
'SLIP(r)
e-or(itu C3 "5urm
o/ << H

Bonus Problem of 10 oints

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..F 0.3 r < %

.[c.JCc.J.r- C.85'0 10
C)

GoodLuck
6

You might also like