Name_______________________
Login___________________SID________
CS 010: Introduction to
Computer Science I
Quiz 4: 10 minutes
- What
is output by the following code fragment?
int x = 0;
while (x < 5)
{
x++;
}
cout << x;
a.
0
b.
12345
c.
01234
d.
4
e.
5
f.
none of the above
- What
is output by the following code fragment?
int x = 0;
while (x < 5)
{
x += 2;
}
cout << x;
a.
246
b.
024
c.
4
d.
5
e.
6
f.
none of the above
- What
is output by the following code fragment?
int x = 0;
while (x < 5)
{
x += 3;
cout << x;
}
a.
0
b.
03
c.
36
d.
3
e.
6
f.
none of the above
- The
following expression has what type of value if c1 is a
Circle that has been properly declared and initialized? In other words,
what type of variable can this expression’s value be
assigned to?
c1.get_center().get_x()
a.
Circle
b.
Point
c.
double
d.
Circle and/or Point
e.
Point and/or double
f.
Circle and/or Point and/or double
- What
is the value of count after the following code fragment executes?
int count = 0;
Point p1(0,0);
while (p1.get_x() < 5)
{
p1.move(2,1);
count++;
}
- 0
- 2
- 3
- 4
- 5
- none
of the above
- What
are the possible values of the following expression?
rand() % 5 + 1
- 0
to 4 (integers only)
- 1 to 5 (integers only)
- 1
to 6 (any real or floating-point number)
- true
or false
- any
integer less than 6
- none
of the above
- It
is a syntax error to have a return statement in a void function (a
function that has the return type of void).
- TRUE
- FALSE
- Given
this function definition
int do_something(int x)
{
if (x >= 100)
{
return x;
}
else if (x >= 50)
{
return
x + 50;
}
else
{
return
0;
}
}
What is the
value of the following expression?
do_something(50)
- 0
- 50
- 100
- 150
- This
function call should not be used as an expression.
- None
of the above
- Given
this function definition
void do_something_else(int x)
{
cout << x + 50;
}
What is the
value of the following expression?
do_something_else(50)
- 50
- 100
- This function call should
not be used as an expression.
- None
of the above
- All return statements must return a value.
- TRUE
- FALSE