CSCE 206 Exam#2

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

F

A For loop is somewhat limited, because the counter can only be incremented by one each time through the loop.

T

A block of code can be nested.

B

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

A

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

D

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

A

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

F

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

F

A local variable and a global variable may not have the same name within the same program.

T

A parameter is a local variable that is declared inside the parentheses of a function definition.

T

A reference parameter is implemented as a local variable in the called function.

F

A stack frame is created for all invoked functions except main().

T

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

F

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

D

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) 10 B) 25 C) 5 D) 15 E) 0

T

An initialization expression may be omitted from the for loop if no initialization is required.

T

An ofstream variable can be initialized to the name of an existing file.

C

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) Only 5 is false. B) 3, 4, 6, 7 are false. C) 3 and 4 are false. D) All are false. E) None of these

T

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

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) 2 B) 0 C) 1 D) 3 E) None of these

C

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) communicate B) change C) persist D) execute E) None of these

T

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

C

If you place a semicolon after the test expression in a while loop, the code is a(n): A) infinite loop B) post-test loop C) loop statement without a body. D) Compilation error E) None of these

E

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

D

Input values should always be checked for: A) reasonableness B) appropriate range C) Correctness D) A and B only. E) None of these

T

It is possible to define a file stream object and open a file in one statement.

F

Local variables are initialized to zero by default.

D

Relational operators allow you to _________ numbers. A) average B) add C) multiply D) compare E) None of these

A

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

T

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

A

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

F

The code " if(-50) " would cause a compiler error.

F

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

F

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

F

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

T

The open function invoked through an ifstream variable must be passed the name of an existing file.

F

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

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

A

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

A

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

D

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

C

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

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) infinite B) do-while C) for D) while E) None of these

C

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

C

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

B

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

D

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

B

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

C

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

A

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) 1 B) 98 C) 0 D) 99 E) None of These

B

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 2 2 B) 2 0 0 C) 2 0 2 D) 0 0 0 E) None of these

A

What is the output of the following segment of code if 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) 13 B) 3 C) 0 D) 28 E) None of these

D

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) x C) true D) false E) None of these

D

What will following segment of code output? 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 false! B) This is true! C) This is true! This is false! D) This is true! This is all folks! E) None of these

C

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

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) 0 1 2 3 4 D) The loop will display numbers starting at 0, for infinity. E) None of these

B

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) 10 10 B) 1 1 C) 7 15 D) 0 0 E) None of these

F

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

A

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

F

You may not nest a while loop inside a For loop.

F

You may not use the break and continue statements within nested loop syntax.

T

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


संबंधित स्टडी सेट्स

Chapter 3 - The Economic Problem

View Set

Chapter 2-1 - Structure of neurons

View Set

ISYS 310 Chapter 5 (Network and transport layers)

View Set

Microeconomics Assignments Chapters 1-3

View Set

Tesco Interview Preparation: Situation Questions

View Set

CHEM Knewton Alta 1.2 The Scientific Method

View Set