Font size
WorksheetsIT112 Midterm
Total questions: 100
Worksheet time: 2hrs 34mins
This is a code that has not yet been linked into a complete program.
Source Code
Assembly Code
Object Code
Machine Code
The object code is produced in what program development phase?
Preprocessing
Compilation
Linking
Loading
Executing
In what phase the c++'s executable program is produced?
Preprocessing
Compilation
Linking
Loading
Executing
By default, how are instructions executed by the CPU?
One instruction a a time
Several Instructions at a time
All instructions in one time
None of the above
Single line comments are denoted by what symbol?
//
\\
/*
*/
Which of the following are ignored by the C++ compiler and the computer? Check all that applies.
Comments
Blank lines
Spaces
Tab Spaces
Preprocessing directives
A preprocessing directive starts with what symbol?
//
#
(
{
The library defined in the preprocessor directive must be enclosed by what symbols?
{ }
[ ]
< >
( )
Blanks lines, spaces, and tab characters are called?
Keywords
White spaces
Symbols
Escape Sequences
A code that is reserved by C++ for a specific use.
Keyword
White space
Symbol
Escape Sequence
Which symbol starts a block of code?
<
(
{
[
Which symbol is used to determine that a code/keyword is a function?
<
(
{
[
The words enclosed in double quotation marks are known as the following EXCEPT what?
String
Character String
String Literal
Stream
The semicolon (;) is used to?
Start a block of code
Terminate a function
Start a statement
End a statement
Which of the following is the escape character operator?
<<
>>
::
\
Which of the following is the stream insertion operator?
<<
>>
::
\
Which of the following is the stream extraction operator?
<<
>>
::
\
A location in the computer's memory where a value can be stored for use by a program. Note: Answer must be in UPPERCASE letters.
(a)
Which of the following is the input stream object?
>>
<<
cin
cout
Which of the following is NOT a VALID identifier?
X1
_X1
x1
_1x
1x
Which of the following are VALID identifiers?
int
include
return
zero
All variables must be declared before they are used.
True
False
What is the only function all C++ programs must contain?
start()
system()
main()
program()
Which of the following is a correct comment?
*/ Comments */
** Comment **
/* Comment */
{ Comment }
Program
int main()
{
cout<<"Hi everybody";
return 0;
}
Which of the following is NOT a logical operator in C++ language?
&
&&
||
!
Which of the following is NOT a comparison operator in C++ language?
>
<=
=
==
Evaluate the following expressions to true or false
3!=4-1
true
False
Evaluate the following expressions to true or false
5 >= (1+6)-4
True
False
Evaluate the following expressions to true or false
5+1==6 || 8-1>4
True
False
If originally x=2,y=0, and z=1, what is the value of x, y, and z after executing the following code?
if (x>y)
y=x;
else
z=x;
x=2 y=2 z=1
x=0 y=2 z=0
x=2 y=1 z=1
x=2 y=0 z=1
Which of these operators increments an integer variable by one?
" * "
" - - "
" + + "
>
Which of these operators gets the remainder of dividing two numbers?
#
&
%
==
Fill in the blank to get 1 outputted from this code:
int main() {
int a = 2;
int b = 13;
cout<< b _ a <<endl;
}
(a)
True or False. This code will output 0
cout<< 23 % 2 <<endl;
True
False
True or False. This code will output 1
cout<< 55 % 2 <<endl;
True
False
Fill in the blank to get 0 outputted from this code:
int main() {
cout<< 12 ___ 12 <<endl;
}
-
+
==
%
Fill in the blank to get 0 outputted from this code:
int main() {
cout<< 12 ___ 3 <<endl;
}
-
+
==
%
Fill in the blank to get 0 outputted from this code:
int main() {
cout<< 0 ___ 3 <<endl;
}
-
/
==
+
Fill in the blank to get 1 outputted from this code:
int main() {
cout<< 9 % (a) <<endl;
}
Fill in the blank to get 2 outputted from this code:
int main() {
cout<< 5 % (a) <<endl;
}
Fill in the blank to get 3 outputted from this code:
int main() {
cout<< 15 % (a) <<endl;
}
Fill in the blank to get 3 outputted from this code:
int main() {
cout<< 19 ____ 4 <<endl;
}
%
==
+
&&
What does this unary operator mean? : ++
It is the increment operator, usage: x++ , output if x=10: 11
It is the decrement operator, usage x--, output if x=10: 9
It is the logical 'Not' operator, usage !(x), output if x=10: True
What does this unary operator mean? --
It is the decrement operator, usage: X--, output if x=10 : 9
It is the increment operator, usage: x++, output if x=10 : 11
It is the logical 'Not' operator, usage: !(X), output if x=10: True
How many loops are there in C++
2
3
4
1
What is currect syntax of for loop?
for(initialization;condition; increment/decrement)
for(increment/decrement; initialization; condition)
for(initialization, condition, increment/decrement
None of These
Can a for loop contain another for loop?
No
Yes
Compilation Error
Runtime Error
Each pass through a loop is called a/an
pass through
enumeration
iteration
culmination
Which looping process checks the test condition at the end of the loop?
for
while
do-while
no looping process checks the test condition at the end
In a group of nested loops, which loop is executed the most number of times?
the outermost loop
the innermost loop
all loops are executed the same number of times
cannot be determined without knowing the size of the loops
The statement i++; is equivalent to
i = i + i;
i = i + 1;
i = i - 1;
i --;
Which looping process is best used when the number of iterations is known?
for
while
do-while
all looping processes require that the iterations be known
What's wrong? for (int k = 2, k <=12, k++)
the increment should always be ++k
the variable must always be the letter i when using a for loop
there should be a semicolon at the end of the statement
the commas should be semicolons
If there is more than one statement in the block of a for loop, which of the following must be placed at the beginning and the ending of the loop block?
parentheses ( )
braces { }
brackets [ ]
arrows < >
What output is produced by the following segment of code:
for(int fun = 20; fun > 1; fun -=3)
cout << fun << " ";
20 17 14 11 8 5 2 -1
20 17 14 11 8 5 2
17 14 11 8 5 2 -1
20 17 14 11 8 5
Infinite Loop
What output is produced by the following segment of code:
for(int i = 1; i <= 10; i++)
cout << i << " ";
0 1 2 3 4 5 6 7 8 9 10
0 1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9
Infinite Loop
What output is produced by the following segment of code:
for(int i = 0; i < 10; i++)
cout << i << " ";
0 1 2 3 4 5 6 7 8 9 10
0 1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9
Infinite Loop
What output is produced by the following segment of code:
for(int i = 0; i <= 10; i++)
cout << i << " ";
0 1 2 3 4 5 6 7 8 9 10
0 1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9
Infinite Loop
What output is produced by the following segment of code:
int start = 5;
int end = 20;
for(; start <= end; start +=2)
cout << start << " ";
5 7 9 11 13 15 17 19 21
7 9 11 13 15 17 19 20
7 9 11 13 15 17 19 21
5 7 9 11 13 15 17 19
Infinite Loop
What output is produced by the following segment of code:
for (int x = 10; x > 0; x++)
cout << x << " ";
10 9 8 7 6 5 4 3 2 1
10 9 8 7 6 5 4 3 2 1 0
9 8 7 6 5 4 3 2 1
No Output
Infinite Loop
What output is produced by the following segment of code:
for (int dmc = 8; dmc >= 10; dmc-=4)
cout << * << " ";
* * *
* *
*
No Output
Infinite Loop
What output is produced by the following segment of code:
for (int dmc = 8; dmc >= 8; dmc-=4)
cout << dmc << " ";
8 4 0
8 4
8
No Output
Infinite Loop
What output is produced by the following segment of code:
for (int dmc = 8; dmc >= 0; dmc-=4)
cout << dmc << " ";
8 4 0
8 4
8
No Output
Infinite Loop
What output is produced by the following segment of code:
for (int x = 5; x > 0; x--);
cout << * << " ";
* * * * *
* * * * * *
*
No Output
Infinite Loop
The statements in the body of a while loop may never be executed while the statements in the body of a do-while loop will be executed
at least once
at least twice
never
as many times as the user wishes
A for statement contains three expressions: initialization, condition, and
reversal
update
null
validation
If you want a user to enter exactly 20 values, which loop would be the best to use?
while
switch
do-while
for
How many times will the above loop display "Hello world!"?
19
20
21
an infinite number of times
A file must be __________ before data can be written to or read from it.
opened
closed
named
buffered
To allow file access in a program, you must use __________ in the header file.
#include <file>
#include <fileaccess>
#include <fstream>
#include <cfile>
Assuming outFile is a file stream object and number is a variable, which statement writes the contents of number to the file associated with outFile?
write(outFile, number);
outFile >> number;
number >> outFile;
outFile << number;
What is the output of the above program?
0 1 2 3 4
0 1 2 3
0 1 2
0 1
What is the output of the above program?
0 1 2 3 4
0 1 2 3
0 1 2 4
0 1 2
These are operators that add and subtract one from their operands.
plus and minus
++ and --
binary and unary
conditional and relational
Which of the following is not a fundamental type is not present in C but present in C++?
int
void
bool
char
What is the size of a boolean variable in C++?
1 bit
2bit
1byte
2byte
Which of the following is an entry-controlled loop?
for
none
do-while
all of above
Which of the following is an exit-controlled loop?
for
while
do-while
all of above
What is the final value of x in the following code segment?
int x = 7;
x += 2*x;
63
21
81
This code segment will not compile.
What is the final value of y in the following code segment?
int y = 3 * 7 % 8 + 1 * 4;
9
24
25
6
This code segment will not compile.
What is the final value of x in the following code segment?
int x = 7/2;
3 1/2
3.5
3.0
This code segment will not compile.
What is the final value of w in the following code segment?
int w = int(3 / 2) + 5 % 10 - 3.5;
-2
3
-3
2
This code segment will not compile.
What is the final value of x in the following code segment?
(Assume the header file <cmath> has been included.)
double x = pow(2, 3) + 1 / 2;
9.5
8.5
8.0
9.0
This code segment will not compile.
What is the final value of x in the following code segment?
(Assume the header file <cmath> has been included.)
double x = 15 / sqrt(4.0) - 10 % 3;
6.5
6.0
0.0
-0.5
This code segment will not compile.
Which of these variables can only contain a single letter?
char symbol;
string word;
int num;
double num;
Which of these variables can contain decimal numbers?
int apples;
double apples;
char apples;
void apples;
How can we store a user input to the variable
int apples; ?
cin << int apples;
cin >> apples;
cin;
What kind of data type is this value?
9.45
float
integer
character
string
What data type is this value?
'R'
integer
float
character
string
For the following code, what is the name of the variable?
int game = 2;
int
integer
game
2
For the following code, what is the data type?
float boat = 3.4;
float
boat
decimal
3.4
What is the output for this code?
int x = 3;
int y = 6;
cout << x + y;
9
18
6
3
What is the output of this code?
int x = 4;
x = 5;
cout << x;
4
5
20
9
What is the output of this code?
int y = 4;
y = y / 2;
cout << y + 1;
3
2
9
8
