wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

CS10 Midterm Prep II

Total questions: 29

Worksheet time: 7hrs 46mins

Name
Class
Date
1.
What is a possible result when executing the following command in Linux? g++ test.cpp
a)
Logic errors within the file test.cpp are reported
b)
Syntax errors within the file test.cpp are reported
c)
The source code within test.cpp is translated into machine code and then executed (run)
d)
The source code within test.cpp is executed (run)
2.
The _____________ command is utilized to navigate to a different directory in the terminal.
a)
ls
b)
cd
c)
run
d)
g++
3.
Comments are utilized by the compiler to interpret source code.
a)
True
b)
False
c)
Depends on what's around it
d)
Depends on the language
4.
Which of the following assigns 7 into the variable z?
a)
7 = z
b)
s = 7
c)
z = 7
d)
z << 7
5.
Which code block creates the following output?
Dig
Dug
a)
cout << "Dig Dug" << endl;
b)
cout << "Dig" endl "Dug";
c)
cout << "Dig" << endl << "Dug";
d)
cout << "Dig\tDug";
6.
Which expression is true only when integer x is non-negative?
a)
x >= 0
b)
x != 0
c)
x > 0
d)
x >= -1
7.
Given this program: 

string str;
cout << "Enter a sentence:\n";
cin >> str;
cout << str;

A user inputs:
There is a tide in the affairs of men.

What is the output?
a)
men.
b)
men.
c)
There is a tide in the affairs of men.
d)
There
8.
What is the result of the expression: 7 % 0
a)
7
b)
0
c)
unknown
d)
runtime error
9.
Given the string s contains the value "camel", which expression results in 'c'?
a)
s.find(1)
b)
s.at(1)
c)
s.at(0)
d)
s.at('c')
10.
Given two integer variables sum and num, which statement will correctly calculate the floating-point average and assign the average into the double variable ave?
a)
ave = sum / num;
b)
ave = sum / static_cast<double>(num);
c)
ave = sum / static_cast<int>(num);
d)
static_cast<double>(ave) = sum / num;
11.
Given that both x and y are positive, and y is greater than x: what is the value of the expression: x % y
a)
x
b)
y
c)
0
d)
y * x
12.
What is the C++ operator that is the opposite of the equality operator (i.e. inequality)?
a)
!=
b)
!!
c)
!
d)
=!
13.
Which of the following expressions determines if the char variable myC is either 'q' or 'm'?
a)
myC == 'q' || 'm'
b)
myC == 'q' && myC == 'm'
c)
myC == 'q' && 'm'
d)
myC == 'q' || myC == 'm'
14.
Your 65 year old Grandpa is going to the movies; the ticket clerk runs the program, on the right, to decide which price to charge him.
if (age >= 60) {
cout << 10;
}

if (age >= 18) {  cout << 15;}else {  cout << 7;}


What is the output?
a)
10
b)
1015
c)
15
d)
10157
15.
Given that uppercase letters are before lowercase letters in the ASCII table, how many characters exist in the ASCII table from the start of uppercase letters to the end of lowercase letters, including both sets of letters?
a)
'z' - 'A' - 1
b)
'z' - 'A'
c)
'z' - 'A' + 1
d)
'Z' - 'a' + 1
16.
Which block of code identifies when the char variable mystery contains any numeric digit?
a)
if ( mystery >= '0'){  if (mystery <= '9')  {  cout << "I'm a number!";  }}
b)
if ( mystery > '0'){  if (mystery < '9')  {  cout << "I'm a number!";  }}
c)
if ( mystery <= '0'){  if (mystery >= '9')  {  cout << "I'm a number!";  }}
d)
if ( mystery >= '0'){  cout << "I’m a number!";}else if (mystery <= '9'){  cout << "I'm a number!";}
17.
Is there anything wrong with the following code fragment?
for (int i = 0; i < 7; i + 1)
a)
compiler error
b)
logic/runtime error
c)
no errors
d)
This is not C++
18.
What is the value of the integer pos, after the following two statements?
string myS = "piecemeal";
int pos = myS.find('e');
a)
7
b)
string::npos
c)
0
d)
2
19.
Which variable datatype is best suited to store the result of the following expression?
5 + 7 * 4 - 10 * 3 / 2.0
a)
int
b)
char
c)
bool
d)
double
20.
The string s stores the value "mit", which statement updates s to contain the value "bit"?
a)
s.at(1) = 'b';
b)
s.at(0) = 'b';
c)
s.at(0) == 'b';
d)
cout << 'b' << s.at(1) << s.at(2);
21.
string greeting;
getline(cin, greeting);

User Input:
Have a great day!"
What is the value of greeting?
a)
a
b)
Have
c)
Have a great day!
d)
Have a great day!"
22.
_______________ is a named location in memory used to store data.
a)
a variable
b)
a statement
c)
an expression
d)
a function
23.
int x = 8;
while (x > 1){  x = x % 3;}

How many times will the loop iterate?
a)
0
b)
1
c)
4
d)
infinite
24.
What is the value of the C++ expression:
2345 / 10

a)
234
b)
2345
c)
10
d)
23.45
25.
Given string s is assigned "what's", what is stored in s after the statement: s = s + "up?";
a)
what'sup?
b)
what's
c)
what's up
d)
up?
26.
What is output by the following block of code?
for (int i = 2; i < 14; i = i + 4) {  cout << i << ' ';}
a)
2 6 10
b)
2 6 10 14
c)
2 10 14
d)
14 10 2 6
27.
How many times will the following code iterate?
while(1) {...}
a)
1
b)
3
c)
5
d)
none of the above
28.
When would you use string::npos?
a)
When finding a sub string
b)
When comparing integers
c)
When dealing with imaginary numbers
d)
When writing for loops
29.
Which of the following produces a different result?
a)
int x = 5;
for (int i = 0; i < x; i++) {cout << i << endl; }
b)
int z = 5;
while (int x = 0; x < z; x++) { cout << i << endl;}
c)
cout << 0 << endl;
cout << 1 << endl;
cout << 2 << endl;
cout << 3 << endl;
cout << 4 << endl;
d)
cout << "0\n1\n2\n\3\n\4\n";