Professional Documents
Culture Documents
Form
1
Instructions:
Read
Carefully!
1.
On
the
scantron
sheet,
bubble
&
enter
your
name
and
UMID
and
Form
number
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++.
7.
All
code
and
input
is
written
in
a
fixed
width
font.
If
it
looks
like
a
space,
it
is
a
space.
8.
This
course
operates
under
the
rules
of
the
College
of
Engineering
Honor
Code.
Your
signature
endorses
the
pledge
below.
After
you
finish
your
exam,
print
your
uniqname
and
sign
below:
Print clearly:
I
have
neither
given
nor
received
aid
on
this
examination,
nor
have
I
concealed
any
violations
of
the
Honor
Code.
__________________________________________________________________
12.
Which
of
the
following
is
a
correct
implementation
of
isFull
given
the
following
RME:
(Project
5
based
-
Connect4
game
board)
//
Requires:
gameBoard
has
been
initialized
//
Effects:
Returns
true
if
the
gameBoard
is
full,
false
otherwise
bool
isFull(const
char
gameBoard[NUM_ROWS][NUM_COLS]);
Remember:
const
char
EMPTY
=
'
';
A)
for
(int
i
=
0;
i
<
NUM_ROWS;
++i)
{
for
(int
j
=
0;
j
<
NUM_COLS;
++j)
{
if
(gameBoard[i][j]
!=
EMPTY)
return
true;
}
}
return
false;
B)
for
(int
i
=
0;
i
<
NUM_COLS;
++i)
{
if
(gameBoard[NUM_ROWS
-
1][i]
==
EMPTY)
return
false;
}
return
true;
C)
for
(int
i
=
0;
i
<
NUM_ROWS;
++i)
{
for
(int
j
=
0;
j
<
NUM_COLS;
++j)
{
if
(gameBoard[i][j]
==
EMPTY)
return
false;
}
}
return
true;
D)
for
(int
i
=
0;
i
<
NUM_COLS;
++i)
{
if
(gameBoard[0][i]
!=
EMPTY)
return
true;
}
return
false;
E)
B
and
C
13.
What
is
the
effect
of
the
following
code?
(Be
careful
on
this
one.)
void
digimon(string&
digitalMonsters)
{
char
c
=
digitalMonsters[0];
for
(int
i
=
1;
i
<
digitalMonsters.length();
++i)
{
digitalMonsters[i-1]
=
digitalMonsters[i];
}
digitalMonsters[digitalMonsters.length()
-
1]
=
c;
}
A)
Rotates
all
of
the
letters
in
digitalMonsters
to
the
left.
B)
Rotates
all
of
the
letters
in
digitalMonsters
to
the
right.
C)
The
code
goes
out
of
bounds
under
some
conditions.
D)
The
code
goes
into
an
infinite
loop.
14.
Given
the
following
code:
int
rocket_power()
{
ifstream
ins;
ins.open("fish_taco_count.txt");
int
count
=
0;
string
woogidi;
ins
>>
woogidi;
while
(ins.good())
{
ins
>>
woogidi;
count++;
}
return
count;
}
What
is
returned
by
rocket_power()
if
the
input
file
contains
the
following?
Twister
ate
10
fish
tacos.
Otto
ate
3
fish
tacos.
Reggie
ate
5
fish
tacos.
A)
0
B)
15
C)
2
D)
The
code
does
not
compile
17.
Consider
the
following
code.
(Time
consuming)
struct
Looney
{
string
season;
};
int
main()
{
Looney
toon;
bool
duck
=
true;
bool
rabbit
=
false;
int
i
=
0;
while
(i
<
3)
{
if
(duck)
{
toon.season
=
"DUCK
SEASON";
rabbit
=
!rabbit;
}
if
(rabbit)
{
toon.season
=
"RABBIT
SEASON";
duck
=
!duck;
}
cout
<<
toon.season
<<
"!
";
i++;
}
}
What
prints!!!?
(after
all
it
is
Looney
Toons)
A)
RABBIT
SEASON!
RABBIT
SEASON!
DUCK
SEASON!
B)
DUCK
SEASON!
RABBIT
SEASON!
DUCK
SEASON!
C)
RABBIT
SEASON!
DUCK
SEASON!
RABBIT
SEASON!
D)
RABBIT
SEASON!
RABBIT
SEASON!
RABBIT
SEASON!
E)
This
enters
an
infinite
loop
11