COP3014 Midterm

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

In what order would the following operators be evaluated? -,*,/,+,%

* , / , % , - , +

What value does function mystery return when called with a value of 4? int mystery ( int number ) { If ( number <= 1 ) Return 1; Else Return number * mystery (number - 1 ); }

24

Assuming the following pseudocode for the Fibonacci series, what is the values of fibonacci(5)? fibonacci( 0 ) = 0 fibonacci( 1 ) = 1 fibonacci( n ) = fibonacci ( n -1 ) + fibonacci ( n - 2 )

5

Given the following function template Template < class T > T maximum ( T value1, T value2 ) { If ( value1 > value2 ) Return value1; Else Return value2; } What would be returned by the following two function calls? Maximum ( 2, 5); Maximum ( 2.3, 5.2 );

5 and 5.2

Consider the following code, assuming that x is an int with an intial value of 12 if ( x = 6 ) cout << x; What is the output?

6

What is the final value of x after performing the following operations? int x = 21; double y = 6; double z = 14; y = x / z; x = 5.5 * y;

8

Which of the following C++ Standard Library header files does not contain a C++ Standard Library container class?

<string>

The assignment operator __ assigns the value of the expression on its right to the variable on its left.

=

Each of the following is a relational or equality operator except:

=!

An operator that associates from right to left is

?:

To handle situations where a loop must reinitialize a variable at the beginning of each iteration, such re-initialization could be performed by:

A declaration inside the loop body

A function prototype can always be omitted when:

A function is defined before it's first invoked

An activation record will be popped off the function call stack whenever:

A function returns control to its caller

A switch statement should be used:

All of the above

Which of the following data types can be used to represent integers?

All of the above

Which of the following does counter-controlled repetition require?

All of the above

Which of the following is a compilation error?

All of these

Which of the following is/are considered part of Web 2.0?

All of these

How many times will the following loop print hello? i=1 while (i <= 10) cout << "hello";

An infinite number of times

Using a while loop's counter-control variable in a calculation after the loop ends often causes a common logic error called:

An off-by-one error

Consider the execution of the following for loop For (int x = 1; x < 5; increment ) Cout << x + 1 << endl; If the last value printed is 5, which of the following might have been used for increment?

Any of the above

Which of the following is not one of the rules for forming structures programs?

Any transition arrow can be reversed

A reference parameter:

Both (a) and (b)

Using the following function definition, the parameter list represented by: A B ( C ) { D }

C

The inline keyword:

Can reduce a function's execution time but increase program size

The data type bool:

Can take on values true and false

Which of the following is correct when labeling cases in a switch structure?

Case 1

Which of the following is false?

Continue and break statements may be embedded only within repetition statements

Which of the following encompasses the other three?

Control structure

Pseudocode does not include:

Declarations

The function prototype double mySqrt ( int x );

Declares a function called mySqrt which takes an integer as an argument and returns a double

In regards to default arguments, which of the following is false?

Default values cannot be global variables or function calls

An identifier's storage class:

Determines the period during which that identifier exists in memory

Overloaded functions must have:

Different parameter lists

Functions can

Do all of the above

In C++, the condition ( 4 > y > 1 ):

Does not evaluate correctly and should be replaced by ( 4 > y && y > 1)

Which of the following is not a valid enumeration statement?

Enum person {me, you, me};

Which operation does not take place in the following example? int x = 21; double y = 6; double z = 14; y = x / z; x = 5.5 * y;

Explicit conversion

Which of the following statements does not cause a syntax error to be reported by the C++ compiler?

Extra blank lines

In an activity diagram for an algorithm, what does a solid circle surrounded by a hollow circle represent?

Final state

Which of the following is true of function templates?

Formal type parameters act as placeholders for built-in types of user-defined types and are used to specify the types of arguments to the function, to specify the return type of the function, and to declare variable within the body of the function definition

If a set of functions have the same program logic and operations and differ only in the data type(s) each receives as argument(s) then a(n) __ should be used.

Function template

Each standard library has a corresponding:

Header file

Which is the output of the following statements?

Hello World

A function prototype does not have to

Include parameter names

The conditional operator (?:):

Is the only ternary operator in C++

All of the following are reasons to use recursion except:

It maximizes execution performance

Type-safe linkage is ensured by

Name mangling

Having a loop within a loop is known as:

Nesting

The std::endl stream manipulator ___.

Outputs a newline and flushes the output buffer

If grade has the value of 60, what will the following code display? if ( grade >= 60 ) cout << "Passed";

Passed

Which of the following operations has the highest precedence?

Postincrement

Recursion is memory-intensive because:

Previous function calls are still open when the function calls itself and the activation records of these previous calls still occupy space on the call stack

What will the following program segment do? int counter = 1; do { cout << counter << " "; } while (++counter <= 10);

Print the numbers 1 through 10

Indefinite repetition is controlled by a:

Sentinel value

The ___, ___ and ___ are the only three forms of control necessary.

Sequence, selection, repetition

In indefinite repetition, an input value:

Should always be evaluated before being processed

The OR ( | | ) operator:

Stops evaluation upon finding one condition to be true

An example of a unary operator is:

The ! logical operator

What happens when two blocks, one nested inside of the other, both declare variables with the same identifier? (Assume that the outer block declares its variable before the opening left-brace of the inner block.)

The 'outer' variable is irretrievable lost when the 'inner' variable is declared

If a do...while structure is used:

The body of the loop will execute at least one

Which of the following statements is false?

The commas used to separate the arguments in a function call are comma operators.

Call-by-reference can achieve the security of call-by-value when

The const qualifier is used

All of the following are true of functions except:

The definition of a function usually is visible to other functions

Which of the following is not included in a function's activation record?

The name of the function

The argument list of a function call must match, or be consistent with, the parameter list of the called function in all of the following details, except:

The names of arguments/parameters in the list

Which of the following does the C++ compiler not examine in order to select the proper overloaded function to call?

The return type of the function

If a variable is declared in the initialization expression of a for statement, then:

The scope of the variable is restricted to that for loop

An uninitialized local variable contains:

The value last stored in the memory location reserved for that variable

Which of the following is not true of static local variables?

They're accessible outside of the function in which they define

The unary scope resolution operator is used

To access a global variable when a local variable of the same name is in scope

If the function Int volume ( int x = 1, int y = 1, int z = 1 ); Is called by the expression volume ( 3), how many default arguments are used?

Two

End-of-line comments that should be ignored by the compiler are denoted using:

Two forward slashes ( // )

The rand function generates a data value of the type

Unsigned int

Which of the following is a poor programming practice?

Using floating-point values for counters in counter-controlled repetition

Which of the following statements about the for statement is false?

You must declare the control variable before the for statement

Which of the following is false?

You should always try to write the fastest, smallest code possible before attempting to make it simple and correct

Which of the following is the escape character?

\

The escape sequence for a newline is:

\n

What will be the output after the following C++ statements have been executed? int a, b, c, d; a=4; b=12; c=37; d=51; if(a<b) cout<<"a<b"<<endl; if(a>b) cout<<"a>b"<<endl; if(d<=c) cout<<"d<=c"<<endl; if(c!=d) cout<<"c!=d"<<endl;

a<b c!=d

Float and double variables should be used

as approximated representations of decimal numbers

Which of the following will not increment c by 1?

c + 1;

Which of the following does not perform the following task: Display correct if answer is equal to 7 and incorrect if answer is not equal to 7?

cout << answer == 7 ? "correct" : "incorrect";

Which of the following is a repetition statement?

do...while

Which of the following for headers is not valid?

for ( int i = 0; int j = 5; ; i++ )

The expression if ( num!= 65 ) cannot be replaced by:

if ( !(num - 65) )

Which of the following statements does not overwrite a preexisting value stored in a memory location?

int a;

Which of the following is a variable declaration statement?

int total;

Converting from type __ to type __ will result in the loss of data.

int, char

A block:

is a compound statement

Variables are also known as:

lvalues, but can be used as rvalues

Depending on the circumstances, the compiler may ignore the storage class specifier:

register

Which of the following is not one of the C++ control structures?

select

Which of the following is a parameterized stream manipulator used to format output?

setw

The __ object enables a program to read data from the user

std::cin

Which of the following statements could potentially change the value of number2?

std::cin >> number2;

Which of the following statements would display the phrase C++ is fun?

std::cout << "\"C++ is fun\"";

Which of the following is not a syntax error?

std::cout<<"Hello world! ";

Which of the following code segments prints a single line containing hello there with the words separated by a single space?

std::cout<<"hello"; std::cout<<" there";

What is wrong with the following while loop? while ( sum <= 1000 ) sum = sum - 30;

sum = sum - 30 should be sum = sum +30 or else the loop may never end

If x initially contains the value 3, which of the following sets x to 7?

x += 4;

Assuming that x and y are equal to 3 and 2, respectively, after the statement x-=y executes, the values of x and y will be:

x: 1; y: 2

In the expression n = x + rand () % y;

y is the scaling value

Assuming that x is equal to 4, which of the following statements will not result in y containing the value 5 after execution?

y=x++


Kaugnay na mga set ng pag-aaral

Geography CH 14: Northern Europe

View Set

PSYC336_Chapter 14 - Cognitive Development in Adolescence

View Set

Pathophysiology Porth's ch. 15 Disorders of the Immune Response

View Set