Ma parda si computer campter

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Which of the following operators has the highest order of precedence?

!

Which of the following operators has the highest precedence?

!

Which of the following is the "not equal to" relational operator?

!=

Which of the following expressions evaluates to true?

"Air" < "An"

During which stage does the central processing unit retrieve from main memory the next instruction in the sequence of program instructions? A) fetch B) decode C) execute D) portability stage

A

Suppose that x = 25.67, y = 356.876, and z = 7623.9674. What is the output of the following statements? cout << fixed << showpoint; cout << setprecision(2); cout << x << ' ' << y << ' ' << z << endl;

25.67 356.88 7623.97

Which of the following is a valid case statement in a switch?

***a. case 1: b. case x<4: c. case 'ab': d. case 1.5:

Which loop structure always executes at least once?

***a. do-while b. for c. while d. sentinel

Which of the following is not a valid identifier?

***a. return b. myInt c. myInteger d. total3

A ____ sign in front of a member name on a UML diagram indicates that this member is a publicmember.

+

increment operator

++; increases the value of a variable by 1

int strange(int x, int y){if (x > y)return x + y;elsereturn x - y; }what is the output of the following statement?cout << strange(4, 5) << endl;

-1

.

.

In C++, the ____ is called the member access operator.

.

Identify two ways to input comments into a program.

// single_line comments /* multi_line comments */

Unless you explicitly initialize global variables, they are auto initialized as

0

When using a return statement, the return of any value other than ____ indicates that something went wrong during program execution.

0

int list[5] = {0, 5, 10, 15, 20};int j;for (j = 0; j < 5; j++) cout << list[j] << " ";cout << endl;

0 5 10 15 20

int matrix[3][2];int j, k;for (j = 0; j < 3; j++) for (k = 0; k < 2; k++) matrix[j][k] = j + k;

01 12 23

1. How many operands does each of the following types of operators require? _______ Unary _______ Binary _______ Ternary

1 2 3

There are a number of syntax errors in the following program. Locate as many as you can. */ What's wrong with this program? /* #include iostream using namespace std; int main(); } int a, b, c \\ Three integers a = 3 b = 4 c = a + b Cout < "The value of c is %d" < C; return 0; {

1) The multi-line comment: correct config is /* and */. 2) <iostream> missing less than/greater than symbols. 3) No comma after int main(). 4) The braces at the beginning and end of the function are reversed. 5) int a, b, c; is missing the semi-colon. 6) The single-line // are the wrong direction. 7) The three variable definitions require semi-colons or at least commas after a = 3, b = 4, and then a semi-colon after c = a+ b; 8) cout needs to be lower case. 9) need two less than and two greater than symbols.

How many operands does each of the following types of operators require? _____ Unary _____ Binary _____ Ternary

1, 2, 3

assignment operator

=; assigns whatever is on the right side to the variable on the left side

Which of the following is a relational operator?

==

stream extraction operator

>>; takes information from a stream and puts it into a variable

19. The negation operator is A) Unary B) Binary C) Ternary D) None of the above

A

21. What is the output of the following code? char lastInitial = 'A'; switch (lastInitial) {case 'A': cout << "section 1" <<endl; break; case 'B': cout << "section 2" <<endl; break; case 'C': cout << "section 3" <<endl; break; case 'D': cout << "section 4" <<endl; break; default: cout << "section 5" <<endl; } a. section 1 c. section 3 b. section 2 d. section 5

A

21. When do preprocessor directives execute? A) Before the compiler compiles your program B) After the compiler compiles your program C) At the same time as the compiler compiles your program D) None of the above

A

A for statement contains three expressions: initialization, test, and A) update B) reversal C) null D) validation E) None of these

A

A function ________ contains the statements that make up the function. A) definition B) prototype C) call D) expression E) parameter list

A

A step-by-step problem-solving process in which a solution is arrived at in a finite amount of time is called a(n) ____.

A

A variable declaration announces the name of a variable that will be used in a program, as well as: A) The type of data it will be used to hold B) The operators that will be used on it C) The number of times it will be used in the program D) The area of the code in which it will be used E) None of the above

A

After execution of the following code, what will be the value of input_value if the value 0 is entered at the keyboard at run time? cin >> input_value; if (input_value > 5) input_value = input_value + 5; else if (input_value > 2) input_value = input_value + 10; else input_value = input_value + 15; A) 15 B) 10 C) 25 D) 0 E) 5

A

Assume you have three int variables: x = 2, y = 6, and z. Choose the value of z in the following expression:z = (y / x > 0) ? x : y;. a. 2 c. 4 b. 3 d. 6

A

Consider the following C++ program. #include <iostream> using namespace std; int main() { cout << "Hello World " return 0; } In the cout statement, the missing semicolon in the code above will be caught by the ____. a. compiler c. assembler b. editor d. control unit

A

Consider the following program segment. ifstream inFile; //Line 1 int x, y; //Line 2 ... //Line 3 inFile >> x >> y; //Line 4 Which of the following statements at Line 3 can be used to open the file progdata.dat and input data from this file into x and y at Line 4? a. inFile.open("progdata.dat"); b. inFile(open,"progdata.dat"); c. open.inFile("progdata.dat"); d. open(inFile,"progdata.dat");

A

The statement: return 8, 10; returns the value

10

What is the output of the following C++ code? num = 10;while (num > 10)num = num - 2;cout << num << endl;

10

What is the output of the following C++ code? int j;for (j = 10; j <= 10; j++)cout << j << " ";cout << j << endl;

10 11

int alpha[5] = {2, 4, 6, 8, 10};int j;for (j = 4; j >= 0; j--)cout << alpha[j] << " "; cout << endl;

10 8 6 4 2

Which of the following expressions correctly determines that x is greater than 10 and less than 20?

10 < x & & x < 20

Consider the statement int list[10][8];. Which of the following about list is true?

10 rows 8 columns

Suppose sum and num are int variables, and the input is 18 25 61 6 -1. What is the output of the following code?

110

What is the output of the following statements? cout << setfill('*'); cout << "12345678901234567890" << endl cout << setw(5) << "18" << setw(7) << "Happy" << setw(8) << "Sleepy" << endl;

12345678901234567890 ***18**Happy**Sleepy

What is the output of the following statements? cout << setfill('*') ;cout << "12345678901234567890" << endl cout << setw(5) << "18" << setw(7) << "Happy"<< setw(8) << "Sleepy" << endl;

12345678901234567890 ***18**Happy**Sleepy

What is the output of the following statements? cout << "123456789012345678901234567890" << endlcout << setfill('#') << setw(10) << "Mickey"<< setfill(' ') << setw(10) << "Donald" << setfill('*') << setw(10) << "Goofy" << endl;

123456789012345678901234567890 ####Mickey Donald*****Goofy

Suppose j, sum, and num are int variables, and the input is 26 34 61 4 -1. What is the output of the code?

125

The expression static_cast<int>(6.9) + static_cast<int>(7.9) evaluates to ____.

13

The output of the statement: cout << pow(3.0, 2.0) + 5 << endl; is

14.0

Suppose that x = 1565.683, y = 85.78, and z = 123.982. What is the output of the following statements? cout << fixed << showpoint; cout << setprecision(3) << x << ' '; cout << setprecision(4) << y << ' ' << setprecision(2) << z << endl;

1565.683 85.7800 123.98

Suppose that x = 1565.683, y = 85.78, and z = 123.982. What is the output of the following statements? cout << fixed << showpoint; cout << setprecision(3) << x << ' '; cout << setprecision(4) << y << ' ' << setprecision(2) << z << endl;

1565.683 85.7800 123.98

The length of the string "computer science" is ____.

16

Assume you have three int variables: x = 2, y = 6, and z. Choose the value of z in the following expression: z = (y / x > 0) ? x : y;

2

Suppose that count is an int variable and count = 1. After the statement count++;executes, the value of count is ____.

2

What is the output of the following C++ code? int x = 55;int y = 5;switch (x % 7){case 0:case 1:y++;case 2:case 3:y = y + 2;case 4:break;case 5:case 6:y = y - 3;} cout << y << endl;

2

Without this statement appearing in a switch construct, the program "falls through" all of the statements below the one with the matching case expression. A) break B) exit C) switch D) scope E) None of these

A

____ programs perform a specific task. a. Application c. Operating b. System d. Service

A

A class-type attribute is best modeled by:

A composition association.

To handle situations where a loop must reinitialize a variable at the beginning of each iteration, such reinitialization could be performed by

A declaration inside the loop body.

An example of a secondary storage device is:

A hard disk.

infinite

A loop that continues to execute endlessly is called a(n) ____ loop.

11. Every C++ program must have a A) cout statement B) function main C) #include statement D) All of the above

B

13. The following data 72 'A' "Hello World" 2.8712 are all examples of A) Variables B) Literals or constants C) Strings D) None of the above

B

A ________ variable is declared outside all functions. A) local B) global C) floating-point D) counter E) None of these

B

A file must be ________ before data can be written to or read from it. A) closed B) opened C) buffered D) initialized E) None of these

B

A function ________ eliminates the need to place a function definition before all calls to the function. A) header B) prototype C) argument D) parameter E) None of these

B

A program that loads an executable program into main memory is called a(n) ____.

B

A sequence of eight bits is called a ____. a. binary digit c. character b. byte d. double

B

A set of well-defined steps for performing a task or solving a problem is known as a(n): A) Hierarchy B) Algorithm C) Central Processing Unit D) Encoded instruction E) None of the above

B

A variable or expression listed in a call to a function is called the ____. a. formal parameter c. data type b. actual parameter d. type of the function

B

A variable whose value can be either true or false is of this data type. A) binary B) bool C) T/F D) float E) None of the above

B

A(n) ________ is a diagram that shows the logical flow of a program. A) UML diagram B) flowchart C) hierarchy chart D) program schematic E) None of these

B

A(n) ________ is the most fundamental set of programs on a computer. A) compiler B) operating system C) application D) utility program E) None of these

B

Assume that a program has the following string object definition: string name; Which of the following statements correctly assigns a string literal to the string object? A) name = Jane; B) name = "Jane"; C) name = 'Jane'; D) name = (Jane);

B

Besides decimal, two other number systems you might encounter in C++ programs are: A) Octal and Fractal B) Hexadecimal and Octal C) Unary and Quaternary D) Base 7 and Base 9 E) None of the above

B

During which stage does the central processing unit analyze the instruction and encode it in the form of a number, and then generate an electronic signal? A) fetch B) decode C) execute D) portability stage

B

EXIT_FAILURE and ________ are named constants that may be used to indicate success or failure when the exit() function is called. A) EXIT_TERMINATE B) EXIT_SUCCESS C) EXIT_OK D) RETURN_OK E) None of these

B

Every complete C++ program must have a ________. A) comment B) function named main C) preprocessor directive D) symbolic constant E) cout statement

B

For a program to use the assert function, it must include which of the following? a. #include <assert> c. #include <assertc> b. #include <cassert> d. #include NDEBUG

B

Given that, x = 2, y = 1, and z = 0, what will the following cout statement display? cout << "answer = " << (x || !y && z) << endl; A) answer = 0 B) answer = 1 C) answer = 2 D) None of these

B

Given the following function definition: void calc (int a, int& b) { int c; c = a + 2; a = a * 3; b = c + a; } What is the output of the following code fragment that invokes calc? int x = 1; int y = 2; int z = 3; calc(x, y); cout << x << " " << y << " " << z << endl; A) 1 2 3 B) 1 6 3 C) 3 6 3 D) 1 14 9 E) None of these

B

True/False: A CPU really only understands instructions that are written in machine language. Select one: True False

True

The ____ monitors the overall activity of the computer and provides services. a. central processing unit c. arithmetic logic unit b. operating system d. control unit

B

The ________ causes a program to wait until information is typed at the keyboard and the Enter key is pressed. A) Output stream B) cin object C) cout object D) Preprocessor E) None of the above

B

The appearance of = in place of == resembles a(n) ____. a. syntax error c. compilation error b. silent killer d. input failure

B

The conditional operator ?: takes ____ arguments. a. two c. four b. three d. five

B

The declaration int a, b, c; is equivalent to which of the following? a. inta , b, c; c. int abc; b. int a,b,c; d. int a b c;

B

The devices that feed data and programs into computers are called ____ devices. a. entry c. output b. input d. secondary

B

The do-while loop is considered a(n) ________ loop. A) pre-test B) post-test C) infinite D) limited E) None of these

B

The function, pow(x, 5.0), requires this header file. A) cstdlib B) cmath C) cstring D) iostream E) iomanip

B

The memory allocated for a float value is ____ bytes. a. two c. eight b. four d. sixteen

B

The programmer usually enters source code into a computer using: A) Pseudocode B) A text editor C) A hierarchy chart D) A compiler E) None of the above

B

The term GB refers to ____. a. giant byte c. group byte b. gigabyte d. great byte

B

The while loop contains an expression that is tested for a true or false value, and a statement or block that is repeated as long as the expression: A) is false B) is true C) does not evaluate to true or false D) evaluates to true or false E) None of these

B

These are operators that add and subtract one from their operands. A) plus and minus B) ++ and -- C) binary and unary D) conditional and relational E) None of these

B

These operators connect two or more relational expressions into one, or reverse the logic of an expression. A) relational B) logical C) irrational D) negation E) None of these

B

These types of arguments are passed to parameters automatically if no argument is provided in the function call. A) Local B) Default C) Global D) Relational E) None of these

B

This is a complete instruction that causes the computer to perform some action. A) Line B) Statement C) Variable D) Key Word E) None of the above

B

This is a dummy function that is called instead of the actual function it represents. A) main function B) stub C) driver D) overloaded function

B

This is a pre-test loop that is ideal in situations where you do not want the loop to iterate if the condition is false from the beginning. A) do-while B) while C) for D) infinite E) None of these

B

This is a variable that is regularly incremented or decremented each time a loop iterates. A) constant B) counter C) control statement D) null terminator E) None of these

B

This is used in a program to mark the beginning or ending of a statement, or separate items in a list. A) Separators B) Punctuation C) Operators D) Key Words E) None of the above

B

This is used to mark the end of a complete C++ programming statement. A) Pound Sign B) Semicolon C) Data type D) Void E) None of the above

B

This means to increase a value by one. A) decrement B) increment C) modulus D) parse E) None of these

B

This operator performs a logical NOT operation. A) -- B) ! C) <> D) >< E) None of these

B

This statement causes a loop to terminate early. A) stop B) break C) null D) terminate E) None of these

B

This step will uncover any syntax errors in your program. A) Editing B) Compiling C) Linking D) Executing E) None of these

B

To develop a program, you can use an informal ____. mixture of C++ and ordinary language, called a. assert code b. pseudocode c. cppcode d. source code

B

To read data from a file, you define an object of this data type. A) inputFile B) ifstream C) fstream D) ofstream

B

What does the term hardware refer to? A) The relative difficulty of programming B) The physical components that a computer is made of C) The way a computer's storage space is organized D) The logical flow of instructions E) None of the above.

B

True/False: The CPU is the most important component in a computer because without it, the computer could not run software. Select one: True False

True

When reading data into a char variable, after skipping any leading whitespace characters, the extraction operator >> finds and stores only the next character; reading stops after a single character. (T/F)

True

What is the output of the following C++ code? int x = 35; int y = 45; int z; if (x > y) z = x + y; else z = y - x; cout << x << " " << y << " " << z << endl; a. 354580 c. 3545-10 b. 354510 d. 35450

B

What is the output of the following code segment? n = 1; for ( ; n <= 5; ) cout << n << ' '; n++; A) 1 2 3 4 5 B) 1 1 1 ... and on forever C) 2 3 4 5 6 D) 1 2 3 4 E) 2 3 4 5

B

What is the output of the following code segment? n = 1; while (n <= 5) cout << n << ' '; n++; A) 1 2 3 4 5 B) 1 1 1... and on forever C) 2 3 4 5 6 D) 1 2 3 4 E) 2 3 4 5

B

What is the output of the following program? #include <iostream> using namespace std; void showDub(int); int main() { int x = 2; showDub(x); cout << x << endl; return 0; } void showDub(int num) { cout << (num * 2) << endl; } A) 2 2 B) 4 2 C) 2 4 D) 4 4

B

What is the output of the following statement? cout << 4 * (15 / (1 + 3)) << endl; A) 15 B) 12 C) 63 D) 72 E) None of these

B

What is the output of the following statements? cout << setfill('*'); cout << "12345678901234567890" << endl cout << setw(5) << "18" << setw(7) << "Happy" << setw(8) << "Sleepy" << endl; a. 12345678901234567890 ***18 Happy Sleepy b. 12345678901234567890 ***18**Happy**Sleepy c. 12345678901234567890 ***18**Happy Sleepy d. 12345678901234567890 ***18**Happy Sleepy**

B

What is the value of average after the following code executes? double average; average = 1.0 + 2.0 + 3.0 / 3.0; A) 2.0 B) 4.0 C) 1.5 D) 6.0

B

What is the value of the following expression? true && false A) true B) false C) -1 D) +1

B

What is the value stored at x, given the statements: int x; x = 3 / static_cast<int>(4.5 + 6.4); A) .3 B) 0 C) .275229 D) 3.3 E) None of these

B

What will be the output of the following code segment after the user enters 0 at the keyboard? int x = -1; cout << "Enter a 0 or a 1 from the keyboard: "; cin >> x; if (x) cout << "true" << endl; else cout << "false" << endl; A) Nothing will be displayed. B) false C) x D) true

B

What will the following code display? int number = 6 int x = 0; x = --number; cout << x << endl; A) 6 B) 5 C) 7 D) 0

B

What will the following code display? int number = 7; cout << "The number is " << "number" << endl; A) The number is 7 B) The number is number C) The number is7 D) The number is 0

B

What will the following code display? int numbers[4] = { 99, 87 }; cout << numbers[3] << endl; A) 87 B) 0 C) garbage D) This code will not compile

B

An expression such as pow(2,3) is called a(n) ____________________. A. function declaration B. function call C. function initialization. D. None of the above

B. Function call

Why do local variables lose their values between calls to the function in which they are defined?

Because they are created in memory when the function begins execution, and are destroyed when the function ends.

Which of the following is true about classes and structs?

By default, all members of a struct are public and all members of a class are private.

Whereas < is called a relational operator, x < y is called a(n) ________. A) Arithmetic operator B) Relative operator C) Relational expression D) Largeness test E) None of these

C

20. A(n) ___________ is like a variable, but its value is read-only and cannot be changed during the program's execution. A) secure variable B) uninitialized variable C) named constant D) locked variable

C

9. Every complete statement ends with a A) period B) # symbol C) semicolon D) ending brace

C

A file ________ is a small holding section of memory that file-bound information is first written to. A) name B) number C) buffer D) segment E) None of these

C

A function can have zero to many parameters, and it can return this many values. A) zero to many B) no C) only one D) a maximum of ten E) None of these

C

A function prototype is ____. a. a definition, but not a declaration b. a declaration and a definition c. a declaration, but not a definition d. a comment line

C

A program called a(n) ____ combines the object program with the programs from libraries.

C

A program called a(n) ____ translates instructions written in high-level languages into machine code. a. assembler c. compiler b. decoder d. linker

C

A statement that starts with a # symbol is called a: A) Comment B) Function C) Preprocessor directive D) Key word E) None of the above

C

A variable's ________ is the part of the program that has access to the variable. A) data type B) value C) scope D) reach E) None of the above

C

A(n) ________ is a set of instructions that the computer follows to solve a problem. A) Compiler B) Linker C) Program D) Operator E) None of the above

C

A(n) ________ is information that is passed to a function, and a(n) ________ is information that is received by a function. A) function call, function header B) parameter, argument C) argument, parameter D) prototype, header E) None of these

C

Associativity is either right to left or: A) Top to bottom B) Front to back C) Left to right D) Undeterminable E) None of the above

C

Assume that a program has the following variable definition: char letter; Which of the following statements correctly assigns the character Z to the variable? A) letter = Z; B) letter = "Z"; C) letter = 'Z'; D) letter = (Z);

C

Assuming dataFile is a file stream object, the statement: dataFile.close(); A) is illegal in C++ B) needs a filename argument to execute correctly C) closes a file D) is legal but risks losing valuable data E) None of these

C

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? A) write(outFile, number); B) outFile >> number; C) outFile << number; D) number >> outFile;

C

Suppose that ch1, ch2, and ch3 are variables of the type char and the input is: A B C Choose the value of ch3 after the following statement executes: cin >> ch1 >> ch2 >> ch3; a. 'A' c. 'C' b. 'B' d. '\n'

C

Suppose that x = 1565.683, y = 85.78, and z = 123.982. What is the output of the following statements? cout << fixed << showpoint; cout << setprecision(3) << x << ' '; cout << setprecision(4) << y << ' ' << setprecision(2) << z << endl; a. 1565.683 85.8000 123.98 c. 1565.683 85.7800 123.98 b. 1565.680 85.8000 123.98 d. 1565.683 85.780 123.980

C

Suppose that x = 25.67, y = 356.876, and z = 7623.9674. What is the output of the following statements? cout << fixed << showpoint; cout << setprecision(2); cout << x << ' ' << y << ' ' << z << endl; a. 25.67 356.87 7623.96 c. 25.67 356.88 7623.97 b. 25.67 356.87 7623.97 d. 25.67 356.876 7623.967

C

Suppose that x is an int variable and y is a double variable and the input is: 10 20.7 Choose the values after the following statement executes: cin >> x >> y;. a. x=10,y=20 c. x=10,y=20.7 b. x=10,y=20.0 d. x=10,y=21.0

C

Suppose that x is an int variable, y is a double variable, z is an int variable, and the input is: 15 76.3 14 Choose the values after the following statement executes: cin >> x >> y >> z; a. x=15,y=76,z=14 b. x=15,y=76,z=0 c. x=15,y=76.3,z=14 d. x=15.0,y=76.3,z=14.0

C

The ________ is/are used to display information on the computer's screen. A) Opening and closing braces B) Opening and closing quotation marks C) cout object D) Backslash E) None of the above

C

The ________ of a variable is limited to the block in which it is declared. A) precedence B) associativity C) scope D) branching ability E) None of these

C

The ________ operator always follows the cin object, and the ________ operator follows the cout object. A) binary, unary B) conditional, binary C) >>, << D) <<, >> E) None of the above

C

The basic commands that a computer performs are ____, and performance of arithmetic and logical operations. a. input, file, list c. input, output, storage b. output, folder, storage d. storage, directory, log

C

The computer's main memory is commonly known as: A) The hard disk B) The floppy disk C) RAM D) Secondary storage E) None of the above

C

The default section of a switch statement performs a similar task as the ________ portion of an if/else if statement. A) conditional B) break C) trailing else D) All of these E) None of these

C

The devices that the computer uses to display results are called ____ devices. a. exit c. output b. entry d. input

C

The expression in an if statement is sometimes called a(n) ____. a. selection statement c. decision maker b. action statement d. action maker

C

The numeric data types in C++ can be broken into two general categories: A) numbers and characters B) singles and doubles C) integer and floating point D) real and unreal E) None of the above

C

The programming language C++ evolved from ____.

C

The programming language C++ was designed by Bjarne Stroustrup at Bell Laboratories in the early ____.

C

The programming process consists of several steps, which include: A) Input, Processing, and Output B) Key Words, Operators, and Punctuation C) Design, Creation, Testing, and Debugging D) Syntax, Logic, and Error Handling E) None of the above

C

The statements written by the programmer are called: A) Syntax B) Object code C) Source code D) Runtime libraries E) None of the above

C

The value in this type of local variable persists between function calls. A) global B) internal C) static D) dynamic E) None of these

C

These are used to declare variables that can hold real numbers. A) Integer data types B) Real data types C) Floating point data types D) Long data types E) None of the above

C

This control sequence is used to skip over to the next horizontal tab stop. A) \n B) \h C) \t D) \a E) \'

C

This is a control structure that causes a statement or group of statements to repeat. A) decision statement B) constant C) loop D) cout object E) None of these

C

This is a variable, usually a bool or an int, that signals when a condition exists. A) relational operator B) arithmetic operator C) flag D) float E) None of these

C

This is a volatile type of memory, used for temporary storage. A) Address B) ALU C) RAM D) Disk drive E) None of the above

C

This loop is a good choice when you know how many times you want the loop to iterate in advance of entering the loop. A) do-while B) while C) for D) infinite E) None of these

C

This manipulator causes the field to be left-justified with padding spaces printed to the right. A) left_justify B) right C) left D) left_pad E) None of these

C

This manipulator is used to establish a field width for the value immediately following it. A) field_width B) set_field C) setw D) iomanip E) None of the above

C

This operator represents the logical AND. A) ++ B) || C) && D) @ E) None of these

C

This statement causes a function to end. A) end B) terminate C) return D) release E) None of these

C

This statement will pause the screen, until the [Enter] key is pressed. A) cin; B) cin.getline(); C) cin.get(); D) cin.ignore(); E) cin.input();

C

This stream manipulator forces cout to print the digits in fixed-point notation. A) setprecision(2) B) setw(2) C) fixed D) setfixed(2) E) None of these

C

This term refers to the programmer reading the program from the beginning and stepping through each statement. A) Pseudocoding B) Software Engineering C) Desk Checking D) Spot Checking E) None of the above

C

This type of variable is defined inside a function and is not accessible outside the function. A) global B) reference C) local D) counter E) None of these

C

Three primary activities of a program are: A) Variables, Operators, and Key Words B) Lines, Statements, and Punctuation C) Input, Processing, and Output D) Integer, Floating-point and Character E) None of the above

C

To allow file access in a program, you must #include this header file. A) file B) fileaccess C) fstream D) cfile

C

What does <= mean?? a. less than b. greater than c. less than or equal to d. greater than or equal to

C

What is the output of the following program? #include <iostream> using namespace std; int getValue(int); int main() { int x = 2; cout << getValue(x) << endl; return 0; } int getValue(int num) { return num + 5; } A) 5 B) 2 C) 7 D) "getValue(x)"

C

What is the output of the following segment of code if the value 4 is input by the user when asked to enter a number? int num; int total = 0; cout << "Enter a number from 1 to 10: "; cin >> num; switch (num) { case 1: case 2: total = 5; case 3: total = 10; case 4: total = total + 3; case 8: total = total + 6; default: total = total + 4; } cout << total << endl; A) 0 B) 3 C) 13 D) 28 E) None of these

C

What is the value of donuts after the following code executes? int donuts = 10; if (donuts = 1) donuts = 0; else donuts += 2; A) 12 B) 10 C) 0 D) 1

C

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) 15 D) 2

C

What is the value of x after the following statements execute? int x; x = (5 <= 3 && 'A' < 'F') ? 3 : 4 a. 2 c. 4 b. 3 d. 5

C

What value is returned by the following return statement? int x = 5; return x + 1; a. 0 b. 5 c. 6 d. 7

C

What will be the value of result after the following code has been executed? int a = 60; int b = 15; int result = 10; if (a = b) result *= 2; A) 10 B) 120 C) 20 D) This code will not compile.

C

What will the following code display? cout << "Four " << "score "; cout << "and " << "seven/n"; cout << "years" << "ago" << endl; A) Four score and seven yearsago B) Four score and seven years ago C) Four score and seven/nyearsago D) Four score and seven yearsago

C

What will the following code display? cout << "Monday"; cout << "Tuesday"; cout << "Wednesday"; A) Monday Tuesday Wednesday B) Monday Tuesday Wednesday C) MondayTuesdayWednesday D) "Monday" "Tuesday" "Wednesday"

C

What will the following code display? int number = 6; cout << ++number << endl; A) 6 B) 5 C) 7 D) 0

C

What will the following code display? int number = 6; ++number; cout << number << endl; A) 6 B) 5 C) 7 D) 0

C

What will the following code display? int number = 6; number++; cout << number << endl; A) 6 B) 5 C) 7 D) 0

C

What will the following code display? int numbers[] = { 99, 87, 66, 55, 101 }; for (int i = 1; i < 4; i++) cout << numbers[i] << endl; A) 99 87 66 55 101 B) 87 66 55 101 C) 87 66 55 D) Nothing. This code has an error.

C

What will the following segment of code output? score = 40; if (score > 95) cout << "Congratulations!\n"; cout << "That's a high score!\n"; cout << "This is a test question!" << endl; A) This is a test question! B) Congratulations! That's a high score! This is a test question! C) That's a high score! This is a test question! D) Congratulations! That's a high score! E) None of these

C

What will the following segment of code output? Assume the user enters a grade of 90 from the keyboard. cout << "Enter a test score: "; cin >> test_score; if (test_score < 60); cout << "You failed the test!" << endl; if (test_score > 60) cout << "You passed the test!" << endl; else cout << "You need to study for the next test!"; A) You failed the test! B) You passed the test! C) You failed the test! You passed the test! D) You failed the test! You did poorly on the test! E) None of the above

C

What will the value of x be after the following statements execute? int x; x = 18 % 4; A) 0.45 B) 4 C) 2 D) unknown

C

When an if statement is placed within the conditionally-executed code of another if statement, this is known as: A) complexity B) overloading C) nesting D) validation E) None of these

C

When one control statement is located within another, it is said to be _____. a. blocked b. compound c. nested d. closed

C

When the final value of an expression is assigned to a variable, it will be converted to: A) The smallest C++ data type B) The largest C++ data type C) The data type of the variable D) The data type of the expression E) None of the above

C

Which character signifies the beginning of an escape sequence? A) // B) / C) \ D) # E) {

C

Which line in the following program contains a call to the showDub function? 1 #include <iostream> 2 using namespace std; 3 4 void showDub(int); 5 6 int main() 7 { 8 int x = 2; 9 10 showDub(x); 11 cout << x << endl; 12 return 0; 13 } 14 15 void showDub(int num) 16 { 17 cout << (num * 2) << endl; 18 } A) 4 B) 6 C) 10 D) 15

C

Which of the following expressions correctly determines that x is greater than 10 and less than 20? a. 10<x<20 c. 10<x&&x<20 b. (10<x<20) d. 10<x||x<20

C

Which of the following expressions will determine whether x is less than or equal to y? A) x > y B) x =< y C) x <= y D) x >= y

C

Which of the following is the "not equal to" relational operator? a. ! b. | c. != d. &

C

Which of the following statements about global variables is true? A) A global variable is accessible only to the main function. B) A global variable is declared in the highest-level block in which it is used. C) A global variable can have the same name as a variable that is declared locally within a function. D) If a function contains a local variable with the same name as a global variable, the global variable's name takes precedence within the function. E) All of these are true.

C

Which statement allows you to properly check the char variable code to determine whether it is equal to a "C" and then output "This is a check" and then advance to a new line? A) if code is equal to C cout << "This is a check\n"; B) if (code = "C") cout << "This is a check" << endl; C) if (code == 'C') cout << "This is a check\n"; D) if (code == C) cout << "This is a check" << endl;

C

Which statement will read an entire line of input into the following string object? string address; A) cin << address; B) cin address; C) getline(cin, address); D) cin.get(address); E) None of the above

C

Which value can be entered to cause the following code segment to display the message: "That number is acceptable." int number; cin >> number; if (number > 10 && number < 100) cout << "That number is acceptable.\n"; else cout << "That number is not acceptable.\n"; A) 100 B) 10 C) 99 D) 0 E) All of these

C

Words that have a special meaning and may be used only for their intended purpose are known as: A) Operators B) Programmer Defined Words C) Key Words D) Syntax E) None of the above

C

You may define a ________ in the initialization expression of a for loop. A) constant B) function C) variable D) new data type E) None of these

C

____ consists of 65,536 characters. a. ASCII-8 c. Unicode b. ASCII d. EBCDIC

C

____ represent information with a sequence of 0s and 1s. a. Analog signals c. Digital signals b. Application programs d. System programs

C

________ are used to translate each source code instruction into the appropriate machine language instruction. A) Modules B) Library routines C) Compilers D) Preprocessor directives E) None of the above

C

Which of the following statements is correct? A) #include (iostream) B) #include {iostream} C) #include <iostream> D) #include [iostream] E) All of the above

C) #include <iostream>

10. Which of the following statements is correct? A) #include (iostream) B) #include {iostream} C) #include <iostream> D) #include [iostream] E) All of the above

C) <iostream>

A(n) _____ is like a variable, but its value is read-only and cannot be changed during the program's execution. A) secure variable B) uninitialized variable C) named constant D) locked variable

C) named constant

Every complete statement ends with a A) period B) # symbol C) semicolon D) ending brace

C) semicolon

16. Which of the following are not valid cout statements? (Circle all that apply.) A) cout << "Hello World"; B) cout << "Have a nice day"; C) cout < value; D) cout << Programming is great fun;

C, D

Suppose that x = 1565.683, y = 85.78, and z = 123.982. What is the output of the following statements? cout << fixed << showpoint; cout << setprecision(3) << x << ' '; cout << setprecision(4) << y << ' ' << setprecision(2) << z << endl; A. 1565.683 85.8000 123.98 B. 1565.683 85.8000 123.98 C. 1565.683 85.7800 123.98 D. 1565.683 85.780 123.980

C. 1565.683 85.7800 123.98

The data type bool:

Can take on values true and false.

_ are used to translate each source code instruction into the appropriate machine language instruction.

Compilers

EOF-controlled

Consider the following code. (Assume that all variables are properly declared.)cin >> ch;while (cin){cout << ch;cin >> ch;}

b

Consider the following program segment. ifstream inFile; //Line 1 int x, y; //Line 2 ... //Line 3 inFile >> x >> y; //Line 4 Which of the following statements at Line 3 can be used to open the file progdata.dat and input data from this file into x and y at Line 4? a. open(inFile,"progdata.dat"); b. inFile.open("progdata.dat"); c. inFile(open,"progdata.dat"); d. open.inFile("progdata.dat");

Which of the following encompasses the other three?

Control structure.

The ____ is the brain of the computer and the single most expensive piece of hardware in your personal computer. a. MM c. RAM b. ROM d. CPU

D

The ________ causes the contents of another file to be inserted into a program. A) Backslash B) Pound sign C) Semicolon D) #include directive E) None of the above

D

The ________ decodes an instruction and generates electrical signals. A) Arithmetic and Logic Unit B) Main memory C) BIOS D) Control Unit E) None of the above

D

The first step in using the string class is to #include the ________ header file. A) iostream B) cctype C) cmath D) string E) None of the above

D

The name for a memory location that may hold data is: A) Key Word B) Syntax C) Operator D) Variable E) None of the above

D

The range-based for loop, in C++ 11, is designed to work with a built-in variable known as the ________. A) counter variable B) i variable C) iterator D) range variable E) None of these

D

The total number of digits that appear before and after the decimal point is sometimes referred to as: A) floating points B) significant digits C) precision D) B and C E) None of these

D

The value in a ________ variable persists between function calls. A) dynamic B) local C) counter D) static local

D

This function causes a program to terminate, regardless of which function or control mechanism is executing. A) terminate() B) return() C) continue() D) exit() E) None of these

D

This is a collection of statements that performs a specific task. A) infinite loop B) variable C) constant D) function E) None of these

D

This is a special value that marks the end of a list of values. A) constant B) variable C) loop D) sentinel E) None of these

D

This is a statement that causes a function to execute. A) for loop B) do-while loop C) function prototype D) function call E) None of these

D

This may be used to write information to a file. A) cout object B) pen object C) output object D) stream insertion operator E) None of these

D

This operator is known as the logical OR operator. A) -- B) // C) # D) || E) None of these

D

This operator is used in C++ to represent equality. A) = B) >< C) !! D) == E) None of these

D

This operator takes an operand and reverses its truth or falsehood. A) || B) relational C) arithmetic D) ! E) None of these

D

This statement may be used to stop a loop's current iteration and begin the next one. A) break B) terminate C) re-iterate D) continue E) None of these

D

This statement may be used to stop a loop's current iteration and begin the next one. A) break B) terminate C) return D) continue E) None of these

D

To use the rand() function, you must #include this header file in your program. A) iostream B) iomanip C) iorand D) cstdlib E) None of these

D

To write data to a file, you define an object of this data type. A) outputFile B) ifstream C) fstream D) ofstream

D

What is assigned to the variable a given the statement below with the following assumptions: x = 10, y = 7, and z, a, and b are all int variables. a = x >= y; A) 10 B) 7 C) The string "x >= y" D) 1 E) 0

D

What is the modulus operator? A) + B) * C) & D) % E) ||

D

What is the output of the following code? int w = 98; int x = 99; int y = 0; int z = 1; if (x >= 99) { if (x < 99) cout << y << endl; else cout << z << endl; } else { if (x == 99) cout << x << endl; else cout << w << endl; } A) 98 B) 99 C) 0 D) 1

D

What is the output of the following code? char lastInitial = 'S'; switch (lastInitial) { case 'A': cout << "section 1" <<endl; break; case 'B': cout << "section 2" <<endl; break; case 'C': cout << "section 3" <<endl; break; case 'D': cout << "section 4" <<endl; break; default: cout << "section 5" <<endl; } a. section 2 b. section 3 c. section 4 d. section 5

D

What is the output of the following program? #include <iostream> using namespace std; void doSomething(int&); int main() { int x = 2; cout << x << endl; doSomething(x); cout << x << endl; return 0; } void doSomething(int& num) { num = 0; cout << num << endl; } A) 2 0 2 B) 2 2 2 C) 0 0 0 D) 2 0 0

D

What statement best describes a variable and its primary purpose? A) A variable is a structured, general-purpose language designed primarily for teaching programming. B) A variable is a collection of eight bits. C) A variable is a word that has a special meaning to the compiler. D) A variable is a named storage location in the computer's memory used for holding a piece of information. E) A variable is a "line" of code in the body of a program, which may change.

D

What will the following code display? cout << "Four" << "score" << endl; cout << "and" << "seven" << endl; cout << "years" << "ago" << endl; A) Four score and seven years ago B) Four score and seven years ago C) Fourscoreandsevenyearsago D) Fourscore andseven yearsago

D

What will the following code display? int x = 0, y = 1, z = 2; cout << x << y << z << endl; A) 0 1 2 B) 0 1 2 C) xyz D) 012

D

What will the following code display? int x = 0; for (int count = 0; count < 3; count++) x += count; cout << x << endl; A) 0 1 2 B) 0 C) 6 D) 3

D

What will the following program segment display? int funny = 7, serious = 15; funny = serious % 2; if (funny != 1) { funny = 0; serious = 0; } else if (funny == 2) { funny = 10; serious = 10; } else { funny = 1; serious = 1; } cout << funny << " " << serious << endl; A) 7 15 B) 0 0 C) 10 10 D) 1 1 E) None of these

D

What will the value of result be after the following statement executes? result = 6 - 3 * 2 + 7 - 10 / 2 ; A) 8 B) 6 C) 1.5 D) 2

D

When this operator is used with string operands it concatenates them, or joins them together. A) & B) * C) % D) + E) None of the above

D

When you want to process only partial data, you can use the stream function ____ to discard a portion of the input. a. clear c. delete b. skip d. ignore

D

Which data type typically requires only one byte of storage? A) short B) int C) float D) char E) double

D

Which line in the following program contains the header for the showDub function? 1 #include <iostream> 2 using namespace std; 3 4 void showDub(int); 5 6 int main() 7 { 8 int x = 2; 9 10 showDub(x); 11 cout << x << endl; 12 return 0; 13 } 14 15 void showDub(int num) 16 { 17 cout << (num * 2) << endl; 18 } A) 4 B) 6 C) 10 D) 15

D

Which line in the following program will cause a compiler error? 1 #include <iostream> 2 using namespace std; 3 4 int main() 5 { 6 const int MY_VAL = 77; 7 MY_VAL = 99; 8 cout << MY_VAL << endl; 9 return 0; 10 } A) 6 B) 8 C) 9 D) 7

D

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, y, z = 7, 16, 28 D) int x = 7, y = 16, z = 28; E) None of these will work.

D

Which of the following function prototypes is valid? a. int funcTest(int x, int y, float z){} b. funcTest(int x, int y, float){}; c. int funcTest(int, int y, float z) d. int funcTest(int, int, float);

D

Which of the following operators has the lowest precedence? a. ! c. && b. || d. =

D

You can disable assert statements by using which of the following? a. #include <cassert> c. #clear NDEBUG b. #define <assert> d. #define NDEBUG

D

____ is a parameterized stream manipulator. a. endl b. fixed c. scientific d. setfill

D

Every C++ program must have a A) cout statement B) function main C) #include statement D) All of the above

D) All of the above

Suppose that x and y are int variables, ch is a char variable, and the input is: 4 2 A 12 Choose the values of x, y, and ch after the following statement executes: cin>>x>>ch>>y; A. x=4,ch=2,y=12 B. x=4,ch=A,y=12 C. x=4,ch='',y=2 D. This statement results in input failure

D. This statement results in input failure

Suppose that x is an int variable and y is a double variable. The input is: 10.5 20.7 Choose the values after the following statement executes: cin >> x >> y;. A. x= 10, y= 20 B. x= 10, y= 20.0 C. x= 10, y= 20.7 D. x= 10, y= 0.5

D. x= 10.5, y= 0.5

Pseudocode does not include:

Declarations

_____ arguments are passed to parameters automatically if no argument is provided in the function call.

Default

This term refers to the programmer reading the program from the beginning and stepping through each statement.

Desk checking

In a function header, you must furnish: A) data type(s) of the parameters B) data type of the return value C) the name of function D) names of parameter variables E) All of these

E

Of the following, which is a valid C++ identifier? A) June1997 B) _employee_number C) ___department D) myExtraLongVariableName E) All of the above are valid identifiers.

E

This function in C++ allows you to identify how many bytes of storage on your computer system an integer data value requires. A) len B) bytes C) f(x) D) int E) sizeof

E

Which escape sequence causes the cursor to move to the beginning of the current line? A) \n B) \t C) \a D) \b E) \r

E

Which of the following is a common input device? A) Keyboard B) Mouse C) Scanner D) Microphone E) All of the above

E

Which of the following is a preprocessor directive? A) pay = hours * rate; B) cin >> rate; C) // This program calculates the user's pay. D) int main() E) #include <iostream>

E

Consider the following code. (Assume that all variables are properly declared.) cin >> ch;while (cin){cout << ch;cin >> ch;}

EOF Controlled

a

Entering a char value into an int variable causes serious errors, called input failure. a. True b. False

function main

Every C++ program must have a [cout statement [function main [#include statement [all of the above

semicolon

Every complete statement ends with a: [period [# symbol [semicolon [ending brace

A comma is also called a statement terminator.

F

An operator that has only one operand is called a unique operator.

F

Assume that all variables are properly declared. The following for loop executes 20 times. for (i = 0; i <= 20; i++)cout << i;

F

Given this declaration: class myClass{public:void print(); //Output the value of x;MyClass();private:int x;};myClass myObject;The following statement is legal. myObject.x = 10;

F

If an object is created in a user program, then the object can access both the public and private members of the class

F

If input failure occurs in a C++ program, the program terminates immediately and displays an error message.

F

If the expression in an assert statement evaluates to true, the program terminates.

F

If the heading of a member function of a class ends with the word const, then the function member cannot modify the private member variables, but it can modify the public member variables.

F

In C++, both ! and != are relational operators.

F

In C++, reserved words are the same as predefined identifiers.

F

In a sentinel-controlled while loop, the body of the loop continues to execute until the EOF symbol is read.

F

In an output statement, each occurrence of endl advances the cursor to the end of the current line on an output device.

F

The execution of a return statement in a user-defined function terminates the program.

F

The extraction operator >> skips only all leading blanks when searching for the next data in the input stream.

F

The following return statement returns the value 10. return 10, 16;

F

The following statements will result in input failure if the input values are not on a separate line. (Assume that x and y are int variables.) cin >> x; cin >> y;

F

The following while loop terminates when j > 20. j = 0;while (j < 20)j++;

F

The operators !, &&, and || are called relational operators.

F

The public members of a class must be declared before the private members.

F

The result of a logical expression cannot be assigned to an int variable, but it can be assigned to a bool variable.

F

You can use arithmetic operators to perform arithmetic operations on class objects.

F

23. T F Variable names may begin with a number.

FALSE

26. T F You cannot initialize a named constant that is declared with the const modifier.

FALSE

True/False: A function's return data type must be the same as the function's parameter(s).

FALSE

True/False: A local variable and a global variable may not have the same name within the same program.

FALSE

True/False: A variable called "average" should be declared as an integer data type because it will probably hold data that contains decimal places.

FALSE

True/False: A while loop is somewhat limited, because the counter can only be incremented by one each time through the loop.

FALSE

True/False: Arithmetic operators that share the same precedence have right to left associativity.

FALSE

True/False: C++ 11 introduces an alternative way to define variables, using the template key word and an initialization value.

FALSE

True/False: If you do not follow a consistent programming style, your programs will generate compiler errors.

FALSE

True/False: If you want to know the length of the string that is stored in a string object, you can call the object's size member function.

FALSE

True/False: In C++ 11, the range-based for loop is best used in situations where you need the element subscript for some purpose.

FALSE

True/False: In C++, it is impossible to display the number 34.789 in a field of 9 spaces with 2 decimal places of precision.

FALSE

True/False: In programming, the terms "line" and "statement" always mean the same thing.

FALSE

True/False: Local variables are initialized to zero by default.

FALSE

True/False: Machine language is an example of a high-level language.

FALSE

True/False: Programs are commonly referred to as hardware.

FALSE

True/False: Pseudocode is a form of program statement that will always evaluate to "false."

FALSE

True/False: The C++ language requires that you give variables names that indicate what the variables are used for.

FALSE

True/False: The condition that is tested by a while loop must be enclosed in parentheses and terminated with a semicolon.

FALSE

True/False: The default section is required in a switch statement.

FALSE

True/False: The fixed manipulator causes a number to be displayed in scientific notation.

FALSE

True/False: The following code correctly determines whether x contains a value in the range of 0 through 100. if (x >= 0 && <= 100)

FALSE

True/False: The following statement will output $5.00 to the screen: cout << setprecision(5) << dollars << endl;

FALSE

True/False: The increment and decrement operators can be used in mathematical expressions; however, they cannot be used in relational expressions.

FALSE

True/False: The preprocessor executes after the compiler.

FALSE

True/False: The scope of a variable declared in a for loop's initialization expression always extends beyond the body of the loop.

FALSE

True/False: When a function is called, flow of control moves to the function's prototype.

FALSE

True/False: When a program uses the setw manipulator, the iosetwidth header file must be included in a preprocessor directive.

FALSE

True/False: You may nest while and do-while loops, but you may not nest for loops.

FALSE

True/False: You may not use the break and continue statements within the same set of nested loops.

FALSE

True/False: You may not use the break statement in a nested loop.

FALSE

True/False: You must furnish an argument with a function call.

FALSE

Assume that all variables are properly declared. The following for loop executes 20 times. for (i = 0; i <= 20; i++) cout << i;

False

In a sentinel-controlled while loop, the body of the loop continues to execute until the EOF symbol is read.

False

T/F Variable names may begin with a number.

False

T/F You cannot initialize a named constant that is declared with the const modifier.

False

T/F All static variables are initialized to -1 by default.

False

T/F Changes to a function parameter always affect the original argument as well.

False

T/F Function headers are terminated with a semicolon.

False

T/F It is not possible for a function to have some parameters with default arguments and some without.

False

T/F The exit function can only be called from the main.

False

T/F When a function terminates, it always branches back to the main, regardless where it was called from.

False

The following statements will result in input failure if the input values are not on a separate line. (Assume that x and y are int variables.) cin >> x; cin >> y; (T/F)

False

The following while loop terminates when j > 20. j = 0; while (j < 20)

False

The statement in the body of a while loop acts as a decision maker.

False

True/False: In programming, the terms "line" and "statement" always mean the same thing. Select one: True False

False

True/False: Machine language is an example of a high-level language. Select one: True False

False

True/False: Programs are commonly referred to as hardware. Select one: True False

False

True/False: The preprocessor executes after the compiler. Select one: True False

False

In an output statement, each occurrence of endl advances the cursor to the end of the current line on an output device. (T/F)

False - advances cursor to beginning of next line (End current line, start new line)

peek returns next character from input stream and removes it (T/F)

False - does not remove it

The manipulator setw formats the output of an expression in a specific number of columns; the default output is left-justified.

False - right-justified

In an activity diagram for an algorithm, what does a solid circle surrounded by a hollow circle represent?

Final state.

multi-line

Is the following comment written using single-line or multi-line comment symbols? /* This program was written by M.A. Codewriter */

Consider the following statement: int alpha[25][10];. Which of the following statements about alpha is true?

Rows of alpha are numbered 0...24 and columns are numbered 0...9.

The program crashes...Ex: an operation attempted to divide by zero.

Runtime error

Which of the following is NOT a reserved word in C++?

Select

Indefinite repetition is controlled by a:

Sentinel value.

Should never be modified.

Should always be evaluated before being processed.

Is the following comment written using single-line or multi-line comment symbols? // this program was written by M. A. Codewriter

Single-Line

6. Is the following comment written using single-line or multi-line comment symbols? // This program was written by M. A. Codewriter

Single_line

Compilation errors resulting from illegal uses of key words, operators, punctuation, and other language elements

Syntax error

A class is an example of a structured data type.

T

A compound statement functions as if it was a single statement.

T

A control structure alters the normal sequential flow of execution in a program.

T

Assume that all variables are properly declared. The following statement in a value-returning function is legal. if (x % 2 == 0)return x;elsereturn x + 1;

T

Entering a char value into an int variable causes serious errors, called input failure.

T

If a C++ arithmetic expression has no parentheses, operators are evaluated from left to right.

T

If an object is declared in the definition of a member function of the class, then the object can access both the public and private members of the class.

T

In C++ terminology, a class object is the same as a class instance.

T

In C++, && has a higher precedence than ||.

T

In C++, a function prototype is the function heading without the body of the function.

T

In C++, the operators != and == have the same order of precedence.

T

In a counter-controlled while loop, the loop control variable must be initialized before the loop.

T

In the case of the sentinel-controlled while loop, the first item is read before the while loop is entered

T

Once you write and properly debug a function, you can use it in the program (or different programs) again and again without having to rewrite the same code repeatedly.

T

Suppose P and Q are logical expressions. The logical expression P && Q is true if both P and Q are true.

T

Suppose a = 5. After the execution of the statement ++a; the value of a is 6.

T

Suppose we declare a variable sum as an int. The statement " sum += 7; " is equivalent to the statement " sum = sum + 7; " .

T

Suppose x is 5 and y is 7. Choose the value of the following expression: (x != 7) && (x <= y)

T

The control statements in the for loop include the initial statement, loop condition, and update statement.

T

The control variable in a flag-controlled while loop is a bool variable.

T

The data type of a variable in a return statement must match the function type.

T

The following function heading in a C++ program is valid: int funcExp(int u, char v, float g)

T

The maximum number of significant digits in float values is up to 6 or 7.

T

The number of input data extracted by cin and >> depends on the number of variables appearing in the cin statement.

T

The number of iterations of a counter-controlled loop is known in advance.

T

Using functions greatly enhances a program's readability because it reduces the complexity of the function main.

T

When reading data into a char variable, after skipping any leading whitespace characters, the extraction operator >> finds and stores only the next character; reading stops after a single character.

T

You can use the function getline to read a string containing blanks.

T

True

T/F: a left brace in a C++ program should always be followed by a right brace later in the program.

False

T/F: variable names may begin with a number.

True/False: If the sub-expression on the left side of the || operator is true, the expression on the right side will not be checked.

TRUE

22. T F A variable must be defined before it can be used.

TRUE

24. T F Variable names may be up to 31 characters long.

TRUE

25. T F A left brace in a C++ program should always be followed by a right brace later in the program.

TRUE

True/False: A CPU really only understands instructions that are written in machine language.

TRUE

True/False: A parameter is a special-purpose variable that is declared inside the parentheses of a function definition.

TRUE

True/False: A preprocessor directive does not require a semicolon at the end.

TRUE

True/False: A static variable that is defined within a function is initialized only once, the first time the function is called.

TRUE

True/False: A while loop's body can contain multiple statements, as long as they are enclosed in braces.

TRUE

True/False: An expression that has any value other than 0 is considered true by an if statement.

TRUE

True/False: An initialization expression may be omitted from the for loop if no initialization is required.

TRUE

True/False: An output file is a file that data is written to.

TRUE

True/False: As a rule of style, when writing an if statement you should indent the conditionally-executed statements.

TRUE

True/False: Both of the following if statements perform the same operation. if (sales > 10000) commissionRate = 0.15; if (sales > 10000) commissionRate = 0.15;

TRUE

True/False: C++ does not have a built in data type for storing strings of characters.

TRUE

True/False: Escape sequences are always stored internally as a single character.

TRUE

True/False: Floating point constants are normally stored in memory as doubles.

TRUE

True/False: Global variables are initialized to zero by default.

TRUE

True/False: If the sub-expression on the left side of an && operator is false, the expression on the right side will not be checked.

TRUE

True/False: If you want to stop a loop before it goes through all its iterations, the break statement may be used.

TRUE

True/False: In C++ 11 you can pass a string object as argument to a file stream object's open member function.

TRUE

True/False: In C++, key words are written in all lowercase letters.

TRUE

True/False: It is not considered good programming practice to declare all of your variables globally.

TRUE

True/False: It is possible for a function to have some parameters with default arguments and some without.

TRUE

True/False: It is possible to define a file stream object and open a file in one statement.

TRUE

True/False: Multiple relational expressions cannot be placed into the test condition of a for loop.

TRUE

True/False: One reason for using functions is to break programs into manageable units, or modules.

TRUE

True/False: Software engineering is a field that encompasses designing, writing, testing, debugging, documenting, modifying, and maintaining computer programs.

TRUE

True/False: The CPU is the most important component in a computer because without it, the computer could not run software.

TRUE

True/False: The cin << statement will stop reading input when it encounters a newline character.

TRUE

True/False: The only difference between the get function and the >> operator is that get reads the first character typed, even if it is a space, tab, or the [Enter] key.

TRUE

True/False: The term "bit" stands for binary digit.

TRUE

True/False: The update expression of a for loop can contain more than one statement, e.g. counter++, total+= sales.

TRUE

True/False: When C++ is working with an operator, it strives to convert the operands to the same type.

TRUE

True/False: When the fixed manipulator is used, the value specified by the setprecision manipulator will be the number of digits to appear after the decimal point.

TRUE

True/False: When typing in your source code into the computer, you must be very careful since most of your C++ instructions, header files, and variable names are case sensitive.

TRUE

True/False: When writing long integer literals or long long integer literals in C++ 11, you can use either an uppercase or lowercase L.

TRUE

True/False: You may use the exit() function to terminate a program, regardless of which control mechanism is executing.

TRUE

True/False: You should be careful when using the equality operator to compare floating point values because of potential round-off errors.

TRUE

True/False: string objects have a member function named c_str that returns the contents of the object formatted as a null-terminated C-string.

TRUE

Which of the following is not a piece of information that could be found in the attribute compartment of a class's rectangle in the UML?

The attribute's memory location.

True

The control statements in the for loop include the initial statement, loop condition, and update statement.

True

The control variable in a flag-controlled while loop is a bool variable.

b

The extraction operator >> skips only all leading blanks when searching for the next data in the input stream. a. True b. False

literals or constants

The following data 72 'A' "Hello World" 2.8712 are all examples of [Variable [Literals or constants [Strings [None of the above

b

The following statements will result in input failure if the input values are not on a separate line. (Assume that x and y are int variables.) cin >> x; cin >> y; a. True b. False

Unary

The negation operator is [unary [binary [ternary [None of the above

a

The number of input data extracted by cin and >> depends on the number of variables appearing in the cin statement. a. True b. False

True

The number of iterations of a counter-controlled loop is known in advance.

What does the term hardware refer to?

The physical components that a computer is made of.

T/F Initialization of static local variables only happen once, regardless of how many times the function in which they are defined is called.

True

T/F Many functions may have local variables with the same name.

True

T/F Overuse of global variables can lead to problems.

True

T/F Static local variables are not destroyed when a function returns.

True

T/F The scope of the parameter is limited to the function which uses it.

True

T/F When a function with default arguments is called and an argument is left out, all arguments that come after it must be left out as well.

True

The control statements in the for loop include the initial statement, loop condition, and update statement.

True

The control variable in a flag-controlled while loop is a bool variable.

True

The extraction operator >> skips only all leading blanks when searching for the next data in the input stream. (T/F)

True

The header file fstream contains the definitions of ifstream and ofstream. (T/F)

True

The manipulator setfill is used to fill the unused columns on an output device with a character other than a space. (T/F)

True

The manipulator setprecision formats the output of floating-point numbers to a specified number of decimal places. (T/F)

True

The number of input data extracted by cin and >> depends on the number of variables appearing in the cin statement. (T/F)

True

The number of iterations of a counter-controlled loop is known in advance.

True

You can use the function getline to read a string containing blanks (T/F)

True

You can use the function getline to read a string containing blanks. (T/F)

True

A class and its members can be described graphically using a notation known as the ____ notation.

UML

When only a copy of an argument is passed to a function, it is said to be passed by ______

Value

Suppose that ch1 and ch2 are char variables and the input is: WXYZ What is the value of ch2 after the following statements execute? cin.get(ch1); cin.putback(ch1); cin >> ch2;

W

10 11

What is the output of the following C++ code? int j; for (j = 10; j <= 10; j++)cout << j << " ";cout << j << endl;

25 1

What is the output of the following C++ code?count = 1;num = 25;while (count < 25){num = num - 1;count++;}cout << count << " " << num << endl;

10

What is the output of the following C++ code?num = 10;while (num > 10)num = num - 2;cout << num << endl;

infinite loop

What is the output of the following loop?count = 5;cout << 'St';do{cout << 'o';count--;} while (count <= 5);

d

What is the output of the following statements? cout << setfill('*'); cout << "12345678901234567890" << endl cout << setw(5) << "18" << setw(7) << "Happy" << setw(8) << "Sleepy" << endl; a. 12345678901234567890 ***18**Happy Sleepy b. 12345678901234567890 ***18**Happy Sleepy** c. 12345678901234567890 ***18 Happy Sleepy d. 12345678901234567890 ***18**Happy**Sleepy

40

What is the value of x after the following statements execute?int x = 5;int y = 30;dox = x * 2;while (x < y);

at the same time as the compiler compiles your program

When do preprocessor directives execute? [before the compiler compiles your program [after the compiler compiles your program [at the same time as the compiler compiles your program [None of the above

a

When reading data into a char variable, after skipping any leading whitespace characters, the extraction operator >> finds and stores only the next character; reading stops after a single character. a. True b. False

b

When you want to process only partial data, you can use the stream function ____ to discard a portion of the input. a. delete b. ignore c. skip d. clear

the statement

Which executes first in a do... while loop?

72 = amount; profit = 129

Which of the following are not valid assignment statements? [total = 9; [72 = amount; [profit = 129 [letter = 'W';

do....while

Which of the following is a repetition structure in C++?

do...while

Which of the following loops does not have an entry condition?

do...while loop

Which of the following loops is guaranteed to execute at least once?

In all these solutions we are going to assume that appropriate variables have already been declared. A.) To store value of variable a increased by 2 to variable b we use following line: b = a + 2; B.) To store value of variable b multiplied by 4 to variable a we use following line: a = 4 * b; C.) To store value of variable a divided be 3.14 to variable b we use following line: b = a / 3.14; D.) To store value of variable b reduced by 8 to variable a we use following line: a = b - 8; E.) To store 27 to variable a we use following line: a = 27; F.) To store character 'K' in variable c we use following line: c = 'K'; G.) Look at the ASCII table and fine the value of character 'B'. As you can see from the table, ASCII code for 'B' is 66. So, code we need is given below: c = 66;

Write assignment statements that perform the following operations with the variables a , b , and c . A) Adds 2 to a and stores the result in b . B) Multiplies b times 4 and stores the result in a . C) Divides a by 3.14 and stores the result in b . D) Subtracts 8 from b and stores the result in a . E) Stores the value 27 in a. F) Stores the character 'K' in c . G) Stores the ASCII code for 'B' in c .

Suppose that ch1 and ch2 are char variables and the input is: WXYZ What is the value of ch2 after the following statements execute? cin >> ch1; ch2 = cin.peek(); cin >> ch2;

X

When a function accepts multiple arguments, does it matter order the arguments are passed in?

Yes. The first argument is passed into the parameter variable that appears first inside the function header's parentheses. Likewise, the second argument is passed into the second parameter, and so on.

a

You can use the function getline to read a string containing blanks. a. True b. False

Which escape sequence cause a "backslash" to be printed?

\\ NOTE: to have this appear: /\/\ win /\/\ you need to input: "/\\/\\ win /\\/\\

Which of the following is the newline character?

\n

Identify the escape sequences: \n \t \a \b \r \\ \' \"

\n Newline Causes the cursor to go to the next line for subsequent printing. \t Horizontal tab C auses the cursor to skip over to the next tab stop. \a Alarm Causes the computer to beep. \b Backspace Causes the cursor to back up, or move left one position. \r Return Causes the cursor to go to the beginning of the current line, not the next line. \\ Backslash Causes a backslash to be printed. \' Single quote C auses a single quotation mark to be printed. \" Double quote

d

____ is a parameterized stream manipulator. a. scientific b. fixed c. endl d. setfill

identifier

a C++ identifier consists of letters, digits, and the underscore character (_); it must begin with a letter or underscore

function

a collection of statements; when activated, or executed, it accomplishes something

floating-point

a data type that deals with decimal numbers

integral

a data type that deals with integers, or numbers, without a decimal part

Which of the following loops does not have an entry condition?

a do while loop

floating-point notation

a form of scientific notation used to represent real numbers

predefined function

a function that is already written and provided as part of the system

named constant

a memory location whose content is not allowed to change during program execution

variable

a memory location whose content may change during program execution

collating sequence

a predefined ordering for the characters in a set

preprocessor

a program that carries out preprocessor directives

keyword

a reserved word

computer program

a sequence of statements whose objective is to accomplish a task

string

a sequence of zero or more characters

semantics

a set of rules that gives meaning to a language

programming language

a set of rules, symbols, and special words

data type

a set of values together with a set of operations

input statement

a statement that places data into variables using cin and >>

simple assignment statement

a statement that uses only the assignment operator to assign values to the variable on the left side of the operator

null string

a string containing no characters

enumeration

a user-defined data type

Which of the following operators has the highest precedence? a. ! b. * c. % d. =

a. !

Which of the following best describes an operator? Select one: a. An operator allows you to perform operations on one or more pieces of data. b. An operator is a symbolic name that refers to a variable. c. An operator is a rule that must be followed when constructing a program. d. An operator is a word that has a special meaning. e. An operator marks the beginning or ending of a statement, or is used to separate items in a list.

a. ( An operator allows you to perform operations on one or more pieces of data. )

Suppose that x is an int variable. Which of the following expressions always evaluates to true? a. (x > 0) I I (x <= 0) b. (x >= 0) I I (x == 0) c. (x > 0) && ( x <= 0) d. (x > 0) & & (x == 0)

a. (x > 0) I I (x <= 0)

Even when there is no power to the computer, data can be held in: A) Secondary storage B) The Input Device C) The Output Device D) The Algorithm E) None of the above

A

Functions are ideal for use in menu-driven programs. When a user selects a menu item, the program can ________ the appropriate function. A) call B) prototype C) define D) declare E) None of these

A

How many times will the following loop display "Hello"? for (int i = 0; i < 20; i++) cout << "Hello!" << endl; A) 20 B) 19 C) 21 D) An infinite number of times

A

How many times will the following loop display "Hello"? for (int i = 20; i > 0; i--) cout << "Hello!" << endl; A) 20 B) 19 C) 21 D) An infinite number of times

A

If a function is called more than once in a program, the values stored in the function's local variables do not ________ between function calls. A) persist B) execute C) communicate D) change E) None of these

A

Which of the following operators has the highest precedence? a. ! c. % b. * d. =

A

Which statement is equivalent to the following? number += 1; A) number = number + 1; B) number + 1; C) number = 1; D) None of these

A

In C++, the dot is an operator called the ____ operator. The '.' In cin.get(ch1)

member access

The components of a class are called the ____ of the class.

members

What is the % symbol called? What are the result of the follow statements: 28 % 5 = 31 % 10 = 40 % 2 = 20 % 30 =

modulus Ex: 28 % 5 = 5 * 5 = 25 => 28 - 25 =3. therefore the remainder is 3. 3 1 0 20

Two or more functions may have the same name, as long as their ___ are different

parameter lists

Special arguments that hold copies of function arguments are called

parameters

A software ____________________ is a piece of code written on top of an existing piece of code intended to fix a bug in the original code.

patch

A do...while loop is a(n) ____________________ loop, since the loop condition is evaluated after executing the body of the loop.

posttest

class rectangleType{public:void setLengthWidth(double x, double y);//Postcondition: length = x; width = y;void print() const;//Output length and width;double area();//Calculate and return the area of the rectangle;double perimeter();//Calculate and return the parameter;rectangleType();//Postcondition: length = 0; width = 0;rectangleType(double x, double y);//Postcondition: length = x; width = y;private: double length;double width;}; Consider the accompanying class definition. Which of the following variable declarations is correct?

rectangleType rectangle;

Reference variables allow arguments to be passed by ___

reference

When used as parameters, ___ variables allow the function to access the parameter's original argument

reference

Which of the following are equivalent to (!(x < 15 && y >= 3))? a. (x >= 15 || y < 3) b. (x >= 15 && y < 3) c. (x > 15 && y <= 3) d. (x > 15 || y < 3) e. C and D

a. (x >= 15 || y < 3)

Which of the following boolean expressions tests to see if x is between 2 and 15 (including 2 and 15)? a. (x >= 2 && x <= 15) b. (x <= 15 || x >= 2) c. (2 <= x || x <= 15) d. (2 <= x <= 15)

a. (x >= 2 && x <= 15)

Which of the following are equivalent to (!(x<15 && y>=3))?

a. (x>15 && y<=3) b. (x>=15&&y<3) ***c. (x>=15||y<3) d. (x>15||y<3)

What is the output of the following code? if (6 > 8) { cout « " ** " « endl ; cout « "****" « endl; } else if (9 == 4) cout « "***" « endl; else cout « "*" « endl; a. * b. ** c. *** d ****

a. *

What is the output of the following code fragment? int i = 5; switch(i) { case 0:i = 15;break; case 1:i = 25;break; case 2:i = 35;break; case 3:i = 40; break; default:i = 0; break; } cout << i <<endl; a. 0 b. 15 c. 25 d. 35 e. 40

a. 0

What is the output of the following code fragment? int x=0; while( x < 5) cout << x << endl; x++; cout << x << endl;

a. 0 b. 5 c. 4 ***d. Infinite loop

How many times is "Hi" printed to the screen? for(int i = 0;i < 14;i ++ ); cout << "Hi\n"; a. 1 b. 15 c. 13 d. 14

a. 1

What is the value of x after the following code executes? int x=10; if(x++ > 10) { x=13; }

a. 10 b. 9 c. 13 ***d. 11

What is the value of x after the following code executes? int x = 10; if(x ++ > 10) { x = 13; } a. 11 b. 13 c. 10 d. 9

a. 11

In __ structures, the computer repeats particular statements a certain number of times depending on some condition(s). a. looping b. branching c. selection d. sequence

a. looping

If a programming language does not use short-circuit evaluation, what is the output of the following code fragment if the value of myInt is 0? int other=3, myInt; if(myInt != 0 && (other % myInt) != 0) cout << "other is odd\n"; else cout << "other is even\n";

a. other is even b. other is odd c. 0 ***d. run-time error, no output

If a programming language does not use short-circuit evaluation, what is the output of the following code fragment if the value of myInt is 0? int other = 3, myInt; if(myInt != 0 && other % myInt != 0) cout << "other is odd\n"; else cout << "other is even\n"; a. run-time error, no output b. other is even c. other is odd

a. run-time error, no output

What is the output of the following code? char lastlnitial = 'A'; switch (lastlnitial) { case 'A': cout « "section 1" «endl; break; case 'E': cout « "section 2" «endl; break; case 'C': cout « "section 3" «endl; break; case 'D': cout « "section 4" «endl; break; default: cout « "section 5" «endl; } a. section 1 b. section 2 c. section 3 d. section 5

a. section 1

Which executes first in a do ... while loop? a. statement b. loop condition c. initial statement d. update statement

a. statement

What is the value of the following expression? (true && (4/3 || !(6))) a. true b. illegal syntax c. false

a. true

If you were to write a function for displaying the cost of an item to the screen, which function prototype would be most appropriate?

a. void display(); ***b. void display(float myCost); c. int display (float myCost); d. float display();

The programmer usually enters source code into a computer using: Select one: a. Pseudocode b. A text editor c. A hierarchy chart d. A compiler e. None of these

b. (A text editor )

If you want a loop to quit iterating if x < 10 and y > 3, what would be the proper loop condition test? a. (x >=10 && y <= 3) b. (x >= 10 || y <= 3) c. (x > 10 || y < 3) d. (x < 10 && y > 3)

b. (x >= 10 || y <= 3)

Suppose j, sum, and num are int variables, and the input is 26 34 61 4 -1. What is the output of the code? sum = 0; cin » num; for (int j = 1; j <= 4; j++) { sum = sum + num; cin » num; } cout « sum « endl; a. 124 b. 125 c. 126 d 127

b. 125

What is the value of x after the following code executes? int x = 10; if( ++ x > 10) { x = 13; } a. 10 b. 13 c. 9 d. 11

b. 13

Assume all variables are properly declared. What is the output of the following C++ code? num = 100; while (num <= 150) num = num + 5; cout « num « endl; a. 150 b. 155 c. 160 d. 165

b. 155

What is the output of the following C++ code? int x = 35; int y = 45; int z; if (x > y) z = x + y; else z = y - x; cout « x « " " « y « " " « z « endl; a. 35 45 80 b. 35 45 10 c. 35 45 -10 d. 35 45 0

b. 35 45 10

Given the following code, what is the final value of i? int i,j; for(i = 0;i < 4;i ++) { for(j = 0;j < 3;j ++ ) { if(i == 2) break; } } a. 3 b. 4 c. 5 d. 0

b. 4

Given the following enumerated data type definition, what is the value of SAT? enum myType{SUN,MON,TUE,WED,THUR,FRI,SAT,NumDays}; a. 5 b. 6 c. 7 d. 8 e. unknown

b. 6

Which of the following is a relational operator? a = b. == c. ! d. &&

b. ==

Which of the following is not a good reason for choosing a certain loop control? a. What the loop does b. If the loop is in a function c. The condition for ending the loop d. The minimum number of iterations of the loop

b. If the loop is in a function

Suppose that x is an int variable, ch is a char variable, and the input is: 276. Choose the values after the following statement executes:

b. ch = '2', x = 76

Consider the following code. int limit; int counter = 0; cin » limit; while (counter < limit) { cin » entry; triple = entry * 3; cout « triple; counter++; } cout « endl; This code is an example of a(n) __ while loop. a. flag-controlled b. counter-controlled c. BOF-controlled  d. sentinel-controlled

b. counter-controlled

If x is 0, what is the value of (!x == 0)? a. A b. false c. unable to determine d. true

b. false

When a continue statement is executed in a __ ' the update statement always executes. a. while loop b. for loop c. switch structure d. do ... while loop

b. for loop

Which of the following will cause a logical error if you are trying to compare x to 5? a. if (x == 5) b. if (x = 5) c. if (x <= 5) d. if (x >= 5)

b. if (x = 5)

What is wrong with the following for loop? for(int i = 0;i < 10;i -- ) { cout << "Hello\n"; } a. off-by-one error b. infinite loop c. cannot use a for-loop for this d. i is not initialized.

b. infinite loop

What is the output of the following code fragment if x is 15? if(x < 20) if(x < 10) cout << "less than 10 "; else cout << "large\n"; a. nothing b. large c. less than 10 d. no output, syntax error

b. large

To develop a program, you can use an informal mixture of C++ and ordinary language, called __ . a. assert code b. pseudocode c. cppcode d. source code

b. pseudocode

The appearance of = in place of == resembles a(n) __ . a. syntax error b. silent killer c. compilation error d. input failure

b. silent killer

The conditional operator ? : takes __ arguments. a. two b. three c. four d. five

b. three

Suppose x is 5 and y is 7. Choose the value of the following expression: (x ! = 7) & & (x <= y) a. false b. true c. 0 d. null

b. true

Suppose that alpha and beta are int variables. The statement alpha = ++beta; is equivalent to the statement(s) ____.

beta = beta + 1; alpha = beta;

Assume you have the following declaration int beta[50];. Which of the following is a valid element of beta?

beta[0]

class rectangleType{public:void setLengthWidth(double x, double y);//Postcondition: length = x; width = y;void print() const;//Output length and width;double area();//Calculate and return the area of the rectangle;double perimeter();//Calculate and return the parameter;rectangleType();//Postcondition: length = 0; width = 0;rectangleType(double x, double y);//Postcondition: length = x; width = y;private: double length;double width;}; Consider the accompanying class definition, and the object declaration: rectangleType bigRect(14,10);Which of the following statements is correct?

bigRect.setLengthWidth(3.0, 2.0);

Uses true or false values

bool

A ____ statement causes an immediate exit from the switch structure.

break

Which of the following will not increment c by 1

c + 1;.

Which of the following is the "not equal to" relational operator? a. ! b. I c. != d. &

c. !=

Which of the following loops is guaranteed to execute at least once? a. counter-controlled while loop b. for loop c. do ... while loop d. sentinel-controlled while loop

c. do ... while loop

A(n) __ -controlled while loop uses a bool variable to control the loop. a. counter b. sentinel c. flag d. BOF

c. flag

A loop that continues to execute endlessly is called a(n) __ loop. a. end b. unlimited c. infinite d. definite

c. infinite

What does <= mean? a. less than b. greater than c. less than or equal to d. greater than or equal to

c. less than or equal to

When one control statement is located within another, it is said to be __ . a. blocked b. compound c. nested d. closed

c. nested

Which boolean operation is described by the following table? A B Operation True True True True False True False True True False False False a. and b. not c. or d. none of the above

c. or

In a __ control structure, the computer executes particular statements depending on some condition(s). a. looping b. repetition c. selection d. sequence

c. selection

Suppose that x is an int variable and y is a double variable. The input is: ​ 10 20.7 Choose the values after the following statement executes: cin >> x >> y;.

c. x = 10, y = 20.7

Consider the following code. (Assume that all variables are properly declared.) cin » ch; while (cin) { cout « ch; cin » ch; } This code is an example of a(n) __ loop. a. sentinel-controlled b. flag-controlled c.EOF-controlled d. counter-controlled

c.EOF-controlled

The specification of the assert function is found in the header file ____.

cassert

Suppose that x is an int variable, ch is a char variable, and the input is: 276. Choose the values after the following statement executes: cin >> ch >> x;

ch = '2', x = '76'

Suppose that ch1 and ch2 are char variables, and alpha is an int variable. The input is: ​ A 18 ​What are the values after the following statement executes? cin.get(ch1); cin.get(ch2); cin >> alpha;

ch1 = 'A', ch2 = ' ', alpha = 18

Suppose that ch1 and ch2 are char variables, and alpha is an int variable. The input is: ​ A 18 ​ What are the values after the following statement executes? ​ cin.get(ch1); cin.get(ch2); cin >> alpha;

ch1 = 'A', ch2 = ' ', alpha = 18

Which of the following is a reserved word in C++?

char

the get function presented in this chapter only reads values of type _____________

char

Suppose that x and y are int variables. Which of the following is a valid input statement?

cin >> x >> y;

Which of the following class definitions is correct in C++?

class studentType{public:void setData(string, double, int);private:string name;};

initialized

the first time a value is placed in the variable

precision

the maximum number of significant digits

programming

the process of planning and creating a program

walk-through

the process of tracing values through a sequence

statement terminator

the semicolon

token

the smallest individual unit of a program written in any language

simple data type

the variable or named constant of that type can store only one value at a time

What is the output of the following loop? count = 5;cout << 'St';do{cout << 'o';count--;} while (count <= 5);

this is an infinite loop

clockType-hr: int-min: int-sec: int+setTime(int, int, int): void+getTime(int&, int&, int&) const: void+printTime() const: void+incrementSeconds(): int+incrementMinutes(): int+incrementHours(): int+equalTime(const clockType&) const: bool Consider the UML class diagram shown in the accompanying figure. According to the UML class diagram, how many private members are in the class?

three

When C++ evaluates a logical expression, any nonzero value is treated as _____.

true

The operator ! is ____, so it only has one operand.

unary

When only a copy of an argument is passed to a function, it is said to be passed by a ___

value

double precision

values of type double

single precision

values of type float

You can disable assert statements by using which of the following? a. #include b. #define c. #clear NDEBUG d. #define NDEBUG

d. #define NDEBUG

An Integrated Development Environment typically consists of: Select one: a. A text editor b. A compiler c. A debugger d. All of these e. None of these

d. (All of these)

If you need to write a do-while loop that will ask the user to enter a number between 2 and 5 inclusive, and will keep asking until the user enters a correct number, what is the loop condition? a. (number <= 2 && number <= 5) b. (number < 2 && number > 5) c. (2 <= number <= 5) d. (number < 2 || number > 5) e. (2 < 5 < number)

d. (number < 2 || number > 5)

Which of the following symbols has the highest precedence? a. * b. || c. && d. ++

d. ++

What is the output of the following C++ code? num = 10; while (num > 10) num = num - 2; cout « num « endl; a. 0 b. 6 c. 8 d. 10

d. 10

What is the output of the following C++ code? count = 1; num = 25; while (count < 25) { num = num - 1; count++; } cout « count « " " « num « endl; a. 24 0 b. 24 1 c. 25 0 d. 25 1

d. 25 1

What is the value of x after the following statements execute? int x = 5; int y = 30; do x = x * 2; while (x < y); a. 5 b. 10 c. 20 d. 40

d. 40

Which of the following operators has the lowest precedence? a. ! b. II c. && d. =

d. =

What is the output of the following code fragment? { int x = 13; cout << x <<","; } cout << x << endl; a. 13,0 b. 0,13 c. 13,13 d. Nothing, there is a syntax error.

d. Nothing, there is a syntax error.

What is the output of the following loop? count = 5; cout « 'St'; do { cout « '0'; count--; } while (count <= 5); a. St b. Sto c. Stop d. This is an infmite loop.

d. This is an infmite loop.

Which of the following is not a function of the break statement? a. To exit early from a loop b. To skip the remainder of a switch structure c. To eliminate the use of certain bool variables in a loop d. To ignore certain values for variables and continue with the next iteration of a loop

d. To ignore certain values for variables and continue with the next iteration of a loop

Which of the following is a repetition structure in C++? a. if b. switch c. while ... do d. do ... while

d. do ... while

__ loops are called post-test loops. a. break b. for c. while d. do ... while

d. do ... while

Which loop structure always executes at least once? a. while b. sentinel c. for d. do-while

d. do-while

What is the output of the following code? char lastlnitial = 'S'; switch (lastlnitial) { case 'A': cout « "section 1" «endl; break; case 'E': cout « "section 2" «endl; break; case 'C': cout « "section 3" «endl; break; case 'D': cout « "section 4" «endl; break; default: cout « "section 5" «endl; } a. section 2 b. section 3 c. section 4 d. section 5

d. section 5

A function prototype is

declaration, not a definition

Either a function's ___ or its ___ must precede all calls to the function

definition, prototype

loops are called posttest loops.

do while

Which of the following loops is guaranteed to execute at least once?

do while loop

Which of the following is a repetition structure in C++?

do...while

____ loops are called posttest loops.

do...while

Which of the following loops does not have an entry condition?

do...while loop

Which of the following loops is guaranteed to execute at least once?

do...while loop

Which of the following is a repetition structure?

do...while.

An example of a floating point data type is ____.

double

Can go further beyond the decimal point than float, 8 bytes, approx. 15 digits. Very precise # w/ fractional component.

double

How may int variables months, days, and years be defined in one statement, with months initialize to two and years initialized to three?

double months = 2, days, years = 3;

2. How may the double variables temp, weight, and age be defined in one statement?

double temp, weight, age;

How may the double variables temp, weight, and age be defined in one statement?

double temp, weight, age;

Which of the following data types may be used in a switch statement? a. char b. enum c. bool d. int e. all of the above

e. all of the above

Which of the following is a common input device? Select one: a. Keyboard b. Mouse c. Scanner d. Microphone e. All of these

e. (All of these)

C++ provides a header file called ____________________, which is used for file I/O.

fstream

The heading of the function is also called the

function header

A whole number, can be signed or unsigned and associates with long

int

You can use either a(n) ___ variable or a bool variable to store the value of a logical expression.

int

Name the 7 data types in their respective order

int long float double char string bool

The declaration int a, b, c; is equivalent to which of the following?

int a,b,c;

Consider the following declaration: int alpha[5] = {3, 5, 7, 9, 11};. Which of the following is equivalent to this statement?

int alpha[] = {3, 5, 7, 9, 11};

Which of the following function prototypes is valid?

int funcExp(int x, float v){};

3. How may the int variables months, days, and years be defined in one statement, with months initialized to 2 and years initialized to 3?

int months = 2, days, years = 3;

int test(float, char); ​ which of the following statements is valid?

int u = test(5.0, '*');

You can use either a(n) ____ or a ____ to store the value of a logical expression.

int,bool

The value of the expression in a switch statement must be a(n) ____.

integral

A loop ____________________ is a set of statements that remains true each time the loop body is executed.

invariant

Manipulators without parameters are part of the ____ header file.

iostream

When a function uses a mixture of parameters with and without default arguments, the parameters with default arguments must be defined ____

last

What does <= mean?

less than or equal to

If a function has a local variable with the same name as a global, which can only be seen?

local

structures, the computer repeats particular statements a certain number of times depending on some condition(s).

looping

If a function doesn't return a value, the word ___ will appear as it's return type

void

Functions that do not have a return type are called

void functions

implicit type coercion

when a value of one data type is automatically changed to another data type

If x initially contains the value 3, which of the following sets x to 7?

x += 4;.

Suppose that x is an int variable and y is a double variable. The input is: ​ 10 20.7 ​ Choose the values after the following statement executes: cin >> x >> y;.

x = 10, y = 20.7

Suppose that x is an int variable, y is a double variable, and ch is a char variable. The input is: ​ 15A 73.2 ​ Choose the values after the following statement executes: ​ cin >> x >> ch >> y;

x = 15, ch = 'A', y = 73.2

Suppose that x and y are int variables, and z is a double variable. The input is: ​ 28 32.6 12 ​ Choose the values of x, y, and z after the following statement executes: ​ cin >> x >> y >> z;

x = 28, y = 32, z = .6

Assuming that x and y are equal to 3 and 2, respectively, after the statement x -= y executes, the values of x and y will be:

x: 1; y: 2.

Assuming that x is equal to 4, which of the following statements will not result in y containing the value 5 after execution?

y = x++;.

A destructor has the character ____, followed by the name of the class.

~

decrement operator

—; decreases the value of a variable by 1

T/F In a function prototype, the names of the parameter variables may be left out.

True

The memory allocated for a float value is ____ bytes.

four

To develop a program to solve a problem, you start by ____.

A

12. Preprocessor directives begin with a A) # B) ! C) < D) * E) None of the above

#

You can disable assert statements by using the preprocessor directive ____.

#define NDEBUG

You can disable assert statements by using which of the following?

#define NDEBUG

For a program to use the assert function, it must include which of the following?

#include <cassert>

7. Modify the following program so it prints two blank lines between each line of text. #include <iostream> using namespace std; int main() { cout << "Two mandolins like creatures in the"; cout << "dark"; cout << "Creating the agony of ecstasy."; cout << " - George Barker"; return 0; }

#include <iostream> int main() { cout << "Two mandolins like creatures in the\n\n\n"; cout << "dark\n\n\n"; cout << "Creating the agony of ecstasy.\n\n\n"; cout << " - George Barker\n\n\n"; return 0; }

Modify the following program so it prints two blank lines between each line of text. #include <iostream> using namespace std; int main() { cout << "Two mandolins like creatures in the"; cout << "dark"; cout << "Creating the agony of ecstasy."; cout << " -George Barker"; return 0; }

#include <iostream> using namespace std; int main() { cout << "Two mandolins like creatures in the\n"; cout << endl; cout << "dark\n"; cout << endl; cout << "Creating the agony of ecstasy.\n"; cout << endl; cout << " -George Barker"; return 0; }

References are defined like regular variables except there is an ___ in front of the name

&

In C++, the null character is represented as

'/0'

____ is a valid char value.

'A'

Suppose that ch1, ch2, and ch3 are variables of the type char. The input is: ​ A B C ​What is the value of ch3 after the following statements execute? ​cin.get(ch1); cin.get(ch2); cin.get(ch3);

'B'

Suppose that ch1, ch2, and ch3 are variables of the type char. The input is: ​ A B C ​ What is the value of ch3 after the following statements execute? ​ cin.get(ch1); cin.get(ch2); cin.get(ch3);

'B'

Suppose that ch1, ch2, and ch3 are variables of the type char. The input is: ​ A B C ​ Choose the value of ch3 after the following statement executes: ​ cin >> ch1 >> ch2 >> ch3;

'C'

Which of the following expressions evaluates to true?

(14 >= 5) && ('A' < 'B')

Given the input stream variable cin, the expression ____ evaluates to true if the last input succeeded.

(cin)

Suppose that x is an int variable. Which of the following expressions always evaluates to true?

(x > 0) I I (x <= 0)

Testing your program should be done

***a. As each function is developed b. At the end of the coding c. Only if there appear to be problems d. Only if your instructor requires it.

What is wrong with the following switch statement? int ans; cout <<"Type y for yes on n for no\n"; cin >> ans; switch (ans) { case 'y': case 'Y': cout << "You said yes\n"; break; case 'n': case 'N': cout << "You said no\n"; break; default: cout <<"invalid answer\n"; }

***a. ans is an int b. break; is illegal syntax c. nothing d. there are no break statements on 2 cases.

Suppose that x = 25.67, y = 356.876, and z = 7623.9674. What is the output of the following statements? cout << fixed << showpoint; cout << setprecision(2); cout << x << ' ' << y << ' ' << z << endl;

25.67 356.88 7623.97

The value of the expression 17 % 7 is ____.

3

The value of the expression 33/10, assuming both values are integral data types, is ____.

3

Show the punctuation for: x = 3, Display results for 3 as an int, char, and string.

3 '3' "3"

Suppose that alpha, beta, and gamma are int variables and the input is: 100 110 120 200 210 220 300 310 320 What is the value of gamma after the following statements execute? cin >> alpha; cin.ignore(100, '\n'); cin >> beta; cin.ignore(100,'\n'); cin >> gamma;

300

Suppose that alpha, beta, and gamma are int variables and the input is: 100 110 120 200 210 220 300 310 320 What is the value of gamma after the following statements execute? cin >> alpha; cin.ignore(100, '\n'); cin >> beta; cin.ignore(100,'\n'); cin >> gamma;

300

What is the output of the following C++ code? int x = 35;int y = 45;int z;if (x > y)z = x + y;elsez = y - x; cout << x << " " << y << " " << z << endl;

35 45 10

What is the value of x after the following statements execute? int x;x = (5 <= 3 && 'A' < 'F') ? 3 : 4

4

What is the value of x after the following statements execute? int x = 5;int y = 30;dox = x * 2;while (x < y);

40

____ is a valid int value.

46259

int alpha[5];int j;for (j = 0; j < 5; j++)alpha[j] = 2 * j + 1;

5

Suppose that x = 55.68, y = 476.859, and z = 23.8216. What is the output of the following statements? cout << fixed << showpoint; cout << setprecision(3); cout << x << ' ' << y << ' ' << setprecision(2) << z << endl;

55.680 476.859 23.82

The statement: return 37, y, 2 * 3; returns the value

6

What value is returned by the following return statement? int x = 5;return x + 1;

6

Given the following function: int next(int x){return (x + 1);}what is the output of the following statement?cout << next(next(5)) << endl;

7

What is the final value of x after performing the following operations? int x = 21; double y = 6; double z = 14; y = x / z; x = 5.5 * y

8

The output of the statement: cout << pow(2.0, pow(3.0, 1.0)) << endl;

8.0

Assume the following. ​ static_cast<int>('a') = 97 static_cast<int>('A') = 65

98

In C++, the scope resolution operator is ____.

: :

stream insertion operator

<<; takes information from a variable and puts it into a stream

Which of the following is the "less than or equal to" operator in C++?

<=

To use the predefined function tolower, the program must include the header file

<cctype>

The standard header file for the abs(x)function is

<cmath>

Which of the following operators has the lowest precedence?

=

In C++ 11, the ________ tells the compiler to determine the variable's data type from the initialization value. A) auto key word B) #include preprocessor directive C) variable's name D) dynamic_cast key word E) None of the above

A

In programming terms, a group of characters inside a set of quotation marks is called a(n): A) String literal B) Variable C) Operation D) Statement E) None of the above

A

Look at the following function prototype. int myFunction(double); What is the data type of the function's return value? A) int B) double C) void D) Can't tell from the prototype

A

Manipulators without parameters are part of the ____ header file. a. iostream b. iomanip c. ifstream d. pmanip

A

Suppose that ch1 and ch2 are char variables and the input is: WXYZ What is the value of ch2 after the following statements execute? cin.get(ch1); cin.putback(ch1); cin >> ch2; a. W b. X c. Y d. Z

A

Suppose that ch1 and ch2 are char variables, alpha is an int variable, and the input is: A 18 What are the values after the following statement executes? cin.get(ch1); cin.get(ch2); cin >> alpha; a. ch1='A',ch2=' ',alpha=18 b. ch1='A',ch2='1',alpha=8 c. ch1='A',ch2=' ',alpha=1 d. ch1='A',ch2='\n',alpha=1

A

Suppose that x = 55.68, y = 476.859, and z = 23.8216. What is the output of the following statements? cout << fixed << showpoint; cout << setprecision(3); cout << x << ' ' << y << ' ' << setprecision(2) << z << endl; a. 55.680 476.859 23.82 c. 55.680 476.860 23.82 b. 55.690 476.860 23.82 d. 55.680 476.859 23.821

A

Suppose that x and y are int variables, z is a double variable, and the input is: 28 32.6 12 Choose the values of x, y, and z after the following statement executes: cin >> x >> y >> z; a. x=28,y=32,z=0.6 b. x=28,y=32,z=12.0 c. x=28,y=12,z=32.6 d. x=28,y=12,z=0.6

A

Suppose that x is an int variable, y is a double variable and ch is a char variable and the input is: 15A 73.2 Choose the values after the following statement executes: cin >> x >> ch >> y; a. x=15,ch='A',y=73.2 b. x=15,ch='A',y=73.0 c. x=15,ch='a',y=73.0 d. This statement results in an error because there is no space between 15 and A.

A

Suppose that x is an int variable. Which of the following expressions always evaluates to true? a. (x>0)||(x<=0) c. (x>0)&&(x<=0) b. (x>=0)||(x==0) d. (x>0)&&(x==0)

A

The digit 0 or 1 is called a binary digit, or ____. a. bit c. Unicode b. bytecode d. hexcode

A

The do-while loop is a(n) ________ loop that is ideal in situations where you always want the loop to iterate at least once. A) post-test B) pre-test C) infinite D) null-terminated E) None of these

A

The float data type is considered ________ precision, and the double data type is considered ________ precision. A) single, double B) float, double C) integer, double D) short, long E) None of the above

A

The purpose of a memory address is: A) To identify the location of a byte in memory B) To prevent multitasking C) To obtain an algorithm D) To improve the effectiveness of high-level languages E) None of the above

A

The statement: cin >> setw(10) >> str; will read up to this many characters into str. A) Nine B) Ten C) Eleven D) Eight E) None of these

A

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 once B) at least twice C) as many times as the user wishes D) never E) None of these

A

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 that is repeated only if the expression is false C) one line of code that is repeated once, if the expression is true D) a statement or block that is repeated once, if the expression is true

A

These are data items whose values do not change while the program is running. A) Literals B) Variables C) Comments D) Integers E) None of the above

A

This function tells the cin object to skip one or more characters in the keyboard buffer. A) cin.ignore B) cin.jump C) cin.hop D) cin.skip; E) None of the above

A

This is a set of rules that must be followed when constructing a program. A) Syntax B) Punctuation C) Portability D) Operators E) Key words

A

This operator increments the value of its operand, then uses the value in context. A) prefix increment B) postfix increment C) prefix decrement D) postfix decrement E) None of these

A

This statement uses the value of a variable or expression to determine where the program will branch to. A) switch B) select C) associative D) scope E) None of these

A

What is the output of the following C++ code? int x = 55; int y = 5;switch (x % 7) { case 0: case 1: y++; case 2: case 3: y = y + 2; case 4: break; case 5: case 6: y = y - 3; } cout << y << endl; a. 2 b. 5 c. 8 d. 10

A

What is the output of the following code fragment if the input value is 4? int num; int alpha = 10; cin >> num; switch (num) { case 3: alpha++; break; case 4: case 6: alpha = alpha + 3; case 8: alpha = alpha + 4; break; default: alpha = alpha + 5; } cout << alpha << endl; a. 13 b. 14 c. 17 d. 22

A

What is the output of the following code? if (6 > 8) { cout << " ** " << endl ; cout << "****" << endl; } else if (9 == 4) cout << "***" << endl; else cout << "*" << endl; a. * b. ** c. *** d. ****

A

What is the output of the following program? #include <iostream> using namespace std; void doSomething(int); int main() { int x = 2; cout << x << endl; doSomething(x); cout << x << endl; return 0; } void doSomething(int num) { num = 0; cout << num << endl; } A) 2 0 2 B) 2 2 2 C) 0 0 0 D) 2 0 0

A

What is the output of the following statements? cout << "123456789012345678901234567890" << endl cout << setfill('#') << setw(10) << "Mickey" << setfill(' ') << setw(10) << "Donald" << setfill('*') << setw(10) << "Goofy" << endl; a. 123456789012345678901234567890 ####Mickey Donald*****Goofy b. 123456789012345678901234567890 ####Mickey####Donald*****Goofy c. 123456789012345678901234567890 ####Mickey####Donald#####Goofy d. 23456789012345678901234567890 ****Mickey####Donald#####Goofy

A

What is the value of cookies after the execution of the following statements? int number = 38, children = 4, cookies; cookies = number % children; A) 2 B) 0 C) 9 D) .5 E) None of these

A

What is the value of donuts after the following code executes? int donuts = 10; if (donuts != 10) donuts = 0; else donuts += 2; A) 12 B) 10 C) 0 D) 2

A

What is the value of the following expression? false || true A) true B) false C) -1 D) +1

A

What is the value of the following expression? true && true A) true B) false C) -1 D) +1

A

What is the value of the following expression? true || true A) true B) false C) -1 D) +1

A

What will the following code display? cout << "Four\n" << "score\n"; cout << "and" << "\nseven"; cout << "\nyears" << " ago" << endl; A) Four score and seven years ago B) Four score and seven years ago C) Four score and seven years ago D) Four score and seven years ago

A

What will the following code display? int number = 6; cout << number++ << endl; A) 6 B) 5 C) 7 D) 0

A

What will the following code display? int number = 6; int x = 0; x = number--; cout << x << endl; A) 6 B) 5 C) 7 D) 0

A

What will the following code display? int numbers[] = {99, 87, 66, 55, 101 }; cout << numbers[3] << endl; A) 55 B) 66 C) 101 D) 87

A

What will the following program display? #include <iostream> using namespace std; int main() { int a = 0, b = 2, x = 4, y = 0; cout << (a == b) << " "; cout << (a != b) << " "; cout << (b <=x) << " "; cout << (y > a) << endl; return 0; } A) 0 1 1 0 B) 0 0 1 0 C) 1 1 0 1 D) 1 0 0 1 E) None of these

A

What will the following segment of code output if the value 11 is entered at the keyboard? int number; cin >> number; if (number > 0) cout << "C++"; else cout << "Soccer"; cout << " is "; cout << "fun" << endl; A) C++ is fun B) Soccer is fun C) C++ D) C++fun E) Soccerfun

A

What will the value of x be after the following statements execute? int x = 0; int y = 5; int z = 4; x = y + z * 2; A) 13 B) 18 C) 0 D) unknown

A

When a program lets the user know that an invalid choice has been made, this is known as: A) input validation B) output correction C) compiler criticism D) output validation E) None of these

A

When converting some algebraic expressions to C++, you may need to insert ________ that do not appear in the algebraic expression. A) Parentheses B) Exponents C) Calculations D) Coercions E) None of the above

A

When the power is switched off, everything in ____ is lost. a. main memory c. hard disks b. secondary storage d. floppy disks

A

When used as parameters, these types of variables allow a function to access the parameter's original argument. A) reference B) floating-point C) counter D) undeclared E) None of these

A

Which is true about the following statement? cout << setw(4) << num4 << " "; A) It allows four spaces for the value in the variable num4. B) It outputs "setw(4)" before the value in the variable num4. C) It should use setw(10) to output the value in the variable num10. D) It inputs up to four characters stored in the variable num4. E) None of these

A

Which line in the following program contains the prototype for the showDub function? 1 #include <iostream> 2 using namespace std; 3 4 void showDub(int); 5 6 int main() 7 { 8 int x = 2; 9 10 showDub(x); 11 cout << x << endl; 12 return 0; 13 } 14 15 void showDub(int num) 16 { 17 cout << (num * 2) << endl; 18 } A) 4 B) 6 C) 10 D) 15

A

Which line in the following program will cause a compiler error? 1 #include <iostream> 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) 6 B) 8 C) 9 D) 7

A

Which of the following is not one of the five major components of a computer system? A) Preprocessor B) The CPU (central processing unit) C) Main memory D) Input/Output device E) Secondary storage device

A

The while loop is this type of loop. A) post-test B) pre-test C) infinite D) limited E) None of these

B

flag

A(n) ____-controlled while loop uses a bool variable to control the loop.

What will the following programs print on the screen? A) #include <iostream> using namespace std; int main() { int freeze = 32, boil = 212; freeze = 0 boil = 100 cout << freeze << endl << boil << endl; return 0; } B) #include <iostream> using namespace std; int main() { int x = 0, y = 2; x = y * 4; cout << x << endl << y << endl; return 0; } C) #include <iostream> using namespace std; int main() { cout << "I am the incredible"; cout << "computing\nmachine"; cout << "\nand I will\namaze\n"; cout << "you."; return 0; } D) #include <iostream> using namespace std; int main() { cout << "Be careful\n"; cout << "This might \n be a trick "; cout << "Question\n; return 0; } E) #include <iostream> using namespace std; int main() { int a, x = 23; a = x % 2; cout << x << endl << a << endl; return 0; }

A) 0 100 B) 8 2 C) I am the incredible computing machine and I will amaze you. D) Be careful This might be a trick Question E) 23 1

Preprocessor directives begin with a A) # B) ! C) < D) * E) None of the above

A) #

8. What will the following programs print on the screen? A) #include <iostream> using namespace std; int main() { int freeze = 32, boil = 212; freeze = 0; boil = 100; cout << freeze << endl << boil << endl; return 0; } B) #include <iostream> using namespace std; int main() { int x = 0, y = 2; x = y * 4; cout << x << endl << y << endl; return 0; } C) #include <iostream> using namespace std; int main() { cout << "I am the incredible"; cout << "computing machine"; cout << " and I will amaze "; cout << "you."; return 0; } D) #include <iostream> using namespace std; int main() { cout << "Be careful "; cout << "This might/n be a trick "; cout << "question "; return 0; } E) #include <iostream> using namespace std; int main() { int a, x = 23; a = x % 2; cout << x << endl << a << endl; return 0; }

A) 0, 100 B) 8, 2 C) : I am the incrediblecomputing machine and I will amaze you. D): Be careful This might/n be a trick question E) 23, 1

17. Assume w = 5, x = 4, y = 8, and z = 2. What value will be stored in result in each of the following statements? A) result = x + y; B) result = z * 2; C) result = y / x; D) result = y − z; E) result = w % 2;

A) 12 B) 4 C) 2 D) 6 E) 1

Assume w = 5, x = 4, y = 8, and z = 2. What value will be stored in result in each of the following statements? A) result = x + y; B) result = z * 2; C) result = y / x; D) result = y - z; E) result = w % 2;

A) 12 B) 4 C) 2 D) 6 E) 1

18. How would each of the following numbers be represented in E notation? A) 3.287 × 10 6 B) −978.65 × 10 12 C) 7.65491 × 10 −3 D) −58710.23 × 10 −4

A) 3.287E6 B) -9.7865E14 C) 7.65491E-3 D) -5.871023E0

How would each of the following numbers be represented in E notation? A) 3.287 x 10^6 B) -978.65 x 10^12 C) 7.65491 x 10^-3 D) -58710.23 x 10^-4

A) 3287000 B) -978650000000000 C) .00765491 D) -5.871023

When do preprocessor directive execute? A) Before the compiler compiles your program B) After the compiler compiles your program C) A the same time your compiler compiles your program D) None of the above

A) Before the compiler compiles your program

A group of statements, such as the contents of a function, is enclosed in A) Braces {} B) Parentheses () C) Brackets <> D) All of the above will do

A) Braces {}

14. A group of statements, such as the contents of a function, is enclosed in A) Braces {} B) Parentheses () C) Brackets <> D) All of the above will do

A) Braces {} Note: ( ) are used in naming a function, as in int main()

The negation operator is A) Unary B) Binary C) Ternary D) None of the above

A) Unary

The following data 72 'A' "Hello World" 2.8712 are all examples of A) Variables B) Literals or constants C) Strings D) None of the above

A) Variables

4. Write assignment statements that perform the following operations with the variables a, b, and c. A) Adds 2 to a and stores the result in b . B) Multiplies b times 4 and stores the result in a . C) Divides a by 3.14 and stores the result in b . D) Subtracts 8 from b and stores the result in a . E) Stores the value 27 in a. F) Stores the character 'K' in c . G) Stores the ASCII code for 'B' in c .

A) b = a + 2; B) a = b * 4; C) b = a / 3.14; D) a = b - 8; E) a = 27; F) c = 'K'; G) c = 'B'

Write assignment statements that perform the following operations with the variables a, b and c. A) Adds 2 to a and stores the result in b. B) Multiplies b times 4 and stores the result in a. C) Divides a by 3.14 and stores the result in b. D) Subtracts 8 from b and stores the result in a. E) Stores the value 27 in a. F) Stores the character 'K' in c. G) Stores the ASCII code for 'B' in c.

A) b = a + 2; B) a = b * 4; C) b = a / 3.14; D) a = b - 8; E) a = 27; F) c = 'K'; G) c = 66;

12 4 2 6 1

Assume w=5, x=4, y=8, and z=2. What value will be stored in result in each of the following statements? [result = x+y; [result = z*2; [result = y/x; [result = y-z; [result = w%2

Suppose that x = 55.68, y = 476.859, and z = 23.8216. What is the output of the following statements? cout << fixed << showpoint; cout << setprecision(3); cout<<x<<''<<y<<''<<setprecision(2)<<z<<endl; A. 55.680 476.859 23.82 B. 55.690 476.860 23.82 C. 55.680 476.860 23.82 D. 55.680 476.859 23.821

A. 55.680 476.859 23.82

Suppose that x and y are int variables, and z is a double variable. The input is: ​ 28 32.6 12 ​Choose the values of x, y, and z after the following statement executes: ​cin >> x >> y >> z; A. x=28,y=32,z=0.6 B. x=28,y=32,z=12.0 C. x=28,y=12,z=32.6 D. x=28,y=12,z=0.6

A. x = 28, y = 32, z = 0.6

What does ADT stand for?

Abstract Data Type

What is the difference between an argument and a parameter variable?

An argument is a value passed to a function. A parameter variable is a variable local to the function which receives the argument. That is to say, the argument's value is copied into the parameter variable.

A fatal logic error can be caused by:

An attempt to divide by zero

How many times will the following loop print hello? i = 1; while ( i <= 10 ) cout << "hello";

An infinite number of times.

Using a loop's counter-control variable in a calculation after the loop ends often causes a common logic error called:

An off-by-one error

Which of the following best describes an operator?

An operator allows you to perform operations on one or more pieces of data.

True

Assume all variables are properly declared. The output of the following C++ code is 2 3 4 5. n = 1;while (n < 5){n++;cout << n << " ";}

False

Assume that all variables are properly declared. The following for loop executes 20 times.for (i = 0; i <= 20; i++)cout << i;

Here is the header for a function named computeValue: void computeValue(int value) Which of the following is a valid call to the function? A) computeValue(10) B) computeValue(10); C) void computeValue(10); D) void computeValue(int x);

B

How many times will the following loop display "Hello"? for (int i = 1; i < 20; i++) cout << "Hello!" << endl; A) 20 B) 19 C) 21 D) An infinite number of times

B

If a function does not have a prototype, default arguments may be specified in the function ________. A) call B) header C) execution D) return type E) None of these

B

If you place a semicolon after the statement: if (x < y) A) The code will not compile. B) The compiler will interpret the semicolon as a null statement. C) The if statement will always evaluate to false. D) All of the above E) None of these

B

If you use a C++ key word as an identifier, your program will: A) Execute with unpredictable results B) not compile C) understand the difference and run without problems D) Compile, link, but not execute E) None of the above

B

If you want a user to enter exactly 20 values, which loop would be the best to use? A) do-while B) for C) while D) infinite E) None of these

B

In C++ the = operator indicates: A) equality B) assignment C) subtraction D) negation E) None of these

B

In C++, the dot is an operator called the ____ operator. a. dot access c. data access b. member access d. member

B

In a C++ program, two slash marks ( // ) indicate: A) The end of a statement B) The beginning of a comment C) The end of the program D) The beginning of a block of code E) None of the above

B

In any program that uses the cin object, you must include the ________. A) compiler B) iostream header file C) linker D) >> and << operators E) None of the above

B

In the following C++ statement, what will be executed first according to the order of precedence? result = 6 - 3 * 2 + 7 - 10 / 2 ; A) 6 - 3 B) 3 * 2 C) 2 + 7 D) 7 - 10 E) 10 / 2

B

It is a good programming practice to ________ your functions by writing comments that describe what they do. A) execute B) document C) eliminate D) prototype E) None of these

B

Look at the following function prototype. int myFunction(double); What is the data type of the function's parameter variable? A) int B) double C) void D) Can't tell from the prototype

B

Look at the following statement. while (x++ < 10) Which operator is used first? A) ++ B) < C) Neither. The expression is invalid.

B

Main memory is called ____. a. read only memory c. read and write memory b. random access memory d. random read only memory

B

Mistakes that cause a running program to produce incorrect results are called: A) Syntax errors B) Logic errors C) Compiler errors D) Linker errors E) None of the above

B

Programmer-defined names of memory locations that may hold data are: A) Operators B) Variables C) Syntax D) Operands E) None of the above

B

Something within a while loop must eventually cause the condition to become false, or a(n) ________ results. A) null value B) infinite loop C) unexpected exit D) compiler error E) None of these

B

Suppose that ch1 and ch2 are char variables and the input is: WXYZ What is the value of ch2 after the following statements execute? cin >> ch1; ch2 = cin.peek(); cin >> ch2; a. W b. X c. Y d. Z

B

Suppose that ch1, ch2, and ch3 are variables of the type char and the input is: A B C What is the value of ch3 after the following statements execute?cin.get(ch1); cin.get(ch2); cin.get(ch3); a. 'A' b. 'B' c. 'C' d. '\n'

B

Suppose that outFile is an ofstream variable and output is to be stored in the file outputData.out. Which of the following statements opens the file outputData.out and associates outFile to the output file? a. outFile("outputData.out"); b.outFile.open("outputData.out"); c.open(outFile,"outputData.out"); d.open.outFile("outputData.out");

B

Suppose that x and y are int variables. Which of the following is a valid input statement? a. cin>>x>>cin>>y; c. cin<<x<<y; b. cin>>x>>y; d. cout<<x<<y;

B

Suppose that x is an int variable, ch is a char variable, and the input is: 276. Choose the values after the following statement executes: cin >> ch >> x; a. ch='2',x=276 c. ch='',x=276 b. ch='276',x='.' d. ch='b',x=76

B

Suppose x is 5 and y is 7. Choose the value of the following expression: (x!=7)&&(x<=y) a. false b. true c. 0 d. null

B

What will the following loop display? int x = 0; while (x < 5) { cout << x << endl; x++; } A) 0 1 2 3 4 5 B) 0 1 2 3 4 C) 01 2 3 4 D) The loop will display numbers starting at 0, for infinity.

B

What will the value of x be after the following statements execute? int x; x = 18 / 4; A) 4.5 B) 4 C) 0 D) unknown

B

What will the value of x be after the following statements execute? int x; x = 18.0 / 4; A) 4.5 B) 4 C) 0 D) unknown

B

When a relational expression is false, it has the value ________. A) one B) zero C) zero, one, or minus one D) less than zero E) None of these

B

When a variable is assigned a number that is too large for its data type, it: A) underflows B) overflows C) reverses polarity D) exceeds expectations E) None of the above

B

When the increment operator precedes its operand, as in ++num1, the expression is in this mode. A) postfix B) prefix C) preliminary D) binary E) None of these

B

When using the sqrt function you must include this header file. A) cstdlib B) cmath C) cstring D) iostream E) iomanip

B

Which line in the following program will cause a compiler error? 1 #include <iostream> 2 using namespace std; 3 4 int main() 5 { 6 int number = 5; 7 8 if (number >= 0 && <= 100) 9 cout << "passed.\n"; 10 else 11 cout << "failed.\n"; 12 return 0; 13 } A) 6 B) 8 C) 10 D) 9

B

Which of the following best describes an operator? A) An operator is a rule that must be followed when constructing a program. B) An operator allows you to perform operations on one or more pieces of data. C) An operator marks the beginning or ending of a statement, or is used to separate items in a list. D) An operator is a word that has a special meaning. E) An operator is a symbolic name that refers to a variable.

B

Which of the following defines a double-precision floating point variable named payCheck? A) float payCheck; B) double payCheck; C) payCheck double; D) Double payCheck;

B

Which of the following is a legal identifier? a. program! c. 1program b. program_1 d. program 1

B

Which of the following is a relational operator? a. = b. == c. ! d. &&

B

Which of the following will cause a logical error if you are attempting to compare x to 5? a. if(x==5) c. if(x<=5) b. if(x=5) d. if(x>=5)

B

Which one of the following would be an illegal variable name? A) dayOfWeek B) 3dGraph C) _employee_num D) June1997 E) itemsorderedforthemonth

B

Which statement is equivalent to the following? x = x * 2; A) x * 2; B) x *= 2; C) x = x * x; D) None of these

B

You can use these to override the rules of operator precedence in a mathematical expression. A) [Brackets] B) (Parentheses) C) {Braces} D) The escape character \ E) None of these

B

You must have a ________ for every variable you intend to use in a program. A) purpose B) definition C) comment D) constant E) None of the above

B

You want the user to enter the length, width, and height from the keyboard. Which cin statement is correctly written? A) cin << length, width, height; B) cin.get(length, width, height); C) cin >> length >> width >> height; D) cin >> length, width, height; E) cin << length; width; height;

B

________ functions may have the same name, as long as their parameter lists are different. A) Only two B) Two or more C) Zero D) Un-prototyped E) None of these

B

________ must be included in any program that uses the cout object. A) Opening and closing braces B) The header file iostream C) Comments D) Escape sequences E) None of the above

B

________ reads a line of input, including leading and embedded spaces, and stores it in a string object. A) cin.get B) getline C) cin.getline D) get E) None of these

B

________ represent storage locations in the computer's memory. A) Literals B) Variables C) Comments D) Integers E) None of the above

B

Which of the following are NOT valid assignment statements? (all that apply) A) total = 9; B) 72 = amount; C) profit = 129; D) letter = 'W';

B) 72 = amount;

Which of the following are NOT valid cout statements? A) cout << "Hello World"; B) cout << "Have a nice day"\n; C) cout < value; D) cout << programming is great fun;

B) cout << "Have a nice day"\n; C) cout < value; D) cout << programming is great fun;

15. Which of the following are not valid assignment statements? (Circle all that apply.) A) total = 9; B) 72 = amount; C) profit = 129 D) letter = 'W';

B, C

T/F Functions should be given names that reflect their purpose.

True

Assuming x is 5, y is 6, and z is 8, which of the following is false? 1. x == 5; 2. 7 <= (x + 2); 3. z < = 4; 4. (1 + x) != y; 5. z >= 8; 6. x >= 0; 7. x <= (y * 2) A) 3, 4, 6, 7 are false. B) Only 5 is false. C) 3 and 4 are false. D) All are false. E) None of these.

C

Assuming you are using a system with 1-byte characters, how many bytes of memory will the following string literal occupy? "William" A) 7 B) 14 C) 8 D) 1

C

Character constants in C++ are always enclosed in ________. A) [brackets] B) "double quotation marks" C) 'single quotation marks' D) {braces} E) (parentheses)

C

Characters or symbols that perform operations on one or more operands are: A) Syntax B) Op codes C) Operators D) Program ops E) None of the above

C

Choose the output of the following C++ statement: cout << "Sunny " << '\n' << "Day " << endl; a. Sunny \nDay b. Sunny \nDay endl c. Sunny Day d. Sunny \n Day

C

Computer programs are also known as: A) hardware B) firmware C) software D) silverware E) None of the above

C

Dividing a problem into smaller subproblems is called ____ design.

C

How many times will the following loop display "Hello"? for (int i = 0; i <= 20; i++) cout << "Hello!" << endl; A) 20 B) 19 C) 21 D) An infinite number of times

C

If you place a semicolon after the test expression in a while loop, it is assumed to be a(n): A) pre-test loop B) post-test loop C) null statement D) infinite loop E) None of these

C

In a ______ control structure, the computer executes particular statements depending on some condition(s). a. looping b. repetition c. selection d. sequence

C

In a broad sense, the two primary categories of programming languages are: A) Mainframe and PC B) Hardware and Software C) Low-level and High-level D) COBOL and BASIC E) None of the above

C

In a for statement, this expression is executed only once. A) test B) null C) initialization D) validation E) None of these

C

In memory, C++ automatically places a ________ at the end of string literals. A) Semicolon B) Quotation marks C) Null terminator D) Newline escape sequence E) None of the above

C

Internally, the CPU consists of two parts: A) The Output Device and the Input Device B) The Software and the Hardware C) The Control Unit and the Arithmetic and Logic Unit D) The Single-task Device and the Multi-task Device E) None of the above

C

Look at the following function prototype. int myFunction(double, double, double); How many parameter variables does this function have? A) 1 B) 2 C) 3 D) Can't tell from the prototype

C

Look at the following program and answer the question that follows it. 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 } Which line(s) in this program cause output to be displayed on the screen? A) 13 and 14 B) 8 and 9 C) 14 D) 13 E) 15

C

Main memory is an ordered sequence of items, called ____. a. pixels c. memory cells b. registers d. addresses

C

Relational operators allow you to ________ numbers. A) add B) multiply C) compare D) average E) None of these

C

Suppose that alpha is an int variable and ch is a char variable and the input is: 17 A What are the values after the following statements execute? cin >> alpha; cin >> ch; a. alpha=17,ch=' ' b. alpha=1,ch=7 c. alpha=17,ch='A' d. alpha=17,ch='a'

C

Suppose that alpha, beta, and gamma are int variables and the input is: 100 110 120 200 210 220 300 310 320 What is the value of gamma after the following statements execute? cin >> alpha; cin.ignore(100, '\n'); cin >> beta; cin.ignore(100,'\n'); cin >> gamma; a. 100 b. 200 c. 300 d. 320

C

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 << "This is all folks!" << endl; A) This is true! B) This is false! C) This is true! This is false! D) This is true! This is all folks! E) None of these

D

A ________ argument is passed to a parameter when the actual argument is left out of the function call. A) false B) true C) null D) default E) None of these

D

A character literal is enclosed in ________ quotation marks, whereas a string literal is enclosed in ________ quotation marks. A) double, single B) triple, double C) open, closed D) single, double E) None of the above

D

A function is executed when it is: A) defined B) prototyped C) declared D) called E) None of these

D

A loop that is inside another loop is called: A) an infinite loop B) a pre-test loop C) a post-test loop D) a nested loop E) None of these

D

A(n) ____ consists of data and the operations on those data.

D

An Integrated Development Environment typically consists of: A) A text editor B) A compiler C) A debugger D) All of the above E) None of the above

D

An example of a secondary storage device is: A) The computer's main memory B) The keyboard C) The monitor D) The disk drive E) None of the above

D

Assume that x is an int variable. What value is assigned to x after the following assignment statement is executed? x = -3 + 4 % 6 / 5; A) 0 B) 1 C) 2 D) —3 E) None of these

D

At the heart of a computer is its central processing unit. The CPU's job is: A) To fetch instructions B) To carry out the operations commanded by the instructions C) To produce some outcome or resultant information D) All of the above E) None of the above

D

For every opening brace in a C++ program, there must be a: A) String literal B) Function C) Variable D) Closing brace E) None of the above

D

Given the following code segment, what is output after "result = "? int x = 1, y = 1, z = 1; y = y + z; x = x + y; cout << "result = " << (x < y ? y : x) << endl; A) 0 B) 1 C) 2 D) 3 E) None of these

D

If you intend to place a block of statements within an if statement, you must place these around the block. A) Parentheses ( ) B) Square brackets [ ] C) Angle brackets < > D) Curly braces { } E) None of these

D

In C++ 11, if you want an integer literal to be treated as a long long int, you can append ________ at the end of the number. A) L B) <INT> C) I D) LL E) None of the above

D

In the process of translating a source file into an executable file, which of the following is the correct sequence? A) Source code, preprocessor, modified source code, linker, object code, compiler, executable code. B) Preprocessor, source code, compiler, executable code, linker, modified source code, object code. C) Source code, compiler, modified source code, preprocessor, object code, linker, executable code. D) Source code, preprocessor, modified source code, compiler, object code, linker, executable code. E) Source code, linker, object code, compiler, modified source code, preprocessor, executable code.

D

Input values should always be checked for: A) Appropriate range B) Reasonableness C) Division by zero, if division is taking place D) All of these E) None of these

D

Several categories of computers exist, such as ____. a. microframe, midframe, and miniframe b. midsize, microframe, and mainframe c. mainsize, midsize, and microsize d. mainframe, midsize, and micro

D

Subscript numbering in C++________. A) can be set at runtime B) can begin with a programmer-defined value C) varies from program to program D) begins with zero E) None of these

D

Suppose that x and y are int variables, ch is a char variable, and the input is: 4 2 A 12 Choose the values of x, y, and ch after the following statement executes: cin >> x >> ch >> y; a. x=4,ch=2,y=12 c. x=4,ch='',y=2 b. x = 4, ch = A, y = 12 d. This statement results in input failure

D

1 2 3

How many operands does each of the following types of operators require? [Unary [Binary [Ternary

One operand is required for unary operator. Two operands are required for binary operator. Three operands are required for ternary operator. Examples: Unary operator ! represents logical not operator. If a=false, then !a=true. Notice that the operator ! takes one argument (one operand). Operator + is a binary operator. It takes two operands and result is their sum. Operator ?: is ternary operator. It is used as follows: a ? b : c It is interpreted as: "If a is true, then execute b and if a is false, then execute c".

How many operands does each of the following types of operators require? ______ Unary ______ Binary ______ Ternary

To define more than one variable in one statement we use comma to separate the variables. As such, to define double variables we use following statement: double temp, weight, age; Use semicolon to indicate end of the statement.

How may the double variables temp , weight , and age be defined in one statement?

To define more than one variable in one statement we use comma to separate the variables. To initialize the variable to some value use = operator. As such, to define int variables we use following statement: int months = 2, days, years = 3; Use semicolon to indicate end of the statement.

How may the int variables months , days , and years be defined in one statement, with months initialized to 2 and years initialized to 3?

int months = 2, days, years = 3;

How may the int variables months, days, and years be defined in one statement, with months initialized to 2 and years initialized to 3?

A name you give a variable

Identifier

b

If input failure occurs in a C++ program, the program terminates immediately and displays an error message. a. True b. False

If you are writing a function that accepts an argument and you want to make sure the function cannot change the value of the argument, what do you do?

If the argument is passed by value, nothing needs to be done. The function cannot access the argument. If the argument is passed by reference, the parameter should be defined with the const key word.

When you want to process only partial data, you can use the stream function ____ to discard a portion of the input.

Ignore

Which operation does not take place in the following example?

Implicit conversion.

c

In C++, the dot is an operator called the ____ operator. a. member b. dot access c. member access d. data access

looping

In ____ structures, the computer repeats particular statements a certain number of times depending on some condition(s).

true

In the case of the sentinel-controlled while loop, the first item is read before the while loop is entered.

b

In the statement cin >> x;, x can be a variable or an expression. a. True b. False

Where do you define parameter variables?

Inside the parentheses of a function header.

To use the manipulators setprecision, setw, and setfill, the program must include the header file ________.

Iomanip

A block:

Is a compound statement

Comment is written using multi-line comment symbols. Symbol /* represents the start of the paragraph we are about to put in comment and symbol */ represents the end of the commented paragraph.

Is the following comment written using single-line or multi-line comment symbols? /* This program was written by M. A. Codewriter*/

Comment is written using the single-line comment symbols. Symbol // represents the start of the comment. Everything in line that is written after // symbol is a part of the comment.

Is the following comment written using single-line or multi-line comment symbols? // This program was written by M. A. Codewriter

The conditional operator (?:):

Is the only ternary operator in C++.

b

It is a good idea to redefine cin and cout in your programs. a. True b. False

What is the advantage of breaking your application's code into several small procedures?

It makes the program easier to manage. Real-world programs can easily have thousands of lines of code, and unless they are modularized, they can be very difficult to modify and maintain.

How would a static local variable be useful?

It would enable a function to retain a value between function calls. For example, it can keep track of the number of times the function has been called.

The code compiles fine and runs, but the output is flawed

Logic error

_____ operators enable you to combine logical expressions.

Logical

In a broad sense, the two primary categories of programming languages are:

Low-level and high-level

c

Manipulators without parameters are part of the ____ header file. a. iomanip b. pmanip c. iostream d. ifstream

T/F If other functions are defined before the main, the program still starts executing at the main function.

True

Start with compiling and running written example. As you can see, different parts of text are simply stacked one after another. There is no space between them. To modify it, we are going to use command \n which indicates new line. We want two blank rows between each part of text so we have to add three new line commands to the end of each part of the text - it is equivalent of pressing "Enter" key three times when writing something in notepad. int main() { cout << "Two mandolins like creatures in the\n\n\n"; cout << "dark\n\n\n"; cout << "Creating the agony of ecstasy.\n\n\n"; cout << " - George Barker"; return 0; } We don't need to add new line commands after the last line is printed out. Try to compile and run the program. Another way of solving this problem is to use endl command. Using this command, first line would look like this: cout << "Two mandolins like creatures in the" << endl << endl << endl;

Modify the following program so it prints two blank lines between each line of text. #include <iostream> using namespace std; int main() { cout << "Two mandolins like creatures in the"; cout << "dark"; cout << "Creating the agony of ecstasy."; cout << " - George Barker"; return 0; }

#include<iostream> using namespace std; int main() { cout<<"Two mandolins like creatures in the\n\n\n"; cout<<"dark\n\n\n"; cout<<"Creating the agony of ecstasy.\n\n\n"; cout<<" - George Barker\n\n\n"; return 0; }

Modify the following program so it prints two pblank lines between each line of text. #include<iostream> using namespace std; int main() { cout<<"Two mandolins like creatures in the"; cout<<"dark"; cout<<"Creating the agony of ecstasy."; cout<<" - George Barker"; return 0; }

Is the following comments written using single-line or multi-line comment symbols? / * This program was written by M. A. Codewriter * /

Multi-Line

5. Is the following comment written using single-line or multi-line comment symbols? /* This program was written by M. A. Codewriter*/

Multi-line comment

When one control statement is located within another, it is said to be

Nested

Having a loop within a loop is known as:

Nesting

If grade has the value of 60, what will the following code print? If ( grade >= 60 ) Cout << "Passed";

Passed

Which of the following operations has the highest precedence?

Postincrement

Which of the following is not one of the five major components of a computer system?

Preprocessor

Which statement below about prototypes and headers is true?

Prototypes end with a semicolon, but headers do not.

The computer's main memory is commonly known as:

RAM

_______ local variables retain their value between function calls

Static

Choose the output of the following C++ statement: cout << "Sunny " << '\n' << "Day " << endl;

Sunny Day

125

Suppose j, sum, and num are int variables, and the input is 26 34 61 4 -1. What is the output of the code?sum = 0;cin >> num;for (int j = 1; j <= 4; j++){sum = sum + num;cin >> num;}cout << sum << endl;

d

Suppose that alpha is an int variable and ch is a char variable and the input is: 17 A What are the values after the following statements execute? cin >> alpha; cin >> ch; a. alpha = 17, ch = ' ' b. alpha = 1, ch = 7 c. alpha = 17, ch = 'a' d. alpha = 17, ch = 'A'

c

Suppose that alpha, beta, and gamma are int variables and the input is: 100 110 120 200 210 220 300 310 320 What is the value of gamma after the following statements execute? cin >> alpha; cin.ignore(100, '\n'); cin >> beta; cin.ignore(100,'\n'); cin >> gamma; a. 100 b. 200 c. 300 d. 320

a

Suppose that ch1 and ch2 are char variables and the input is: WXYZ What is the value of ch2 after the following statements execute? cin.get(ch1); cin.putback(ch1); cin >> ch2; a. W b. X c. Y d. Z

b

Suppose that ch1 and ch2 are char variables, alpha is an int variable, and the input is: A 18 What are the values after the following statement executes? cin.get(ch1); cin.get(ch2); cin >> alpha; a. ch1 = 'A', ch2 = ' ', alpha = 1 b. ch1 = 'A', ch2 = ' ', alpha = 18 c. ch1 = 'A', ch2 = '1', alpha = 8 d. ch1 = 'A', ch2 = '\n', alpha = 1

b

Suppose that ch1, ch2, and ch3 are variables of the type char and the input is: A B C What is the value of ch3 after the following statements execute? cin.get(ch1); cin.get(ch2); cin.get(ch3); a. 'A' b. 'B' c. 'C' d. '\n'

b

Suppose that outFile is an ofstream variable and output is to be stored in the file outputData.out. Which of the following statements opens the file outputData.out and associates outFile to the output file? a. open.outFile("outputData.out"); b. outFile.open("outputData.out"); c. open(outFile,"outputData.out"); d. outFile("outputData.out");

d

Suppose that x = 1565.683, y = 85.78, and z = 123.982. What is the output of the following statements? cout << fixed << showpoint; cout << setprecision(3) << x << ' '; cout << setprecision(4) << y << ' ' << setprecision(2) << z << endl; a. 1565.683 85.780 123.980 b. 1565.680 85.8000 123.98 c. 1565.683 85.8000 123.98 d. 1565.683 85.7800 123.98

a

Suppose that x = 55.68, y = 476.859, and z = 23.8216. What is the output of the following statements? cout << fixed << showpoint; cout << setprecision(3); cout << x << ' ' << y << ' ' << setprecision(2) << z << endl; a. 55.680 476.859 23.82 b. 55.680 476.859 23.821 c. 55.690 476.860 23.82 d. 55.680 476.860 23.82

d

Suppose that x and y are int variables, ch is a char variable, and the input is: 4 2 A 12 Choose the values of x, y, and ch after the following statement executes: cin >> x >> ch >> y; a. x = 4, ch = 2, y = 12 b. x = 4, ch = A, y = 12 c. x = 4, ch = ' ', y = 2 d. This statement results in input failure

d

Suppose that x and y are int variables, z is a double variable, and the input is: 28 32.6 12 Choose the values of x, y, and z after the following statement executes: cin >> x >> y >> z; a. x = 28, y = 32, z = 12.0 b. x = 28, y = 12, z = 0.6 c. x = 28, y = 12, z = 32.6 d. x = 28, y = 32, z = 0.6

c

Suppose that x and y are int variables. Which of the following is a valid input statement? a. cin << x << y; b. cin >> x >> cin >> y; c. cin >> x >> y; d. cout << x << y;

c

Suppose that x is an int variable and y is a double variable and the input is: 10 20.7 Choose the values after the following statement executes: cin >> x >> y; .a. x = 10, y = 20 b. x = 10, y = 20.0 c. x = 10, y = 20.7 d. x = 10, y = 21.0

d

Suppose that x is an int variable, ch is a char variable, and the input is: 276. Choose the values after the following statement executes: cin >> ch >> x; a. ch = ' ', x = 276 b. ch = 'b', x = 76 c. ch = '276', x = '.' d. ch = '2', x = 76

a

Suppose that x is an int variable, y is a double variable and ch is a char variable and the input is: 15A 73.2 Choose the values after the following statement executes: cin >> x >> ch >> y; a. x = 15, ch = 'A', y = 73.2 b. x = 15, ch = 'A', y = 73.0 c. x = 15, ch = 'a', y = 73.0 d. This statement results in an error because there is no space between 15 and A.

d

Suppose that x is an int variable, y is a double variable, z is an int variable, and the input is: 15 76.3 14 Choose the values after the following statement executes: cin >> x >> y >> z; a. x = 15, y = 76, z = 14 b. x = 15.0, y = 76.3, z = 14.0 c. x = 15, y = 76, z = 0 d. x = 15, y = 76.3, z = 14

An uninitialized local variable contains:

The value last stored in the memory location reserved for that variable.

Which of the following is true of a pseudocode program?

They help the programmer "think out" a program.

Suppose that x and y are int variables, ch is a char variable, and the input is: 4 2 A 12 Choose the values of x, y, and ch after the following statement executes: cin >> x >> ch >> y;

This statement results in input failure

At the heart of a computer is its central processing unit. The CPU's job is:

To carry out the operations by the instructions, to produce some outcome or resultant information, and to fetch instructions

A CPU really only understands instructions that are written in machine language.

True

Assume all variables are properly declared. The output of the following C++ code is 2 3 4 5. n = 1; while (n < 5) { n++; cout << n << " "; }

True

Entering a char value into an int variable causes serious errors, called input failure. (T/F)

True

In a counter-controlled while loop, the loop control variable must be initialized before the loop.

True

In the case of the sentinel-controlled while loop, the first item is read before the while loop is entered.

True

T/F A left brace in a C++ program should always be followed by a right brace later in the program.

True

T/F A variable must be defined before it can be used.

True

T/F Variable names may be up to 31 characters long.

True

T/F A stub is a dummy function that is called instead of the actual function it represents.

True

T/F Arguments are passed to the function parameters in the order they appear in the function call.

True

T/F Function prototypes are terminated with a semicolon.

True

What is the output of the following code fragment if the input value is 4? int num; int alpha = 10; cin » num; switch (num) { case 3: alpha++; break; case 4: case 6: alpha = alpha + 3;case 8: alpha = alpha + 4; break; default: alpha = alpha + 5; } cout « alpha « endl; a. 13 b. 14 c. 17 d. 22

a. 13

What is the output of the following code fragment? int x=0; { int x=13; cout << x <<","; } cout << x << endl;

a. 13,13 b. 0,13 ***c. 13,0 d. nothing, there is a syntax error.

Assume you have three int variables: x = 2, Y = 6 , and z. Choose the value of z in the following expression: z = ( y / x > 0) ? x : y; a. 2 b. 3 c. 4 d. 6

a. 2

What is the output of the following C++ code? int x = 55; int y = 5; switch (x % 7) { case 0: case 1: y++; case 2: case 3: y = y + 2; case 4: break; case 5: case 6: y = y - 3; } cout « y « endl; a. 2 b. 5 c. 8 d. 10

a. 2

What is the value of x after the following statements? double x; x = 0; x += 3.0 * 4.0; x -= 2.0;

a. 22.0 b. 12.0 ***c. 10.0 d. 14.0

Suppose sum, num, and j are int variables, and the input is 4 7 12 9 -1. What is the output of the following code? cin » sum; cin » num; for (j = 1; j <= 3; j++) { cin » num; sum = sum + num; } cout « sum « endl; a. 24 b. 25 c. 41 d. 42

a. 24

Given the following code, what is the final value of i? int i,j; for(i=0;i<4;i++) { for(j=0;j<3;j++) { if(i==2) break; } }

a. 3 ***b. 4 c. 5 d. 2

What is the output of the following program fragment? cout << (double) 3/4 << endl;

a. 3 b. 0.5 c. 0 ***d. 0.75

What is the value of x after the following statements? float x; x = 15/4;

a. 3.75 b. 4.0 ***c. 3.0 d. 60

What is the next Fibonacci number in the following sequence? 1, 1,2,3,5,8, 13,21, ... a. 34 b. 43 c. 56 d. 273

a. 34

What is the value returned by the following function? int function() { int value = 35; return value + 5; value += 10; }

a. 35 ***b. 40 c. 50 d. 10

What is the output of the following function call? //function body int factorial(int n) { int product=0; while(n > 0) { product = product * n; } n--; return product; } //function call cout << factorial(4);

a. 4 ***b. 0 c. 24 d. 48

What is the output of the following program fragment? cout << pow(4,2) << endl;

a. 4 b. 2 c. 8 ***d. 16

Given the following code, what is the final value of i? int i; for(i = 0; i <= 4;i ++ ) { cout << i << endl; } a. 5 b. 3 c. 4

a. 5

What is the value of x after the following statements? int x, y, z; y = 10; z = 3; x = y * z + 3;

a. Garbage b. 60 c. 30 ***d. 33

Which of the following is not an example of a program bug?

a. Run-time error ***b. Operator error c. Syntax error d. Logic error

If you have the following constant declaration in your program, const int SIZE=34; then which of the following statements is legal?

a. SIZE++; b. x = SIZE--; ***c. cout << SIZE; d. cin >> SIZE;

Which of the following is true about a do ... while loop? a. The body of the loop is executed at least once. b. The logical expression controlling the loop is evaluated before the loop is entered. c. The body of the loop may not execute at all. d. It cannot contain a break statement.

a. The body of the loop is executed at least once.

An algorithm is

a. The inputs and outputs of a program b. The part of the computer that does the processing ***c. A finite set of steps to solve a problem d. A complete computer program

Which of the following is true for a void function?

a. There cannot be a return statement. b. The value of void should be returned. c. The value of 0 should be returned. ***d. Nothing is returned.

Which boolean operation is described by the following table? A B Operation True True True True False False False True False False False False a. and b. not c. or d. none of the above

a. and

What is wrong with the following switch statement? int ans; cout << "Type y for yes on n for no\n"; cin >> ans; switch (ans) { case 'y': case 'Y': cout << "You said yes\n"; break; case 'n': case 'N': cout << "You said no\n"; break; default: cout <<"invalid answer\n"; } a. ans is an int. b. There are no break statements on 2 cases. c. nothing d. break; is illegal syntax.

a. ans is an int.

Which of the following statements is NOT legal?

a. char ch='b'; b. char ch='0'; c. char ch=65; ***d. char ch="cc";

Which of the following is the initial statement in the following for loop? (Assume that all variables are properly declared.) int i; for (i = 1; i < 20; i++) cout « "Hello World"; cout « "!" « endl; a. i = 1; b. i < 20; c. i ++ ; d cout « "Hello World";

a. i = 1;

Which of the following are allowed in the third section of the for loop statement?

a. i++ b. i-- c. i+=2 d. cout << "Hello\n" ***e. all of the above

What is the output of the following code fragment if x is 15? if(x < 20) if(x < 10) else cout << "less than 10 "; cout << "large\n";

a. less than 10 b. nothing ***c. large d. no output, syntax error

Which executes immediately after a continue statement in a while and do-while loop? a. loop-continue test b. update statement c. loop condition d. the body of the loop

a. loop-continue test

Given the following code fragment, and an input value of 0, what is the output that is generated? int x; cout <<"Enter a value\n"; cin >> x; if(x=0) { } cout << "x is zero\n"; else { cout << "x is not zero\n"; }

a. x is zero ***b. x is not zero c. unable to determine d. x is 1

A member function of a class that only accesses the value(s) of the data member(s) is called a(n) ____ function.

accessor

A variable or expression listed in a call to a function is called the

actual parameter

Suppose that alpha is an int variable and ch is a char variable. The input is: ​ 17 A What are the values after the following statements execute? cin >> alpha; cin >> ch;

alpha = 17, ch = 'A'

Suppose that alpha is an int variable and ch is a char variable. The input is: ​ 17 A ​ What are the values after the following statements execute? ​ cin >> alpha; cin >> ch;

alpha = 17, ch = 'A'

Suppose that alpha and beta are int variables and alpha = 5 and beta = 10. After the statement alpha *= beta; executes, ____.

alpha = 50;

Suppose that alpha and beta are int variables. The statement alpha = beta++; is equivalent to the statement(s) ____.

alpha = beta' beta = beta + 1;

reserved words

also known as keywords -word symbols in a programming language that cannot be redefined in any program

cast operator

also known as type conversion or type casting - used to explicitly convert one data type to another data type

arithmetic expression

an expression constructed using arithmetic operators and numbers

integral expression

an expression in which all operands are integers

floating-point expression

an expression in which all operands in the expression are floating-point numbers

mixed expression

an expression that has operands of different data types

run-together word

an identifier that is composed of two or more words that are combined without caps or underscores

unary operator

an operator that has only one operand

binary operator

an operator that has two operands

output statement

an output on the standard output device via cout and <<

Values that are sent into a function are called

arguments

A class object can be ____. That is, it is created each time the control reaches its declaration, and destroyed when the control exits the surrounding block.

automatic

For a program to use the assert function, it must include which of the following? a. #include <assert> c. #include <assertc> b. #include <cassert> d. #include NDEBUG

b. #include <cassert>

The computer's main memory is commonly known as: Select one: a. The hard disk b. The floppy disk c. RAM d. Secondary storage e. None of these

c. (RAM )

What is the output of the following C++ code? int j; for (j = 10; j <= 10; j++) cout « j « " "; cout « j « endl; a. 10 b. 10 10 c. 10 11 d. 11 11

c. 10 11

Which of the following expressions correctly determines that x is greater than 10 and less than 20? a. 10 < x < 20 b. ( 1 0 < x < 20) c. 10 < x & & x < 20 d. 10 < x I I x < 20

c. 10 < x & & x < 20

Suppose sum and num are int variables, and the input is 18 25 61 6 -1. What is the output of the following code? sum = 0; cin » num; while (num != -1) { sum = sum + num; cin » num; cout « sum « endl; a. 92 b. 109 c. 110 d 119

c. 110

What is the output of the following code fragment? int x = 0; { int x = 13; cout << x <<","; } cout << x << endl; a. 0,13 b. 13,13 c. 13,0 d. Nothing, there is a syntax error.

c. 13,0

What is the value of x after the following statements execute? int x; x = (5 <= 3 & & 'A' < 'F') ? 3 : 4 a. 2 b. 3 c. 4 d. 5

c. 4

Given the following enumerated data type definition, what is the value of SAT? enum myType{SUN=3,MON=1,TUE=3,WED,THUR,FRI,SAT,NumDays}; a. 5 b. 8 c. 7 d. 6 e. unknown

c. 7

Which of the following are valid case statements in a switch? a. case 1.5: b. case x < 4: c. case 1: d. case 'ab':

c. case 1:

The expression in an if statement is sometimes called a(n) __ . a. selection statement b. action statement c. decision maker d. action maker

c. decision maker

Which of the following loops does not have an entry condition? a. BOF-controlled while loop b. sentinel-controlled while loop c. do ... while loop d. for loop

c. do ... while loop

clockType-hr: int-min: int-sec: int+setTime(int, int, int): void+getTime(int&, int&, int&) const: void+printTime() const: void+incrementSeconds(): int+incrementMinutes(): int+incrementHours(): int+equalTime(const clockType&) const: bool Consider the UML class diagram shown in the accompanying figure. Which of the following is the name of the class?

clockType

Which header contains the sqrt function?

cmath

int list[5] = {0, 5, 10, 15, 20};int j;for (j = 1; j <= 5; j++) cout << list[j] << " ";cout << endl;

code results in out of bounds

To permit more than one statement to execute if an expression evaluates to true, C++ provides a structure called a ____ statement.

compound

In C++, the ____ operator, written as ?: is a ternary operator.

conditional

source code

consists of the preprocessor directives and program statements

In C++, you can pass a variable by reference and still prevent the function from changing its value by using the keyword ____ in the formal parameter declaration.

const

clockType-hr: int-min: int-sec: int+setTime(int, int, int): void+getTime(int&, int&, int&) const: void+printTime() const: void+incrementSeconds(): int+incrementMinutes(): int+incrementHours(): int+equalTime(const clockType&) const: bool The word ____ at the end of several the member functions in the accompanying figure classclockType specifies that these functions cannot modify the member variables of a clockTypeobject.

const

the value of a default argument must be ___

constant

To guarantee that the member variables of a class are initialized, you use ____.

constructors

Which of the following does not perform the following task: print correct if answer is equal to 7 and incorrect if answer is not equal to 7?

cout << answer == 7 ? "correct" : "incorrect";

int myFunc(int, int); ​ which of the following statements is valid?

cout << myFunc(myFunc(7, 8), 15);

Given the function prototype: float test(int, int, int); which of the following statements is legal?

cout << test(7, 14, 23);

double tryMe(double, double); ​ which of the following statements is valid?

cout << tryMe(2.0, 3.0);

When testing a program with a loop, which of the following tests should be done? a. no iterations of the loops b. the maximum number of iterations c. one less than the maximum number of iterations d. one more than the maximum number of iterations e. A, B, and C

e. A, B, and C

Which of the following are allowed in the third section of the for loop statement? a. i ++ b. cout << "Hello\n" c. i -- d. i += 2 e. all of the above

e. all of the above

In C++, the symbol ==, which consists of two equal signs, is called the ____ operator.

equality

prompt lines

executable statements that inform the user what to do

Which executes first in a do... while loop?

executes do function first

the __ function causes a program to terminate

exit ( )

>> is called stream ___ operator (cin) << is called stream ____ operator (cout)

extraction; Insertion

-controlled while loop uses a bool variable to control the loop.

flag

A number that can have a decimal. Single precision, 4 bytes and numbers between ±3.4E-38 and ±3.4E38. approx. 7 digits. What other data type does this data type associate with?

float double

When a continue statement is executed in a ____, the update statement always executes.

for loop

A variable listed in a header is known as a(n)

formal parameter

___ variables are defined outside of a function, are accessible to any function within their scope, and provide an easy way to share large amounts of data among all the functions in a program

global

pre-increment

has the syntax ++variable

post-increment

has the syntax variable++

post-decrement

has the syntax variable—

pre-decrement

has the syntax —variable

The ___ is the part of a function definition that shows the function's name, return type, and parameter list

header

If a function of a class is static, it is declared in the class definition using the keyword staticin its ____.

heading

What is the initial statement in the following for loop? (Assume that all variables are properly declared.) int i;for (i = 1; i < 20; i++)cout << "Hello World";cout << "!" << endl;

i=1;

self-documenting identifiers

identifiers that describe the purpose of the identifier through the name

Which of the following will cause a logical error if you are attempting to compare x to 5?

if (x=5)

If the possible range of values for a multiple selection statement cannot be reduced to a finite set of values, you must use the ____ structure.

if ... else

Which of the following is a double-selection statement?

if...else.

When you want to process only partial data, you can use the stream function ____ to discard a portion of the input.

ignore

Consider the following program segment. ifstream inFile; //Line 1int x, y; //Line 2... //Line 3 inFile >> x >> y; //Line 4 Which of the following statements at Line 3 can be used to open the file progdata.dat and input data from this file into x and y at Line 4?

inFile.open("progdata.dat");

A for loop is typically called a counted or ____________________ for loop.

indexed

A loop that continues to execute endlessly is called a(n) ____ loop.

infinite

operands

numbers appearing in an arithmetic expression

How many destructors can a class have?

one

In a C++ program, one and two are double variables and input values are 10.5 and 30.6.After the statement cin >> one >> two; executes, ____.

one = 10.5, two = 30.6

If a member of a class is ____, you cannot access it outside the class.

private

Specifying the order in which statements are to be executed in a computer program is called:

program control

Which of the following is a legal identifier?

program_1

____ are executable statements that inform the user what to do.

prompt lines

An ___ eliminates the need to place a function definition before all calls to the function.

prototype

the ___ statement causes the function to end immediately

return (or return x)

syntax rules

rules that describe which statements are legal, or accepted by the programming language, and which are not legal

semantic rules

rules that determine the meaning of the instructions

In a ____ control structure, the computer executes particular statements depending on some condition(s).

selection

A semicolon at the end of the for statement (just before the body of the loop) is a(n) ____________________ error.

semantic

____ is a parameterized stream manipulator.

setfill

In ____ evaluation, the computer evaluates a logical expression from left to right and stops as soon as the value of the expression is known.

short-circuit

Which of the following statements generates a random number between 0 and 50?

srand(time(0)); num = rand() % 50;

Which of the following statements generates a random number between 0 and 50?

srand(time(0));num = rand() % 50;

compound assignment

statement statements that are used to write simple assignment statements in a more concise notation

declaration statements

statements that are used to declare things, such as variables

executable statements

statements that perform calculations, manipulate data, create output, accept input, and so on

Consider the following declaration: char str[15];. Which of the following statements stores "Blue Sky" into str?

strcpy(str, "Blue Sky");

Associated with char, except it's composed of more than one char and uses " ".

string

which of the following correctly finds the sum of the elements of the fourth column of sale?

sum = 0;for(j = 0; j < 10; j++)sum = sum + sale[j][3];

which of the following correctly finds the sum of the elements of the fifth row of sale?

sum = 0;for(j = 0; j < 7; j++)sum = sum + sale[4][j];

Suppose that sum and num are int variables and sum = 5 and num = 10. After the statementsum += num executes, ____.

sum = 15

What is wrong with the following while loop? while ( sum <= 1000 ) sum = sum - 30

sum = sum - 30 should be sum = sum + 30 or else the loop may never end.

The ____ rules of a programming language tell you which statements are legal, or accepted, by the programming language.

syntax

Given the following function: int next(int x) { return (x + 1); }what is the output of the following statement? cout << next(next(5)) << endl; a. 5 c. 7 b. 6 d. 8

C

Suppose that alpha and beta are int variables and alpha = 5 and beta = 10. After the statement alpha *= beta; executes, ____. a. alpha = 5 c. alpha = 50 b. alpha = 10 d. alpha = 50.0

C

Suppose that alpha and beta are int variables. The statement alpha = --beta; is equivalent to the statement(s) ____. a. alpha = 1 - beta; b. alpha = beta - 1; c. beta = beta - 1; alpha = beta; d. alpha = beta; beta = beta - 1;

C

Suppose that alpha and beta are int variables. The statement alpha = beta++; is equivalent to the statement(s) ____. a. alpha = 1 + beta; b. alpha = alpha + beta; c. alpha = beta; beta = beta + 1; d. beta = beta + 1; alpha = beta;

C

The ____ rules of a programming language tell you which statements are legal, or accepted by the programming language. a. semantic c. syntax b. logical d. grammatical

C

The length of the string "computer science" is ____. a. 14 c. 16 b. 15 d. 18

C

The value of the expression 17 % 7 is ____. a. 1 c. 3 b. 2 d. 4

C

Thestatement:return2*3+1,1+5;returnsthevalue ____. a. 2 b. 3 c. 6 d. 7

C

During which stage does the central processing unit retrieve from main memory the next instruction in the sequence of program instructions? Select one: a. portability stage b. decode c. fetch d. execute

(Fetch is incorrect, I believe it is execute)

To use the predefined function tolower, the program must include the header file ____. a. <cctype> b. <iostream> c. <cmath> d. <cstdlib>

A

The output of the statement: cout << pow(2.0, pow(3.0, 1.0)) << endl; is ____. a. 6.0 c. 8.0 b. 7.0 d. 9.0

C

Characters or symbols that perform operations on one or more operands are: Select one: a. Syntax b. Op codes c. Operators d. Program ops e. None of these

c. (Operators )

// Insertion Point 1 using namespace std; const float PI = 3.14; int main() { //Insertion Point 2 float r = 2.0; float area; area = PI * r * r; cout << "Area = " << area <<endl; return 0; } // Insertion Point 3 In this code, where does the include statement belong? a. Insertion Point 1 c. Insertion Point 3 b. Insertion Point 2 d. Anywhere in the program

A

Given the following function: int strange(int x, int y) { if (x > y) } return x + y; else return x - y; what is the output of the following statement? cout << strange(4, 5) << endl; a. -1 c. 9 b. 1 d. 20

A

Given the function prototype: double testAlpha(int u, char v, double t); which of the following statements is legal? a. cout << testAlpha(5, 'A', 2); b. cout << testAlpha( int 5, char 'A', int 2); c. cout << testAlpha('5.0', 'A', '2.0'); d. cout << testAlpha(5.0, "65", 2.0);

A

Suppose that alpha and beta are int variables. The statement alpha = ++beta; is equivalent to the statement(s) ____. a. beta = beta + 1; alpha = beta; b. alpha = beta; beta = beta + 1; c. alpha = alpha + beta; d. alpha = beta + 1;

A

The expression static_cast<int>(6.9) + static_cast<int>(7.9) evaluates to ____. a. 13 c. 14.8 b. 14 d. 15

A

The expression static_cast<int>(9.9) evaluates to ____. a. 9 c. 9.9 b. 10 d. 9.0

A

The output of the statement: cout << tolower('$') << endl; is ____. a. '$' b. '0' c. '1' d. An error, because you cannot use tolower with '$'.

A

The standard header file for the abs(x)function is ____. a. <cmath> c. <cctype> b. <ioinput> d. <cstdlib>

A

Which of the following function prototypes is valid? a. int funcExp(int x, float v); b. funcExp(int x, float v){}; c. funcExp(void); d. int funcExp(x);

A

Which of the following is a reserved word in C++? a. char c. CHAR b. Char d. character

A

Given the following function prototype: double tryMe(double, double);, which of the following statements is valid? Assume that all variables are properly declared. a. cin >> tryMe(x); b. cout << tryMe(2.0, 3.0); c. cout << tryMe(double,double), double); d. cout << (tryMe(float, float), float);

B

Given the following function prototype: int myFunc(int, int);, which of the following statements is valid? Assume that all variables are properly declared. a. cin >> myFunc(y); b. cout << myFunc(myFunc(7, 8), 15); c. cin >> myFunc('2', '3'); d. cout << myFunc(myFunc(7), 15);

B

In a C++ program, one and two are double variables and input values are 10.5 and 30.6. After the statement cin >> one >> two; executes, ____. a. one = 10.5, two = 10.5 c. one = 30.6, two = 30.6 b. one = 10.5, two = 30.6 d. one = 11, two = 31

B

Suppose that count is an int variable and count = 1. After the statement count++; executes, the value of count is ____. a. 1 c. 3 b. 2 d. 4

B

The value of the expression 33/10, assuming both values are integral data types, is ____. a. 0.3 c. 3.0 b. 3 d. 3.3

B

Thestatement:return8,10;returnsthevalue ____. a. 8 c. 18 b. 10 d. 80

B

Which of the following is the newline character? a. \r c. \l b. \n d. \b

B

Which statement below about prototypes and headers is true? a. Parameter names must be listed in the prototype, but not necessarily in the header. b. Prototypes end with a semicolon, but headers do not. c. Headers should come before prototypes. d. Headers end with a semicolon, but prototypes do not.

B

____ are executable statements that inform the user what to do. a. Variables c. Named constants b. Prompt lines d. Expressions

B

____ is a valid char value. a. -129 c. 128 b. 'A' d. 129

B

____ is a valid int value. a. 46,259 c. 462.59 b. 46259 d. -32.00

B

A variable listed in a header is known as a(n) ____ parameter. a. actual b. local c. formal d. function

C

An example of a floating point data type is ____. a. int c. double b. char d. short

C

Functions that do not have a return type are called ____ functions. a. zero c. void b. null d. empty

C

Given the following function prototype: int test(float, char);, which of the following statements is valid? a. cout << test(12,&); b. cout << test("12.0", '&'); c. int u = test(5.0, '*'); d. cout << test('12', '&');

C

Assume the following. static_cast<int>('a') = 97 static_cast<int>('A') = 65 The output of the statement: cout << static_cast<int>(tolower('B')) << endl; is ____. a. 65 c. 96 b. 67 d. 98

D

Given the function prototype: float test(int, int, int); which of the following statements is legal? a. cout << b. cout << c. cout << d. cout << test(7, test(14, 23)); test(test(7, 14), 23); test(14, 23); test(7, 14, 23);

D

Suppose that alpha and beta are int variables. The statement alpha = beta--; is equivalent to the statement(s) ____. a. alpha = 1 - beta; b. alpha = beta - 1; c. beta = beta - 1; alpha = beta; d. alpha = beta; beta = beta - 1;

D

Suppose that sum and num are int variables and sum = 5 and num = 10. After the statement sum += num executes, ____. a. sum = 0 c. sum = 10 b. sum = 5 d. sum = 15

D

The heading of the function is also called the ____. a. title c. function head b. function signature d. function header

D

The output of the statement: cout << pow(3.0, 2.0) + 5 << endl; is ____. a. 11.0 c. 13.0 b. 12.0 d. 14.0

D

Thestatement:return37,y,2*3;returnsthevalue ____. a. 2 c. y b. 3 d. 6

D

True/False: In C++, key words are written in all lowercase letters. Select one: True False

True

True/False: The term "bit" stands for binary digit. Select one: True False

True

Which of the following is not one of the five major components of a computer system? Select one: a. Preprocessor b. The CPU (central processing unit) c. Secondary storage device d. Main memory e. Input/Output device

a. (Preprocessor)

Even when there is no power to the computer, data can be held in: Select one: a. Secondary storage b. The Input Device c. The Output Device d. The Algorithm e. None of these

a. (Secondary storage )

A variable declaration announces the name of a variable that will be used in a program, as well as: Select one: a. The type of data it will be used to hold b. The operators that will be used on it c. The number of times it will be used in the program d. The area of the code in which it will be used e. None of these

a. (The type of data it will be used to hold )

The purpose of a memory address is: Select one: a. To identify the location of a byte in memory b. To prevent multitasking c. To obtain an algorithm d. To improve the effectiveness of high-level languages e. None of these

a. (To identify the location of a byte in memory )

A set of well-defined steps for performing a task or solving a problem is known as aNo: Select one: a. Hierarchy b. Algorithm c. Central Processing Unit d. Encoded instruction e. None of these

b. ( Algorithm )

This step will uncover any syntax errors in your program. Select one: a. Editing b. Compiling c. Linking d. Executing e. None of these

b. (Compiling)

Mistakes that cause a running program to produce incorrect results are called: Select one: a. Syntax errors b. Logic errors c. Compiler errors d. Linker errors e. None of these

b. (Logic errors )

This is used in a program to mark the beginning or ending of a statement, or separate items in a list. Select one: a. Separators b. Punctuation c. Operators d. Key Words e. None of these

b. (Punctuation )

In the process of translating a source file into an executable file, which of the following is the correct sequence? Select one: a. Source code, preprocessor, modified source code, linker, object code, compiler, executable code. b. Source code, preprocessor, modified source code, compiler, object code, linker, executable code. c. Source code, linker, object code, compiler, modified source code, preprocessor, executable code. d. Preprocessor, source code, compiler, executable code, linker, modified source code, object code. e. Source code, compiler, modified source code, preprocessor, object code, linker, executable code.

b. (Source code, preprocessor, modified source code, compiler, object code, linker, executable code. )

This is a complete instruction that causes the computer to perform some action. Select one: a. Line b. Statement c. Variable d. Key Word e. None of these

b. (Statement )

Programmer-defined names of memory locations that may hold data are: Select one: a. Operators b. Variables c. Syntax d. Operands e. None of these

b. (Variables )

A(n) ________ is a diagram that shows the logical flow of a program. Select one: a. UML diagram b. flowchart c. hierarchy chart d. program schematic e. None of these

b. (flowchart)

A(n) ________ is the most fundamental set of programs on a computer. Select one: a. compiler b. operating system c. application d. utility program e. None of these

b. (operating system)

What does the term hardware refer to? Select one: a. The relative difficulty of programming b. The physical components that a computer is made of c. The way a computer's storage space is organized d. The logical flow of instructions e. None of these.

b.( The physical components that a computer is made of )

This is a volatile type of memory, used for temporary storage. Select one: a. Address b. ALU c. RAM d. Disk drive e. None of these

c. ( RAM)

________ are used to translate each source code instruction into the appropriate machine language instruction. Select one: a. Modules b. Library routines c. Compilers d. Preprocessor directives e. None of these

c. (Compilers)

The programming process consists of several steps, which include: Select one: a. Input, Processing, and Output b. Key Words, Operators, and Punctuation c. Design, Creation, Testing, and Debugging d. Syntax, Logic, and Error Handling e. None of these

c. (Design, Creation, Testing, and Debugging)

This term refers to the programmer reading the program from the beginning and stepping through each statement. Select one: a. Pseudocoding b. Software Engineering c. Desk Checking d. Spot Checking e. None of these

c. (Desk Checking)

Three primary activities of a program are: Select one: a. Variables, Operators, and Key Words b. Lines, Statements, and Punctuation c. Input, Processing, and Output d. Integer, Floating-point and Character e. None of these

c. (Input, Processing, and Output )

Words that have a special meaning and may be used only for their intended purpose are known as: Select one: a. Operators b. Programmer Defined Words c. Key Words d. Syntax e. None of these

c. (Key Words )

In a broad sense, the two primary categories of programming languages are: Select one: a. Mainframe and PC b. Hardware and Software c. Low-level and High-level d. COBOL and BASIC e. None of these

c. (Low-level and High-level)

ANo ________ is a set of instructions that the computer follows to solve a problem. Select one: a. Compiler b. Linker c. Program d. Operator e. None of these

c. (Program)

The statements written by the programmer are called: Select one: a. Syntax b. Object code c. Source code d. Runtime libraries e. None of these

c. (Source code)

Internally, the CPU consists of two parts: Select one: a. The Output Device and the Input Device b. The Software and the Hardware c. The Control Unit and the Arithmetic and Logic Unit d. The Single-task Device and the Multi-task Device e. None of these

c. (The Control Unit and the Arithmetic and Logic Unit )

During which stage does the central processing unit analyze the instruction and encode it in the form of a number, and then generate an electronic signal? Select one: a. fetch b. portability stage c. decode d. execute

c. (decode)

Computer programs are also known as: Select one: a. hardware b. firmware c. software d. silverware e. None of these

c. (software )

Which of the following is a preprocessor directive? Select one: a. int main() b. pay = hours * rate; c. // This program calculates the user's pay. d. #include <iostream> e. cin >> rate;

d. (#include <iostream> )

What statement best describes a variable and its primary purpose? Select one: a. A variable is a "line" of code in the body of a program, which may change. b. A variable is a word that has a special meaning to the compiler. c. A variable is a structured, general-purpose language designed primarily for teaching programming. d. A variable is a named storage location in the computer's memory used for holding a piece of information. e. A variable is a collection of eight bits.

d. (A variable is a named storage location in the computer's memory used for holding a piece of information. )

At the heart of a computer is its central processing unit. The CPU's job is: Select one: a. To fetch instructions b. To carry out the operations commanded by the instructions c. To produce some outcome or resultant information d. All of these e. None of these

d. (All of these )

The ________ decodes an instruction and generates electrical signals. Select one: a. Arithmetic and Logic Unit b. Main memory c. BIOS d. Control Unit e. None of these

d. (Control Unit)

This is a set of rules that must be followed when constructing a program. Select one: a. Operators b. Portability c. Key words d. Syntax e. Punctuation

d. (Syntax )

An example of a secondary storage device is: Select one: a. The computer's main memory b. The keyboard c. The monitor d. The disk drive e. None of these

d. (The disk drive )

The name for a memory location that may hold data is: Select one: a. Key Word b. Syntax c. Operator d. Variable e. None of these

d. (Variable )

True/False: Pseudocode is a form of program statement that will always evaluate to "false." Select one: True False

false

True/False: Software engineering is a field that encompasses designing, writing, testing, debugging, documenting, modifying, and maintaining computer programs. Select one: True False

true


Kaugnay na mga set ng pag-aaral

Chapter 1: The First Civilizations and Chapter 2: Cultural Collision

View Set

FIN - 300 Final Exam UKY - Ch. 9

View Set

ART 2140 themes in visual culture 1.6

View Set

PHYS 101, Section W01, Chapter 5 (Homework)

View Set

Nursing Care of the Child With an Alteration in Cellular Regulation/Hematologic or Neoplastic Disorder

View Set

CRJU chapter 1 Self Check: The Criminal Justice (System and Its Functions & Justice Process)

View Set