Professional Documents
Culture Documents
Midterm 2
Midterm 2
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
—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
...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)
..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
.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
.
"
cout << "Enter name of a student:
cin >> ..onme.(.4.a..'
"
cout << "Enter student score between O and 100:
cin >>
while( ) li validating entered score
5
4/ processing —rearr e list of stydents
us)ng-Bubble Sorting
for
cout << setw(10) << name. setw(10) << score.. .4; endl;
system ("pause");
return O;
...n.l..%..n.Å.'a
GoodCuce
6