Name_______________________
Login___________________SID________
CS 010: Introduction to
Computer Science I
Quiz 6: 10 minutes
- How
many asterisks will be output by the following code?
for
(int i = m; i < n; i++)
{
cout << “*“;
}
a.
0
b.
1
c.
n - 1
d.
n
- m
e.
n + m
f.
n - m + 1
- How
many asterisks will be output by the following code?
for (int i = 1; i <= m; i++)
{
for (int j = 1; j <= n; j++)
{
cout << “*“;
}
cout << endl;
}
a.
0
b.
1
c.
m + n
d.
m
* n
e.
(m - 1) + (n - 1)
f.
(m + 1) * (n + 1)
- How
many rows of asterisks will be output by the code in question 2?
a.
0
b.
1
c.
m
d.
n
e.
m - 1
f.
m * n
- What
happens when you put a semicolon right after a while loop’s
conditional expression as in the following example?
while
(n <= 10);
{
cout << n << “ “;
n++;
}
a.
If
n is less than 10, this will be an infinite loop.
b.
This is a syntax error.
c.
This will output the integers from n to 10 if n is less or
equal to 10.
d.
Nothing happens. The while loop is skipped.
- What
happens when you put a semicolon right after a do while
loop’s conditional expression as in the following example?
do
{
cout << n << “ “;
n++;
}
while (n <= 10);
a.
If n is less than 10, this will be an infinite loop.
b.
This is a syntax error.
c.
This
will output the integers from n to 10 if n is less or equal to 10.
d.
Nothing happens. The while loop is skipped.
- What
is output by the following code?
int
n = 10;
do
{
cout << n << “ “;
n++;
}
while (n < 5);
cout
<< n << endl;
- 10
- 10 11
- 11
- 10
10
- 11
12
- There
is a syntax error.
- Is
it possible to say there is definitely a syntax error in the
following code fragment without knowing anything else about the C++
program it came from other than that v is a vector?
v[0]
= 10;
v[1]
= s;
v[2]
= “s“;
- Yes, there is definitely a
syntax error.
- No,
we need to know more about the program this code came from to say it is
definitely a syntax error.
- How
many elements does the vector v have after the following declaration?
vector<int>
v(n);
- 0
- 1
- n
- n
- 1
- n
+ 1
- none
of the above
- What
is the index number of the last element in vector v from question 8?
- 0
- 1
- n
- n - 1
- n
+ 1
- none
of the above
- Which statement(s) outputs the entire contents of
vector v from question 8.
- for (int i = 1; i <= n; i++) cout
<< v[i];
- for (int i = 1; i <= v.size(); i++)
cout << v[i];
- cout << v;
- cout << v[n];
- for
(int i = 0; i < v.size(); i++) cout << v[i];
- A, C, and E all output the entire
contents of vector v.