Professional Documents
Culture Documents
Form 1: 17 Questions at 5 Pts Each Max 80 Points (So You Get One Question On Us)
Form 1: 17 Questions at 5 Pts Each Max 80 Points (So You Get One Question On Us)
Part
1
17
questions
@
5
pts
each
max
80
points
(so
you
get
one
question
on
us)
Form
1
Instructions:
Read
Carefully!
1.
On
the
scantron
sheet,
bubble
&
enter
your
name
and
UMID
and
Form
number
and
sign
your
name
to
indicate
the
honor
pledge
below:
I
have
neither
given
nor
received
aid
on
this
examination,
nor
have
I
concealed
any
violations
of
the
Honor
Code.
2.
This
is
a
closed
book
exam.
You
may
not
refer
to
any
materials
during
the
exam.
3.
Please
turn
off
your
cell
phones
before
the
start
of
the
exam.
4.
Some
questions
are
not
simple,
therefore,
read
carefully.
5.
Assume
all
code
and
code
fragments
compile,
unless
otherwise
specified.
6.
Assume/use
only
the
standard
ISO/ANSI
C++.
1
1)
Ponder
the
following
code
fragment
int
level;
for
(level
=
10;
level
<
20;
level
+=
2)
{
//
do
nothing
}
cout
<<
level;
A)
2
B)
10
C)
20
D)
18
E)
the
code
does
not
compile
for
(int
level
=
10;
level
<
20;
level
+=
2)
{
//
do
nothing
}
cout
<<
level;
A)
2
B)
10
C)
20
D)
18
E)
the
code
does
not
compile
2
3)
Given
the
following
function
definition:
void
missingNo(int&
item)
{
item
*=
10;
}
A)
4
B)
100
C)
40
D)
400
E)
the
code
enters
an
infinite
loop
If
a
variable
life
of
type
int
is
initialized
to
100
what
does
the
C++
expression
adjustLife(life,
-‐20)
+
adjustLife(life,
-‐40)
evaluate
to?
A)
100
B)
120
C)
140
D)
40
E)
-‐60
3
5)
What
does
the
following
code
fragment
print?
int
main()
{
int
levelOfMeowth
=
27;
cout
<<
"Current
Level
:
"
<<
levelOfMeowth
<<
".
";
levelUp(levelOfMeowth);
if
(levelOfMeowth
>
27)
{
cout
<<
"Meowth
evolved
into
Persian!";
}
return
0;
}
int
main()
{
int
levelOfSquirtle
=
15;
cout
<<
"Current
Level
:
"
<<
levelOfSquirtle
<<
".
";
levelUp(levelOfSquirtle);
if
(levelOfSquirtle
>
15)
{
cout
<<
"Squirtle
evolved
into
Wartortle!";
}
return
0;
}
4
7)
What
does
the
following
code
print?
int
main()
{
int
grass[3][3]
=
{
{
0,
0,
1
},
{
0,
0,
0
},
{
1,
0,
0
}
};
for
(int
row
=
0;
row
<
3;
row++)
{
for
(int
col
=
0;
col
<
3;
col++)
{
if
(grass[row][col])
{
cout
<<
"Wild
Rattata
appeared
at
"
<<
row
<<
",
"
<<
col
<<
"!
";
}
}
}
return
0;
}
8) Which of the following conditions should you never use for reading a file inFile in a loop?
5
9)
Consider
the
following
code
(read
carefully!):
A)
Pikachu
B)
???
C)
Unknown
(Not
Unown!)
D)
[Nothing
Prints]
E)
Kyogre
//
REQUIRES:
The
size
of
the
array
is
length;
length
>=
1
int
maxLevel(const
int
levels[],
int
length)
{
int
maximum
=
levels[0];
for
(int
i
=
1;
i
<
length;
i
+=
1)
{
if
(levels[i]
>
maximum)
{
return
levels[i];
}
else
{
return
maximum;
}
}
return
maximum;
}
6
11)
Consider
the
following
code
fragment:
int
grade
=
70;
switch
(
grade
)
{
case
100
:cout
<<
"Grade
A
";
break;
case
80
:cout
<<
"Grade
B
";
break;
case
60
:cout
<<
"Grade
C
";
break;
default
:cout
<<
"This
one
is
easy!!";
}
What
prints?
A)
Grade
A
B)
Grade
B
C)
Grade
C
D)
This
one
is
easy!!
E)
the
code
does
not
compile
13)
Think
critically
about
which
test
case
exposes
the
potentially
buggy
swap
implementation
(read
carefully!):
7
14)
Consider
the
following
code
fragment:
ifstream
in;
in.open("file.txt");
in
>>
c;
while
(in
>>
x)
{
count++;
}
What
does
the
above
code
fragment
print,
if
file.txt
contains
2
4
a
3
4
5
4
?
Please
note
the
whitespaces
between
the
characters.
A)
0
B)
1
C)
2
D)
3
E)
4
8
15)
Consider
the
following
code
fragment:
//
REQUIRES:
The
size
of
the
array
is
n;
n>=
1
bool
harpDarp(const
int
array[],
int
n)
{
int
prev
=
array[0];
for
(int
i
=
1;
i
<
n;
++i)
{
if
(array[i]
<
prev)
{
return
false;
}
prev
=
array[i];
}
return
true;
}
What
would
misty
be
initialized
to?
int
first[3]
=
{3,
6,
6};
int
second[4]
=
{2,
4,
5,
3};
bool
misty
=
harpDarp(first,
3)
&&
harpDarp(second,
4);
A)
false
B)
true
C)
{3,
5,
7}
D)
{2,
4,
5,
3}
E)
None
of
the
above
9
17)
Consider
the
following
code
fragment:
C) 0 0 0 1 2
10