CSCE 206 Exam 2

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

A file ________ is a small holding section of memory that file-bound information is first written to. A) buffer B) segment C) name D) number E) None of these

A

Look at the following statement. while (x++< 10) Which operator is used first? A) < B) ++ C) Neither. The expression is invalid. D) ++ is not executed, just < E) None of the above.

A

This operator increments the value of its operand, then uses the value in context. A) prefix increment B) postfix decrement C) prefix decrement D) postfix increment 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

A

When used as parameters, these types of variables allow a function to access the parameter's original argument. A) reference B) undeclared C) floating-point D) counter E) None of these

A

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

B

A(n) ________ is information that is passed to a function, and a(n) ________ is information that is received by a function. A) prototype, header B) argument, parameter C) function call, function header D) parameter, argument E) None of these

B

Given the following function definition 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 fragment that invokes calc? (All variables are of type int) x = 1; y = 2; z = 3; calc(x, y); cout << x << " " << y << " " << z << endl; A) 1 14 9 B) 1 6 3 C) 3 6 3 D) 1 2 3 E) None of these

B

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 only if the expression is false B) a statement or block that is repeated as long as 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 once, if the expression is true E) None of the above

B

This is a variable that is regularly incremented or decremented each time a loop iterates. A) null terminator B) counter C) control statement D) constant E) None of these

B

This statement may be used to stop a loop's current iteration and begin the next one. A) break B) continue C) re-iterate D) terminate E) None of these

B

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

B

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; A) 7 B) 1 C) 0 D) 10 E) The string "x >= y"

B

What is the output of the following program? # 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; } A) 2 B) 7 C) 5 D) "getValue(x)" E) None of the above

B

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 true! B) This is true! This is all folks! C) This is true! This is false! D) This is false! E) None of these

B

What will the following program display? # include <iostream> using namespace std; int main( ) { int a = 0, b = 2, x = 4, y = 0; cout << (a == b) << " "; cout << (a != b) << " "; cout << (b <=x)<< " "; cout << (y > a) << endl; return 0; } A) 1 0 0 1 B) 0 1 1 0 C) 0 0 1 0 D) 1 1 0 1 E) None of these

B

What will the following segment of code output? You can assume the user enters a grade of 90 from the keyboard. cout << "Enter a test score: "; cin >> test_score; if (test_score < 60) cout << "You failed the test!" << endl; if (test_score > 60) cout << "You passed the test!" << endl; else cout << "You need to study for the next test!"; A) You failed the test! You did poorly on the test! B) You passed the test! C) You failed the test! D) You failed the test! You passed the test! E) None of these

B

Which of the following statements about global variables is true? A) A global variable is declared in the highest-level block in which it is used. B) A global variable can have the same name as a variable that is declared locally within a function. C) A global variable is accessible only to the main function. D) If a function contains a local variable with the same name as a global variable, the global variable's name takes precedence within the function. E) All of these are true

B

If you place a semicolon after the statement if (x < y) A) the code will not compile B) the if statement will always evaluate to false C) the compiler will interpret the semicolon as a null statement D) All of the above E) None of these

C

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

C

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

C

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

C

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

C

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

C(B)

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

D

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

D

These types of arguments are passed to parameters automatically if no argument is provided in the function call. A) global B) local C) relational D) default E) None of these

D

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

D

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

D

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

D

A loop that is inside another loop is called: A) a pre-test loop B) embedded C) an infinite loop D) a post-test loop E) None of these

E

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

E

This is a pre-test loop that is ideal in situations where you want the loop to iterate if the condition is false from the beginning. A) infinite B) while C) for D) do-while E) None of these

E

What is the output of the following code segment? n = 1; for ( ; n <= 5; ) cout << n << ' '; n++; A) 2 3 4 5 6 B) 1 2 3 4 5 C) 1 2 3 4 D) 2 3 4 5 E) 1 1 1 ... and on forever

E

A file must be ________ before data can be written to or read from it. A) initialized B) created C) buffered D) closed E) None of these

E(B)

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

False

T/F: A local variable and a global variable may not have the same name within the same program.

False

T/F: The default section is required in a switch statement.

False

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

False

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

False

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

False

T/F: You may not use the break and continue statements within the same set of nested loops.

False

T/F: You must furnish an argument with a function call.

False

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

True

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

True

T/F: As a rule of style, when writing an if statement you should indent the conditionally-executed statements.

True

T/F: If the sub-expression on the left side of an && operator is false, the expression on the right side will not be checked.

True

T/F: It is not considered good programming practice to declare all of your variables globally.

True

T/F: It is possible for a function to have some parameters with default arguments and some without

True

T/F: The update expression of a for loop can contain more than one statement, e.g. counter++, total+= sales.

True


Set pelajaran terkait

Exploring Creation with Chemistry Mod 1 OYOs

View Set

Other Health Insurance Concepts Practice Questions

View Set

Sololearn Python for Beginners #6 Functions

View Set

Torts - Invasion of Right to Privacy

View Set

Genetics Final Exam Homework Review

View Set

US History Final Chapter 20, Emergence of Urban America

View Set

The Hero's Journey- An Archetypal Story

View Set