C++

Ace your homework & exams now with Quizwiz!

The while loop is this type of loop.

pre-test

This operator increments the value of its operand, then uses the value in context.

prefix increment

A function ________ eliminates the need to place a function definition before all calls to the function.

prototype

When used as parameters, these types of variables allow a function to access the parameter's original argument.

reference

This statement causes a function to end.

return

This manipulator is used to establish a field width for the value immediately following it.

setw

A character literal is enclosed in ________ quotation marks, whereas a string literal is enclosed in ________ quotation marks.

single, double

The value in this type of local variable persists between function calls.

static

To access an array element, use the array name and the element's ________

subscript

The default section of a switch statement performs a similar task as the ________ portion of an if/else if statement.

trailing else

What is the value of the following expression? false || true

true

A for statement contains three expressions: initialization, test, and

update

Which of the following expressions will determine whether x is less than or equal to y?

x <= y

When a relational expression is false, it has the value ________.

zero

This operator is known as the logical OR operator.

||

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;

—3

This operator performs a logical NOT operation.

!

This operator takes an operand and reverses its truth or falsehood.

!

The ________ causes the contents of another file to be inserted into a program.

#include directive

What is the modulus operator?

%

When this operator is used with string operands it concatenates them, or joins them together.

+

These are operators that add and subtract one from their operands.

++ and --

What will the following code display? int numbers[4] = { 99,87}; cout << numbers[3] << endl;

0

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;

1

What is the output of the following code segment? n = 1; while (n <= 5) cout << n << ' '; n++;

1 1 1...and on forever

What is the output of the following statement? cout << 4 * (15 / (1+3)) << endl;

12

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;

13

Look at the following program and answer the question that follows it. #include <iostream> using namespace std; int main() { int hours; double payRate, grossPay; hours = 40; payRate = 20.0; grossPay = hours * payRate; cout << "My gross pay is $:" <<grossPay << endl; return 0; } Which line(s) in this program cause output to be displayed on the screen?

14

How many times will the following loop display "Hello"? for (int I = 1; I < 20; I++) cout << "Hello!" << endl;

19

What will the value of result be after the following statement executes? result = 6-3*2+7-10/2

2

How many times will the following loop display "Hello"? for (int I = 20; i > 0; i--) cout << "Hello! << endl;

20

How many times will the following loop display "Hello"? for (int i=0; I <=20; i++) cout << "Hello!" << endl;

21

Look at the following function prototype. int myFunction(double, double, double); How many parameter variables does this function have?

3

In the following C++ statement, what will be executed first according to the order of precedence?

3 * 2

What is the value of average after the following code executes? double average; average = 1.0 + 2.0 + 3.0 / 3.0;

4.0

This operator is used in C++ to represent equality.

==

Which of the following statements about global variables is true?

A global variable can have the same name as a variable that is declared locally within a function.

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

All of these

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

All of these

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

For every opening brace "{" in a C++ program, there must be a:

Closing brace "}"

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

E

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

False

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

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

These are data items whose values do not change while the program is running.

Literals

In memory, C++ automatically places a ________ at the end of string literals.

Null terminator

In a C++ program, two slash marks ( // ) indicate:

The beginning of a comment

________ must be included in any program that uses the cout object.

The header file iostream

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;

This is true! This is all folks!

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

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: 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 the sub-expression on the left side of the || operator is true, the expression on the right side will not be checked.

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: You should be careful when using the equality operator to compare floating point values because of potential round-off errors.

True

________ functions may have the same name, as long as their parameter lists are different.

Two or more

________ represent storage locations in the computer's memory.

Variables

Which escape sequence causes the cursor to move to the beginning of the next line?

\n

The while loop has two important parts: an expression that is tested for a true or false value, and:

a statement or block that is repeated as long as the expression is true

A(n) ________ is information that is passed to a function, and a(n) ________ is information that is received by a function.

argument, parameter

Unlike regular variables, these can hold multiple values.

arrays

In C++ the = operator indicates:

assignment

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:

at least once

A function is executed when it is:

called

You want the user to enter the length, width, and height from the keyboard. Which cin statement is correctly written?

cin >> length >> width >> height;

The ________ causes a program to wait until information is typed at the keyboard and the Enter key is pressed.

cin object

This function tells the cin object to skip one or more characters in the keyboard buffer.

cin.ignore()

The function, pow(x, 5.0), requires this header file.

cmath

Relational operators allow you to ________ numbers.

compare

Here is the header for a function named computeValue: void computeValue(int value) Which of the following is a valid call to the function?

computeValue(10);

This statement may be used to stop a loop's current iteration and begin the next one.

continue

The ________ is/are used to display information on the computer's screen.

cout object

A function ________ contains the statements that make up the function.

definition

It is a good programming practice to ________ your functions by writing comments that describe what they do.

document

The individual values contained in array are known as ________.

elements

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;

false

This is a variable, usually a bool or an int, that signals when a condition exists.

flag

This is a collection of statements that performs a specific task.

function

This is a statement that causes a function to execute.

function call

Every complete C++ program must have a ________.

function named main

________ reads a line of input, including leading and embedded spaces, and stores it in a string object

getline()

Which statement will read an entire line of input into the following string object? string address;

getline(cin, address);

This means to increase a value by one.

increment

When a program lets the user know that an invalid choice has been made, this is known as:

input validation

Look at the following function prototype. int myFunction(double); What is the data type of the function's return value?

int

Which of the following is a valid C++ array definition

int array[10];

The numeric data types in C++ can be broken into two general categories:

integer and floating point

In any program that uses the cin object, you must include the ________.

iostream header file

This manipulator causes the field to be left-justified with padding spaces printed to the right.

left

Assume that a program has the following variable definition: char letter; Which of the following statements correctly assigns the character Z to the variable?

letter = 'Z';

This type of variable is defined inside a function and is not accessible outside the function.

local

A loop that is inside another loop is called:

nested loop

When an if statement is placed within the conditionally-executed code of another if statement, this is known as:

nesting

If you place a semicolon after the test expression in a while loop, it is assumed to be a(n):

null statement

A function can have zero to many parameters, and it can return this many values.

only one

When a variable is assigned a number that is too large for its data type, it:

overflows

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.

persist

The do-while loop is a(n) ________ loop that is ideal in situations where you always want the loop to iterate at least once.

post-test


Related study sets

Developmental Psychology Final Exam

View Set

SPMT 455 Sport Governance Mid-Term

View Set

Chapter 53: Care of the Patient with a Neurologic Disorder

View Set

Clinical chapters 13,14,15,16,17

View Set

Introductory Logic Midterm Exam (VPSA) Study Guide Units 1 - 4 (WIP)

View Set