Final Exam Review Flashcards

(49 cards)

1
Q

A statement that starts with a # symbol is called a:
a. comment
b. function
c. keyword
d. preprocessor directive

A

d. preprocessor directive

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

These are data items that cannot have their value changed while the program is running:
a. variables
b. Constants and Literals
c. Floating point numbers
d. integers

A

b. Constants and Literals

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Mark all of the following which are valid identifiers (Each mark is worth one point) :
a. TheLastPeriod.
b. 12Itemstoaddup
c. _start_of_the_block
d. SpecialCharacter!
e. TheSummaryTotal
f. reallyreallyreallylongvariable8675309

A

c, e, f

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

For every opening brace “{“ there must be a:
a. String Literal
b. Variable and semicolon
c. Function
d. Closing Brace “}”

A

d. Closing Brace “}”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

In C++, two slashes “//” indicate :

a. Beginning of a statement
b. Preprocessor Directive
c. the end of a code block
d. The start of a Comment

A

d. The start of a Comment

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the difference between a while loop and a do-while loop?
a. The while loop tests the entry condition after being executed at least once.
b. The wile loop is executed at least once. The do-while loop may not be.
c. There is no difference
d. The do-while loop is executed at least once, the while loop may or may not be executed once.

A

d. The do-while loop is executed at least once, the while loop may or may not be executed once.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What symbol is the modulus operator?
a. %
b. /
c. *
d. &

A

a. %

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the output of the following statement?

cout &laquo_space;4 * (15 / (1 + 3) «endl;
a. 15
b. 72
c. 63
d. 12

A

12

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the mark or character at the end of every c++ statement?
a. # Pound sign or hashtag
b. . Period
c. , Comma
d. ; Semicolon

A

d. ; Semicolon

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Given the definitions below, which statement(s) reads in two integer variables.

int var1,var2;
a. read»var1»var2;
b. cin»var1»var2;
c. read«var1«var2
d. cin«var1«var2;

A

b. cin»var1»var2;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Match the c++ data type to an example of the data that it can hold.
int, float, bool, char
true, a, 1024, 3.14159

A

int-1024
float-3.14159
bool-true
char-a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Given the following segment of code, what line of code contains a syntax error? ?
1 // This program displays my gross wages.
2 // I worked 40 hours and I make $20.00 per hour.
3 #include <iostream>
4 using namespace std;
5
6 int main()
7 {
8 int hours;
9 double payRate, grossPay
10
11 hours = 40;
12 payRate = 20.0;
13 grossPay = hours * payRate;
14 cout << "My gross pay is $" << grossPay << endl;
15 return 0;
16 }</iostream>

a. Line 5, blank line
b. Line 9
c. Line 15
d. Line 14

A

b. Line 9

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Which of the following correctly consolidates the following declaration statements into one statement?

int x=7;
int y=16;
int z=28;

a. int x=7, y=16, z=28;
b. int x=7 y=16 z=28;
c. int x=7; y=16; z=28;
d. int x,y,z = {7,16,28);

A

a. int x=7, y=16, z=28;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What will the following code display to standard output?

cout «“Four\n” &laquo_space;“score\n”
cout«“and”«” \nseven”;
cout«“\nyears “«” ago”«endl;

a. Four score
andseven
years ago
b. Four score and seven years ago
c. Four
score
and
seven
years ago
d. fourscoreandsevenyearsago

A

c. Four
score
and
seven
years ago

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What will be the value of x after the following statements are executed?

int x;
x = 18.0/4;

a. 4.5
b. 5
c. 4
d. 0

A

c. 4

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

The _____ operator always follows the cin object, and the _____ operator always follows the cout object.

a. «,&raquo_space;
b. * , %
c.&raquo_space; , &laquo_space;
d. binary, unary

A

c.&raquo_space; , «

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

In any program that uses the cin object, you must include the ________.
a. standard C library or #include <cstdlib.h>
b. compiler
c. linker
d. The iostream header file or #include <iostream></iostream></cstdlib.h>

A

d. The iostream header file or #include <iostream></iostream>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

You can use these to override the rules of operator precedence in a mathematical expression.
a. [Square Brackets]
b. {curly brackets}
c. “Double Quotes”
d. (parenthesis)

A

d. (parenthesis)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

In the following C++ statement, what will be executed first according to the order of precedence?
result = 6 - 3 * 2 + 7 - 10 / 2;
a. 3*2
b. 7-10
c. 2+7
d. 6-3

A

a. 3*2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

In the iomanip library, this manipulator is used to establish the width for the value immediately following it.

a. fwidth() // field width
b. setf() // Set field
c. setw() // Set Width
d. setsize() // Set size

A

c. setw() // Set Width

21
Q

What is true about the following statement?

cout &laquo_space;setw(4) &laquo_space;num4 &laquo_space;” “;

a. It allows 4 spaces to print the value in num4
b. It prints out the number 4
c. It outptus setw(4) before the value in num4.
d. It outputs up to four ascii characters in num4

A

a. It allows 4 spaces to print the value in num4

22
Q

Which of the following statements are equivalent to the following?

x = x * 2;

a. X = x * x;
b. X * =2 ;
c. x*x;
d. X * 2 ;

23
Q

What will be the output of the following code segment after the user enters 0 at the keyboard?

int x = -1;
cout &laquo_space;“Enter a 0 or a 1 from the keyboard: “;
cin&raquo_space; x;
if (x)
cout &laquo_space;“true” &laquo_space;endl;
else
cout &laquo_space;“false” &laquo_space;endl;

a. false
b. x
c. true
d. nothing will be displayed

24
Q

What is the output of the following code segment?

 int x = 5;
 if (x = 2)
       cout << "This is true!" << endl;
 else
       cout << "This is false!" << endl;
       cout << "That is all folks!" << endl;

a. This is false!
That is all folks!

b. This is true!
That is all folks!

c. That is all folks!

d. This is true!
This is false!

A

b. This is true!
That is all folks!

25
The operator that represents a logical AND is: a. && b. ** c. || d. ++
a. &&
26
This operator is used to ask the question if two items are equal: a. == b. !! c. = d. ><
a. ==
27
In C and C++ the = (equal sign) represents what? a. negation b. Assignment c. Equality d. subtraction
b. Assignment
28
If you intend to perform a group of statements within an if statement, you must place these around the block. a. Curly braces {} b. Parens () c. Angle brackets <> d. Square brackets []
a. Curly braces {}
29
This operator is known as the logical OR operator is: a. ^^ b. || c. ++ d. &&
b. ||
30
The operator that negates a logical statement is: a. ! b. -- c. <> d. ><
a. !
31
These are called increment and decrement operators that add and subtract one from their operands: a. + and - b. -- and ++ c. - and + d. ++ and - -
d. ++ and --
32
What is the output of the following code segment? n = 1; while (n <= 5) cout << n << ' '; n++; a. 1 2 3 4 b. 2 3 4 5 6 c. 1 1 1 1 .. goes on forever, infinite loop c. 1 2 3 4 5
c. 1 1 1 1 .. goes on forever, infinite loop
33
The while loop has two important parts: an expression that is tested for a true or false value, and: a. a statement or block that is repeated as long as the expression is true b. a statement or block is repeated only once if the expression is false c. one line of code is repeated once if the statement is true d. The statement will be executed at least once even if the expression is false
a. a statement or block that is repeated as long as the expression is true
34
The statements in the body of a while loop may never be executed, whereas the statements in the body of a do-while loop will be executed: a. at least twice b. never c. It cannot be determined d. at least once
d. at least once
35
A for statement contains three expressions: initialization, test, and a. reversal b. validation c. null d. increment or update
d. increment or update
36
A trick question for you...Let's see how many were paying attention. How many time will the words Hello World be printed out? for (int n=0; n <= 5; ); cout << “Hello World” << endl; a. 6 times b. 5 times c. infinite loop d. just once
c. infinite loop
37
The do-while loop is considered ? a. pre-test b. limited-test c. in-test d. post-test
d. post-test
38
A prototype for the following function would look like which of the following: int Square_It (const int x) { int y; y = x*x; return y; } a. int Square_It (const int x); b. void Square_It(const int x); c. int Square_It(int x); d. void Square_It(int x);
a. int Square_It (const int x);
39
What is the value of the following expression (the part inside the parens)? if(true && false) { // some code goes here; } a. The if statement will always be true b. It depends upon the compiler c. The if statement will always be false d. The code will cause a syntax error
c. The if statement will always be false
40
What is the value of number after the following statements execute? int number = 10; number += 5; number -= 2; number *= 3; a. 3 b. 30 c. 39 d. 2
c. 39
41
Which line in the following program will cause a compiler error? 1 #include 2 using namespace std; 3 4 int main() 5 { 6 const int MY_VAL; 7 MY_VAL = 77; 8 cout << MY_VAL << endl; 9 return 0; 10 } a. 8 b. 9 c. 6 d. 7
c. 6
42
When avariable is assigned a number that is too large for it to hold , what happens? a. reverses polarity b. nothing c. overflow d. exceeds expectations
c. overflow
43
The following code segment will generate a syntax errror (true/false)? if (x=1) cout <<"Hello World" <
b. False
44
The reverse of < (less than) is >= (greater than or equal to). a. True b. False
A. True
45
The value of a variable cannot be added to itself. a. True b. False
b. False
46
With the setprecision() command in the iomanip library it puts a $ in front of the number. a. True b. False
b. False
47
The purpose of the break statement in a loop is to stop the loop completely. a. True b. False
a. True
48
The continue statement and the break statement used in loops perform the same function. a. True b. False
b. False
49
Match the logical operator with its meaning. ==, <, >, <=, >=, greater than, greater than or equal to, equal, less than, less than or equal to
== equal < less than > greater than <= less than or equal to >= greater than or equal to