Name_______________________
Login___________________SID________
CS 010: Introduction to
Computer Science I
if ( … )
stmt;
else if ( … )
stmt;
else if ( … )
stmt;
a.
0
b. 1
c. 2
d. 3
e. can not be determined
x is not equal to the strings “a” and “b”, both lower and uppercase
a. (x != “a” || x != “A” || x != “b” || x != “B”)
b. ((x != “a” || “A”) && (x != “b” || “B”))
c. !(x == “a” || x == “A”) || !(x == “b” || x == “B”)
d.
(x != “a” && x != “A” && x != “b” && x != “B”)
e. None of the above
if (x==1 && y==2) if (x==1)
cout << "HELLO\n"; {
else if (y == 2)
cout << "GOODBYE\n"; cout << "HELLO\n";
else
cout << "GOODBYE\n";
}
a. for (int i = 0; i < second; i++) cout << first;
b. for (int i = first; i <= second; i++) cout << first;
c. for (int i = 0; i <= second; i++) cout << i;
d.
for (int i = first; i <= second; i++) cout << i;
e. for (int i = second; i > first; i--) cout << second;
a.
TRUE
b. FALSE
double a = 1;
double b = 1;
int i = 0;
do {
b = b / 2;
a = a + b;
i = i + 2;
}while (a < 1.8);
cout << i;
a. 2
b. 3
c. 4
d.
6
e. None of the above
7. How many “*” will be output when the following code fragment is executed?
for (int i = 1; i <=n; i++)
for (int j = 0; j < m; j++)
cout << “*”;
a. m
b. n + m
c.
n * m
d. (n – 1) * (m – 1)
e. None of the above
a. for (int i = 0; i < v.size() - 1; i++) v[i] = rand()%100;
b.
for (int i = 0; i < v.size(); i++) v[i] = rand()%100;
c. for (int i = 1; i < v.size(); i++) v[i] = rand()%100;
d. for (int i = 1; i < v.size() + 1; i++) v[i] = rand()%100;
e. for (int i = 0; i <= v.size(); i++) v[i] = rand()%100;
a. A function cannot return a vector.
b. Vector parameters should never be passed by reference.
c.
All elements of a vector must be of the same type.
d. Vectors cannot contain strings.
a. TRUE
b. FALSE