Programming test 2

¡Supera tus tareas y exámenes ahora con Quizwiz!

The ____ operator takes an operand and reversed its truth or falsehood.

!

What will the following code print? num = 5; out << num++ << " "; cout << num-- << " "; cout << --num;

654

What will the following code print? num = 8; cout << --num << " "; cout << num++ << " "; cout << num;

7 7 8

The ____ operator is used in c++ to test for equality.

==

True/False: The following statements will not print anything. x =5; if (x < 5) cout << "Hello "; cout << "world \n";

False

True/False: To check if a variable has a particular value, use the = relational operator as in the statement: if (s = 3)

False

To ____ a value means to increase it.

Increment

If nothing within a while loop ever causes the condition to become false, a(n) ________ may occur.

Infinite loop

When a program lets the user know that an invalid menu choice has been made, this is an example of

Input validation

The ++ operator

Is a unary operator, adds to the value of its operand, and can operate in prefix or postfix mode.

A _____ is a variable that controls the number of times a loop iterates.

Loop control variable

If a while loop has no braces around the body of the loop

The loop body contains just one statement

True/ False: Assuming goodData is a Boolean variable, the following two tests are logically equivalent. If (goodData == false) If (!goodData)

True

True/ False: The following C++ test checks if the variable child is in the range 3-12

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

What will the following statement do if x equals 17 and answer = 20? answer = x > 100 ? 0 : 1;

assign 1 to answer

A ____ is a variable that is regularly incremented or decremented each time a loop iterates

counter

A void function is one that

returns no value

Two or more functions may have the same name provided that

their parameter lists are different

If a switch statement has no ________ statements, the program "falls through" all of the statements below the one with the matching case expression.

to break

Relational operators allow you to ________ numbers.

to compare

The ____ statement causes a function to end and the flow of control to move back to the point where the function call was made

to return

You may define a __________ in the initialization expression of a for loop.

variable

A function other than the main function is executed

whenever it is called

In a function header, in addition to the name of the function, you are required to furnish

A data type for each parameter, an identifier name for each parameter and the data type of the return value.

For data validation, it is best to use

A while loop

A variable that keeps a running total of data values is called a(n) ________.

Accumulator

In a function call, in addition to the name of the function, you are required to furnish

An identifier name or constant for each argument

The whole loop has two important parts: a condition that is tested and a statement or block or statements that is executed.

As long as the condition is true

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

Definition

Enumerated data type named student

Enum student { bill, Tom, Mary }

True/ False: A while loop may have a semicolon after the test expression and before the body of the loop, but it is not required.

False

True/ False: The following C++ test checks if the variable child is in the range 3 to 12

False

True/ False: to decrement a number means to increase its value

False

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.

False

True/False: logical operators AND and OR have a higher precedence than the NOT operator.

False

True/False: the scope of a variable is the program it is defined in

False

The ________ statement acts like a chain of if statements. Each performs its test, one after the other, until one of them is found to be true or until the construct is exited without any test ever evaluating to true.

If/ else if

The - - operator

Is a unary operator, subtracts one from the value of its operand, must have an lvalue, such as a variable, as its operand, and can be used in either prefix or postfix mode.

To use an output file in a c++ program you must

Open the file and create a file stream object that will "point to" the file

When more than one function has the same name they are called _____ functions.

Overloaded

The while loop has two important parts: a condition that is tested and a statement or block of statements that is

Repeated as long as the condition is true

In order for a c++ program to read data from a file,

The file must already exist, the program must define a file stream object that can "point to" the file, and the program must open the file

True/ False: relational expressions and logical expressions are both Boolean, which means they evaluate to true or false.

True

True/ False: when a function needs to use a copy of an argument passed to it, the argument should normally be passed by value.

True

True/False: functions are ideal for use in menu- drive programs. When a user selects a menu item, the program can call an appropriate function to carry out the user's choice.

True

True/False: the statement pass= (score >=7)? True : False; does exactly the same thing as the if/else statement below: If (score >=7) pass= true; Else pass = false;

True

True/False: when a loop is nested inside another loop, the inner loop goes through all its iterations for each iteration of the outer loop

True

When a loop is nested inside another loop, the outer loop goes through all its iterations for each iteration of the inner loop.

True

True/ False: An expression in a C++ if statement that evaluates to 5,-5, or for that matter anything other than 0, is considered true.

True by if statement

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

Update

The ideal type of loop to use for repeating a menu is a(n) ________ loop.

do-while

A _____ is a program module whose purpose is to test other modules by calling them

driver

The ____ function causes the entire program to terminate, regardless of which function or control mechanism is executing.

exit

The ideal type of loop to use if you want a user to enter exactly 20 values is a _____ loop.

for

To use files in a C++ program you must include the ________ header file.

fstream

In a for statement, the _____ expression is executed only once

initialization

A _____ variable is defined inside the body of a function and is not accessible outside that function

local

A sentinel is a special value that ________.

marks the end of a list of values

Breaking a program up into a set of manageable sized functions is called ________ programming.

modular

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

nesting

A trailing else placed at the end of an if/else if statement provides a default action when ________ of the if conditions is/are true.

none

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

reference

If s1 and s2 are string objects, s1 == s2 is true when

s1 = "dog" and s2= "DOG"

The value in ________ local variable is retained between function calls.

static

The C++ ____ operator represents logical AND.

&&

_______ are c++ operators that change their operators by one.

++ and - -

In c++ when a relational expression is false, it has the value

0

What will the following expression evaluate to? !(6>7 || 3 ==4)

0

In a function prototype, in addition to the name of the function, you are required to furnish

A data type for each parameter, an identifier name for each parameter and the data type of the return value.

In the following statement, what is 22.0? cout << sqrt(22.0);

An argument

A ____ is information that is passed to a function, and a ____ is a special variable that receives and holds that information.

Argument, parameter

A flag is a variable, usually of data type ________, that signals whether or not some condition exists.

Bool

The _____ statement causes a loop to terminate early.

Break

A function ____ is a statement that causes a function to execute.

Call

A ____ argument is one that is automatically passed to a parameter when the argument is left out of the function call.

Default

True/ False: both function headers and function calls must list the data types of all data being passed to the function.

False

True/ False: if a function has no return statement, the flow of control moves to the next function in the file when the closing brace of the function body is reached.

False

True/ False: when you make a function call, the order of the arguments you send does not matter as long as the number of arguments matches the number of parameters the function has.

False

True/ false: you may use the edit function to return the flow of control from a function back to main regardless of where the function was called from.

False

True/False: A switch statement branches to a particular block of code depending on the value of a numeric (i.e. integer or floating-point) variable or constant.

False

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

False

True/False: a while loop is somewhat limited, because the counter can only count up, not down.

False

True/False: before beginning to add value to it, an accumulator should be initialized to 1.

False

True/false: you can nest a for loop inside another for loop, but cannot nest a while loop inside another while loop or a do while loop inside another do while loop

False

True/ False: relational operations connect two or more relational expressions into one, or reverse the logic of an expression.

False. Logical operators

A ____ is a variable, usually a bool, that signals when a conditions exists.

Flag

To use files in a c++ program you just include the _____ header file.

Fstream

The _____ statement executes one statement, or block of statements, if a condition is true snd skips it, doing nothing, if the condition is false.

If

The _______ statement causes other program statements to execute only under certain conditions.

If

The _____ statement executes one block of statements if a test condition is true, and another block if the condition is false.

If else

The while loop is a _____ loop, whereas the do while loop is a ____ loop.

Post test, pre test

The do-while loop is a _____ loop, whereas the while loop is a _____ loop.

Post test, pretest

The expression x<y is called a

Relation expression

A ____ is a special value that marks the end of a list of variables

Sentinel

A ___ is a dummy function that is called instead of the actual function it represents, to test that the call to and return from the function are working correctly.

Stub

An overloaded function is one

That has the same name as another function

True/ False: although global variables can be useful, it is considered good programming practice to restrict your use of them.

True

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

True

True/ False: assuming moreData is a Boolean variable, the following two tests are logically equivalent

True

True/ False: in c++ global and local numeric variables are initialized to zero by default.

True

True/ False: it is possible for a function to have some parameters with default arguments and same point.

True

True/ False: one reason for using functions is to break programs into a set of manageable units or modules.

True

True/ false: a function with a return type of bool must return a value of either true or false.

True

True/False: A pair of characters or a pair of string objects can be compared with any of the relational operators.

True

True/False: All of the relational operators are binary.

True

True/False: The block of code in the body of a while statement can contain an unlimited number of statements, provided they are enclosed in a set of braces.

True

True/False: The rule for matching an else with an if is that an else goes with the last if statement before it that doesn't have its own else.

True

True/False: a function can have zero to many parameters and either zero or one return value(s).

True

A static local variable is one

Whose value is retained between functiona

A function can have ____ parameters, and it can have either zero or one return values.

Zero to many

The statements in the body of a do-while loop are executed

at least once

A _____ variable is declared outside all functions.

global

When a function needs access to an original argument passed to it, for example in order to change its value, the argument needs to be

passed into a reference parameter

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

prototype

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

value

The ________ operator is known as the logical OR operator.

||


Conjuntos de estudio relacionados

Module 10: Labor and Worker Protection Law

View Set

Perioperative: Postoperative: M/S

View Set