C++ programming exam 2

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

This operator represents the logical AND:

&&

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

++ and --

When a relational expression is false, it has the value

0

What will the following code display? int x = 0; while (x < 5) { cout << x << " "; x++; }

0 1 2 3 4

Given the following function: 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 segment that invokes calc(): int x = 1; int y = 2; int z = 3; calc(x, y); cout << x << " " << y << " " << z << endl;

1 6 3

What is the value of donuts after the following statement executes? int donuts = 10; if (donuts != 10) donuts = 0; else donuts += 2;

12

What is the output of the following segment of code if the value 4 is input by the user? 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;

13

After the following code executes, what is the value of my_value if the user enters 0? cin >> my_value; if (my_value > 5) my_value = my_value + 5; else if (my_value > 2) my_value = my_value + 10; else my_value = my_value + 15;

15

What will the following code display? #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; }

2 0 0

What will the following code display? #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; }

2 0 2

In the following function prototype, how many parameter variables does this function have? int myFunction(double, double, double);

3

What will the following code display? #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; }

4 2

What will the following code display? #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; }

7

What will the following code display? int number = 6; number++; cout << number << endl;

7

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";

99

The __________ is an equality (or comparison) operator.

==

What is the value of the following expression? true && !false

False

What is the output of the following code segment if the user enters 23? int number; cout << "Enter a number: "; cin >> number; if (number > 0) cout << "Hi, there!" << endl; else cout << "Good-bye." << endl;

Hi, there!

Something within a while loop must eventually cause the condition to become false or a(n) __________ results.

Infinite loop

What is the output of the following code segment if the user enters 90 for the score? cout << "Enter your test score: "; cin >> test_score; if (test_score < 60) cout << "You failed the test." << endl; if (test_score > 60) cout << "You passed the test." else cout << "You need to study harder next time." << endl;

You passed the test.

Which of the following causes a function to execute?

a function call

The do-while loop is considered

a post-test loop

The two important parts of a while loop are the 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

The statements in the body of a while loop may never be executed while the statements in the body of a do-while loop will be executed

at least once

A statement that causes a loop to terminate early is

break

Without this statement appearing in a switch construct, the program "falls through" all of the statements below the one with the matching case expression.

break

A function is executed when it is

called

Relational operators allow you to __________ numbers.

compare

A statement that may be used to stop a loop's current iteration and begin the next one is

continue

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

counter

If you intend to place a block of statements within an if statement, you must place __________ around the block:

curly braces { }

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

definition

The __________ loop is ideal in situations where you want the loop to iterate at least once.

do-while

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

document

What is the data type of the following function prototype's parameter variable? int myFunction(double);

double

If you want a user to enter exactly 20 values, which loop would be the best to use?

for

The __________ loop is a good choice when you know how many times you want the loop to iterate in advance of entering the loop.

for

A collection of statements that performs a specific task is a(n)

function

A _________ variable is declared outside all functions.

global

This means to increase a value:

increment

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

int

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

line 11

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

line 3

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

line 7

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

local

This is a control structure that causes a statement or group of statements to repeat.

loop

A loop that is inside another loop is called a(n)

nested loop

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

nesting

The while loop is a __________ loop.

pre-test

This statement causes a function to end.

return

A special value that marks the end of a list of values is a

sentinel

This statement uses the value of a variable or expression to determine where the program will branch to.

switch

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

trailing else

What is the value of the following expression? true && true

true

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

true

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

update

The __________ loop is a good choice when you do not want the loop to iterate if the condition is false in the beginning.

while

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

x <= y

This operator represents the logical OR:

||


Conjuntos de estudio relacionados

Chapter 14: Physical Development in Adolescence

View Set

The New Deal: Relief, Recovery, and Reform

View Set

NU 322 Exam 2 (Acid Base Balance Ticket to Test)

View Set

8 Questions (Ch. 46), 7 Questions (Ch. 41), 5 Questions (Ch. 26), 5 Questions (Ch. 26), 2 Questions (Ch. 27), 2 Questions (Ch. 27), 3 Questions (Ch. 37), 4 Questions (Ch. 42), 7 Questions (Ch. 44), 5 Questions (Ch. 45), 3 Questions (Ch 16), 4 Questio...

View Set