programming test 2 questions

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

A while loop requires a semicolon after the test expression and before the body of the loop t or f

false

The following C++ test checks if the variable child is in the range 3-12. if (child >= 3 || child <= 12) t or f

false

The three logical operators: AND, OR, and NOT, all have the same precedence. t or f

false

Which of the following will allow an entire line of text to be read into a string object, even if it contains embedded blanks?

getline()

The ______ statement can cause other program statements to execute only under certain conditions.

if

Two different variables in the same program may have the same name

if they have different scope.

The _____ statement will execute one group of statements if a test expression is true or another group if the test expression is false.

if/else

An if statement inside of another if statement is considered a(n) __________.

nested if statement

A(n) __________ is a special variable that holds a value being passed as an argument into a function.

parameter

What type of function does NOT return a value?

void function

For data validation of data, it is best to use a(n)

while or a do...while loop

The ____ operator represents the logical AND.

&&

_____ and ____ are operators that add and subtract one from their operands.

++ and --

How many return values may a function return?

1

Given the following program segment, show exactly what output will be displayed. count = 1; do { count = count + 3; cout << count << " "; }while (count < 15); cout <<"Finished" << endl;

4 7 10 13 16 Finished

Given the following program segment, type exactly what output will be displayed. int num = 3; num *=2; while (num<50) { cout << num << " "; num *=2; }

6 12 24 48

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

778

The ____ operator is used in C++ to represent equality.

==

Which of the following is NOT a logical operator?

EQUAL (==)

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

None of these because one or more characters in the strings have different ASCII codes.

What would the following code output to the user? bool check = 0; if (!check) cout << "This is true!";else cout << "This is false!"

This is true!

Values passed into a function are called:

arguments

In C++ the = operator indicates

assignment

The statements in the body of a while loop might never be executed, whereas the statements in the body of the do-while loop are always executed:

at least once

The OR (||) operator will return false if:

both expressions are false

The AND (&&) operator returns a true if:

both expressions are true

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

break

Is the following a function header or function call? void showResults()

function header

For an if statement to conditionally execute a group of statements, the statements must be enclosed in a set of __________.

curly braces

What is wrong with the following code? The code should display "Have a great day and a great week, too" if value is equal to value2. int value = 2;int value2 = 2; if (value == value2) cout << "Have a great day"; cout << " and a great week, too." << endl;

curly braces are missing around the body of the if-statement

A trailing ____ placed at the end of an if/else if statement provides a default action when none of the ifs have true expressions.

else

To check if a variable contains a particular value, use the = relational operators, as in the statement if (s = 3) cout << "S has the value 3" ; t or f

false

To place an entire block of statements within an if statement, you must place the symbols /* */ around the block. t or f

false

A value of a relational expression is 0 if the expression is __________ or 1 if the expression is __________.

false, true

Is the following a function header or a function call? calcTotal();

function call

The scope of a variable means the part of the program where

it can be used

The while loop is a(n) _____ loop.

pretest

Either a function's __________ or its __________ must precede all calls to the function. header, return value

prototype, definition

An expression using the greater-than, lesser-than, greater-than-or-equal-to, less-than-or-equal-to, equal, or not-equal operator is called a(n) __________ expression.

relational

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

Loops are better suited for use in data validation than if statements. t or f

true

The block of code that follows a while condition can contain an unlimited number of statements, provided they are enclosed in braces. t or f

true

The following statement doubles the value stored in answer. answer *= 2; t or f

true

The if statement regards an expression with a non-zero value as __________.

true

The rule for matching an else with an if is that an else goes with the first if statement before it that doesn't have its own else. t or f

true


Ensembles d'études connexes

The use of electric current in physical therapy

View Set

History 10-3 The Protestant Reformation

View Set

BSC 2010 Ch 6 Dynamic Study Module

View Set

Module 1 C7 Insurance - Annuities

View Set

Standard Form to Slope Intercept Form

View Set

EBM Quiz, DILE Midterm, DILE -- Chapter 2

View Set