CSCE 206 - Exam 2 - Practice 3

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

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

A

A switch statement REQUIRES which of the following? A) A value to test the case constants against B) A break after every case C) A break at the end of the switch statement D) A return statement in the default case. E) None of these

A

Functions are ideal for use in menu-driven programs. When a user selects a menu item, the program can ________ the appropriate function. A) call B) prototype C) define D) declare E) None of these

A

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

A

This statement uses the value of a variable or expression to determine which segment of code will be executed. A) switch B) select C) associative D) scope E) None of these

A

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

A

A do-while loop is often used with A) a counting task B) a file input task C) a menu driven task D) a pre-test loop task E) None of these

C

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

C

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

C

The default section of a switch statement performs a similar task as the ____ portion of an if/else if statement A) conditional B) break C) trailing else D) all of these E) None of these

C

Which of the following statements about global variables is true? A) A global variable is accessible only to the main function. B) A global variable is declared in the highest-level block in which it is used. C) A global variable can have the same name as a variable that is declared locally within a 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.

C

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 ? : x) << endl; A) 0 B) 1 C) 2 D) 3 E) None of these

D

If you place a semicolon after the test expression in a while loop, it is assumed to be a(n): A) pre-test loop B) post-test loop C) null statement D) infinite loop E) None of these

D

The value of a, b, and c are 3, 4 and -5 respectively. Which f the following will evaluate as FALSE? A) !(!5) B) !(c+5) C) a && b && c D) a || b || c E) None of these

E

Which of the following is the last character of all string constants?. A) '\n' B) <cr> C) '/0' D) '.' E) None of these

E

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

False

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

False

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

False

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

False

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

False

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

False

A block of code can be nested

True

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

True

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

True

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

True

The default section of a switch statement performs a similar task as the ________ portion of an if/else if statement. A) conditional B) break C) trailing else D) All of these E) None of these

C

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

C

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) 5 B) 2 C) 7 D) "getValue(x)" E) None of these

C

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

True

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

True

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

True

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

True

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

True

When a program lets the user known that an invalid choice has been made, this is known as: A) input validation B) output correction C) compiler criticism D) output validation E) None of these

A

EXIT_FAILURE and ________ are named constants that may be used to indicate success or failure when the exit() function is called. A) EXIT_TERMINATE B) EXIT_SUCCESS C) EXIT_OK D) RETURN_OK E) None of these

B

Given that, x = 2, y = 1, and z = 0, what will the following cout statement display? cout << "answer = " << (x || !y && z) << endl; A) answer = 0 B) answer = 1 C) answer = 2 D) answer = 3 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? int x = 1; int y = 2; int z = 3; calc(x, y); cout << x << " " << y << " " << z << endl; A) 1 2 3 B) 1 6 3 C) 3 6 3 D) 1 14 9 E) None of these

B

Look at the following statement. while (x++ < 10) Which operator is used first? A) ++ B) < C) Neither. The expression is invalid. D) while statement will ignore the condition E) none of these

B

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

B

To write data to a file you must A) use an outputFile object B) use the "open" function to connect with the file C) define an ifstream object D) A and B. E) none of the above

B

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

B

What is the output of the following program? #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; } A) 2 2 B) 4 2 C) 2 4 D) 4 4 E) None of these

B

When a relational expression is false, it has the value ________. A) one B) zero C) zero, one, or minus one D) less than zero E) None of these

B

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

C

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

C

Input values should always be checked for: A) Appropriate range B) Reasonableness C) Division by zero, if division is taking place D) All of these E) None of these

D

This may be used to write information to a file. A) cout object B) pen object C) output object D) stream insertion operator E) None of these

D

What will the following code display? int x = 0; for (int count = 0; count < 3; count++) x += count; cout << x << endl; A) 0 1 2 B) 0 C) 6 D) 3 E) none of these

D

Which line in the following program contains the header of the showDub function? 1 #include <iostream> 2 using namespace std; 3 4 void showDub(int); 5 6 int main() 7{ 8 int x=2; 9 10 showDub(x); 11 cout << x << endl; 12 return 0; 13 } 14 15 void showDub(int num) 16 { 17 cout << (num * 2) << endl; 18 } A) 4 B) 6 C) 10 D) 15 E) None of these

D

Which of the following can be used to force the conditional test in a loop to be performed sooner? A) exit(0) B) break C) switch D) continue E) jump

D


Conjuntos de estudio relacionados

Comp TIA A+ 220-1001 5.1 Troubleshooting Process

View Set

Personal Finance - Chapter 8 Practice Exam

View Set

Chap 19 Nursing Management of Pregnancy at Risk: Pregnancy-Related Complications

View Set