COSC - 160: Final Review

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

A default constructor has how many parameters? 0 1 2 Variable number

0

What is the value of result after the following C++ statements execute? int a{4}; Int b{12}; int c{37}; int d{51}; int result {d % a * c + a % b +a}; 127 59 51 119

119

Which statement is false? Performing a task in a program requires a method. Classes are reusable software components. A class is to an object as a blueprint is to a house. A class is an instance of its object.

A class is an instance of its object.

Which of the following statements is true? The compiler knows about fundamental types that are "built into" C++. A new type that you create is known as a user-defined type. New classes, when packaged properly, can be reused by other programmers. All of these are true.

All of these are true.

How many times will the following loop print hello? i=1; while (i<10) { cout << "hello"; } 0. 9. 10. An infinite number of times.

An infinite number of times. ??(Check)

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? x++ x += 1 ++x Any of these.

Any of these.

A switch statement should be used: To replace all if...else statements. As a multiple-selection structure. As a single-selection structure. As a double-selection structure.

As a multiple-selection structure.

In order to calculate the ________ of an array of values, the array values must first be summed. Minimum Distribution Maximum Average

Average

A recursive function is a function that: Calls itself, directly or indirectly. Takes 3 arguments. Returns a double. Is inside of another function.

Calls itself, directly or indirectly.

the delete[] operator: Can terminate the program. Must be told which destructor to call when destroying an object. Can delete an entire array of objects declared using new. Is called implicitly at the end of a program.

Can delete an entire array of objects declared using new.

Which of the following encompasses the other three? Repetition structure. Control structure. Selection structure. Sequence structure.

Control structure.

The assignment operator (=) can be used to: Compare two objects. Copy data from one object to another. Test for equality. Copy a class.

Copy data from one object to another.

The function prototype double mySqrt(int x); Defines a function called mySqrt which takes an argument of type x and returns a double. Defines a function called double which calculates square roots. Declares a function called mySqrt which takes an integer as an argument and returns a double. Declares a function called mySqrt which takes a double as an argument and returns an integer.

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

When an argument is passed-by-value, changes in the called function ________ affect the original variable's value; when an argument is passed call-by-reference, changes in the called function ________ affect the original variable's value. Do not, do not Do, do Do not, do Do, do not

Do not, do

Every object of the same class: Shares pointers to all member variables and member functions. Gets a copy of every member function and member variable. Gets a copy of every member variable. Gets a copy of every member function.

Gets a copy of every member variable.

Which of the following statements about nested if...else statements is true? In an if body, an inner if...else executes only if the outer if statement's condition is true. An if...else statement may not be nested in another nested if...else. Each if...else statement must contain only a simple condition. The statement(s) in an inner if always execute(s) if its condition is true.

In an if body, an inner if...else executes only if the outer if statement's condition is true.

(*max)(num1, num2, num3);: Is a declaration of a pointer to a function called max. Is the prototype for function max. Is the header for function max. Is a call to the function pointed to by max.

Is a call to the function pointed to by max.

Which of the following is false about a function to which a built-in array is being passed? It is able to modify the values stored in the built-in array. The built-in array's name is used as an argument in the function call. It is being passed the address of the first element in the built-in array. It always knows the size of the built-in array that is being passed.

It always knows the size of the built-in array that is being passed.

What does the following statement declare? int *countPtr, count; The declaration is invalid. Two pointers to ints. One pointer to an int and one int variable. Two int variables.

One pointer to an int and one int variable.

Which forms of inheritance are is-a relationships? All forms of inheritance are is-a relationships. Only public and private. Only public. Only public and protected.

Only public.

What will the following program segment do? int counter {1}; do { cout << counter << " "; } while (++counter <=10); Print the numbers 1 through 11. Print the numbers 1 through 9. Print the numbers 1 through 10. Cause a syntax error.

Print the numbers 1 through 10.

All of the following are true of functions except: A function call must specify the name and arguments of the function. The implementation of a function is hidden from the caller. The definition of a function usually is visible to other functions. They define specific tasks that can be used at many points in a program.

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 return address of its caller function. Local variables it has declared. Parameter values received from its caller. The name of the function.

The name of the function.

In a typical nested for loop (not a range-based for loop) used to process a two-dimensional array, following the end of each execution of the inner for loop: The inner for loop increments its counter variable. The inner for loop initializes its counter variable. The outer for loop initializes its counter variable. The outer for loop increments its counter variable.

The outer for loop increments its counter variable.

Comparing pointers and performing pointer arithmetic on them is meaningless unless: They point to arrays of the same type. They point to arrays of equal size. They point to elements of the same array. You are trying to compare and perform pointer arithmetic on the values to which they point.

They point to elements of the same array.

Parameterized stream manipulator setfill specifies the fill character that's displayed when an output is displayed in a field wider than the number of characters or digits in the output. The effect of setfill applies: Only to outputs displayed in the current statement. Until the output buffer is flushed. Until explicitly set to a different setting. Only to the current value being displayed.

Until explicitly set to a different setting.

Which of the following statements is false? Variables declared in a particular function's body are local variables, which can be used only in that function. The argument types in the member function call must be consistent with the types of the corresponding parameters in the member function's definition. A function's parameters also are local variables of that function. When a function terminates, the values of its local variables are preserved.

When a function terminates, the values of its local variables are preserved.

A member-function call can supply ________ that help the function perform its task. frameworks classes arguments parameters

arguments

Which of the following is most likely a base class of the other three? miniVan. convertible. automobile. sedan.

automobile.

Which of the following for headers produces the values from 27 through 3, decrementing by 3? for (unsigned int i{27}; i <= 3; i += 3) for (unsigned int i{27}; i >= 3; i -= 3) for (unsigned int i{27}; i > 3; i -= 3) All of these.

for (unsigned int i{27}; i >= 3; i -= 3)

Functions that are not members of a class are called ________ functions. global general isolated universal

global

Which of the following is a double-selection statement? if switch do...while if...else

if...else

Which of the following statements does not overwrite a preexisting value stored in a memory location? int a; width = length; number = 12; y = y + 2;

int a;

Which of the following is not a correct way to initialize a built-in array? int n[5]{0, 7, 0, 3, 8, 2}; int n[5]{9, 1, 9}; int n[5]{7}; int n[]{0, 7, 0, 3, 8, 2};

int n[5]{0, 7, 0, 3, 8, 2};

A class's functions can throw exceptions, such as ________ to indicate invalid data. bad_data invalid_data invalid_argument bad_argument

invalid_argument

From most restrictive to least restrictive, the access modifiers are: protected, private, public private, protected, public protected, public, private private, public, protected

private, protected, public

The default value for a string is: blanks the empty string void null

the empty string

When using exception handling, place any code that might throw an exception in a: throw block. catch block. try statement. what statement.

try statement.

The return type ________ indicates that when a function completes its task, it does not return (i.e., give back) any information to its calling function. void null virtual nullptr

void

If x initially contains the value 3, which of the following sets x to 7? x + 4 = x; x =+ 4; x += 4; x ++ 4;

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 x: 3; y: 5 x: 3; y: -1 x: 5; y: 3

x: 1; y: 2

Assume that the function call operator() is overloaded for data type String in the usual sense of selecting a substring from a larger string. For a String object string1 with the character string "ABCDEFGHI", what string does string1(4, 2) return? "EFGHI" "CD" "CDEF" "EF"

"EF"

In what order would the following operators be evaluated? -, *, /, +, % Assume that if two operations have the same precedence, the one listed first will be evaluated first. *, /, %, -, + -, *, %, +, / -, +, %, *, / +, -, /, *, %

*, /, %, -, +

A double subscripted array declared as array<array<int,5>,3> values; has how many elements? 15 10 8 13

15

Given that k is an integer array starting at location 2000, kPtr is a pointer to k and each integer is stored in 4 bytes of memory, what location does kPtr + 3 point to? 2012 2003 2006 2024

2012

Given the following function template: template <typename T> T maximum(T value1, T value2) { if (value1 > value 2) { 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. 5 and a type-mismatch error. Two error messages. 2 and 2.3.

5 and 5.2.

Consider the following code, assuming that x is an int with an initial value of 12 if(x=6) { cout << x; } What is the output? 12 6 Nothing. A syntax error is produced.

6

Assuming the following pseudocode for the Fibonacci series, what is the value of the 6th Fibonacci number (fibonacci (6))? 3. 7. 1. 5.

8

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.25. 8. 5.5. 5.

8

A class-scope variable hidden by a block-scope variable can be accessed by preceding the variable name with the class name followed by: : . ::

::

Which of the following is not an arithmetic operator? + % = -

=

What method should be used to pass an array to a function that does not modify the array and only looks at it using array subscript notation? A constant pointer to nonconstant data. A constant pointer to constant data. A nonconstant pointer to constant data. A nonconstant pointer to nonconstant data.

A constant pointer to constant data.

An activation record will be popped off the function call stack whenever: A function returns control to its caller. A function calls another function. A function declares a local variable. A function calls itself.

A function returns control to its caller.

Which of the following is false? A string can be defined to store any data type. An exception is thrown if the argument to string's at member function is an invalid subscript. Class string's overloaded [] operator returns a vector element as an rvalue or an lvalue, depending on the context. Class string provides bounds checking in its member function at.

A string can be defined to store any data type.

Which of the following is false? The last element of an array has position number one less than the array size. The position number contained within square brackets is called a subscript. A subscript cannot be an expression. All of these.

A subscript cannot be an expression.

Assuming the following constructor is provided for class Time explicit Time(int = 0, int = 0, int = 0); which of the following is not a valid way to initialize a Time object? Time t1; Time t2{22, 40}; Time t3(22, 40); All of these are valid ways to initialize a Time object.

All of these are valid ways to initialize a Time object.

Which of the following does not declare a 2-by-2 array and set all four of its elements to 0?

All of these initialize all four of the array elements to 0.

Which of the following does counter-controlled iteration require? An initial value. A condition that tests for the final value. An increment or decrement by which the control variable is modified each time through the loop. All of these.

All of these.

Returning references to non-const, private data: Is only dangerous if the binary scope resolution operator (::) is used in the function prototype. Allows private member variables to be modified, thus "breaking encapsulation." Results in a compiler error. Allows private functions to be modified.

Allows private member variables to be modified, thus "breaking encapsulation."

The type of function a client would use to check the balance of a bank account would be: A utility function. A predicate function. An access function. A constructor.

An access function.

Utility functions: Are part of a class's interface. Are intended to be used by clients of a class. Are a type of constructor. Are private member functions that support operations of the class's other member functions.

Are private member functions that support operations of the class's other member functions.

Variables defined inside a member function of a class have: Class scope. Block scope. Class or block scope, depending on whether the binary scope resolution operator (::) is used. File scope.

Block scope.

Pointers may be assigned which of the following values? Any integer values. An address. nullptr. Both An address. and nullptr.

Both An address. and nullptr.

A reference parameter: Is an alias for its corresponding argument. Is declared by following the parameter's type in the function prototype by an ampersand (&). Cannot be modified. Both Is an alias for its corresponding argument and Is declared by following the parameter's type in the function prototype by an ampersand (&).

Both Is an alias for its corresponding argument and Is declared by following the parameter's type in the function prototype by an ampersand (&).

Which of the following is false? Two arrays cannot be meaningfully compared with equality or relational operators. Arrays cannot be assigned to one another (i.e., array1 = array2;). C++ ensures that you cannot "walk off" either end of an array. An entire non-char array cannot be input or output at once.

C++ ensures that you cannot "walk off" either end of an array.

Referencing elements outside the array bounds with the [] operator: Is a syntax error. Can result in changes to the value of an unrelated variable. Is impossible because C++ checks to make sure it does not happen. Enlarges the size of the array.

Can result in changes to the value of an unrelated variable.

If the line: friend class A; appears in class B, and the line: friend class B; appears in class C, then: Class A is a friend of class C. Class C can call class A's private member functions. Class A can access private variables of class B. Class B can access class A's private variables.

Class A can access private variables of class B

Member access specifiers (public and private) can appear: In any order and multiple times, if they have brackets separating each type. In any order and multiple times. Outside a class definition. In any order (public first or private first) but not multiple times.

In any order and multiple times.

The is-a relationship represents: Inheritance. A friend. Information Hiding. Composition.

Inheritance.

All of the following are reasons to use recursion except: It maximizes execution performance. An iterative solution is not apparent. The resulting program is easier to debug. It more naturally mirrors the problem.

It maximizes execution performance.

An array is not: A consecutive group of memory locations. Subscripted by integers. Made up of different data types. None of these.

Made up of different data types.

An explicit constructor: Does not initialize its class's data members. Can be implicitly called by the compiler to perform a data type conversion. Cannot be called outside of the class it is declared in. Must take exactly one argument.

Must take exactly one argument.

The std::endl stream manipulator: Inputs a newline. Outputs a newline and flushes the output buffer. Terminates the program. Flushes the output buffer.

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"; } cout << "Passed"; Passed 60 Nothing.

Passed

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. Many copies of the function code are created. It requires large data values. Recursive functions tend to declare many local variables.

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.

Specifying the order in which statements are to be executed in a computer program is called: An algorithm. Program control. Transfer of control. Pseudocode.

Program control.

Member function definitions: Can use the scope resolution operator anywhere, but become public functions. Require the scope resolution operator only when being defined outside of the definition of their class. Must use the scope resolution operator in their function prototype. Always require the scope resolution operator (::).

Require the scope resolution operator only when being defined outside of the definition of their class.

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.) A syntax error occurs. The "outer" variable is irretrievably lost when the "inner" variable is declared. The "inner" declaration is ignored and the "outer" variable has scope even inside the inner block. The "outer" variable is hidden while the "inner" variable is in scope.

The "outer" variable is hidden while the "inner" variable is in scope.

If a do...while structure is used: The body of the loop will execute at least once. Counter-controlled iteration is not possible. An off-by-one error cannot occur. An infinite loop cannot take place.

The body of the loop will execute at least once.

To prevent modification of a built-in array's values when you pass the built-in array to a function: The built-in array parameter can be preceded by the const qualifier. The built-in array must be declared static in the function. A copy of the built-in array must be made inside the function. The built-in array must be passed by reference.

The built-in array parameter can be preceded by the const qualifier.

The compiler will implicitly create a default constructor if: The class does not contain any data members. The class already defines a default constructor. The class does not define any constructors. The programmer specifically requests that the compiler do so.

The class does not define any constructors.

The code ", have a great day!"s is an example of: a compilation error. a string iterator. string interpolation. a string-object literal.

a string-object literal.

What will be the output after the following C++ statements have been executed?

a<b; c != d; (didn't feel like typing the whole code, haha.)

Which of the following is not a correct way to initialize the array named n? array <int,5> n{0,7,0,3,8}; array <int,5> n{7}; array <int,5> n{0,7,0,3,8,2}; array <int,5> n{9,1,9};

array <int,5> n{0,7,0,3,8,2};

Given the following class definition: class CreateDestroy { public: CreateDestroy() { cout << "constructor called, "; } ~CreateDestroy() { cout << "deconstructor called, "; }; What will the following program output? int main () { CreateDestroy c1; CreateDestroy c2; return 0; } constructor called, constructor called, destructor called, destructor called, constructor called, constructor called, constructor called, destructor called, constructor called, destructor called, constructor called, destructor called,

constructor called, constructor called, destructor called, destructor called,

Given the following class definition: class CreateDestroy { public: CreateDestroy() { cout << "constructor called, "; } ~CreateDestroy() { cout << "deconstructor called, "; }; What will the following program output? int main() { for (int i = 1; i <=2; ++i) { CreateDestroy cd; } return 0; } constructor called, destructor called, constructor called, destructor called, constructor called, constructor called, constructor called, constructor called, destructor called, destructor called, Nothing.

constructor called, destructor called, constructor called, destructor called,

Which of the following is a repetition structure? do...while if...else switch if

do...while

Variables are also known as: Constant variables. lvalues, but can be used as rvalues. rvalues, and cannot be used as lvalues. lvalues, and cannot be used as rvalues.

lvalues, but can be used as rvalues.

The & operator can be applied to: lvalues. constants. rvalues. string literals.

lvalues.

C++ Standard Library function getline, from the <string> header, reads characters up to, but not including, a(n)________ (which is discarded), then places the characters in a string. newline period tab \

newline

The correct function name for overloading the addition (+) operator is: operator+ operator_+ operator:+ operator(+)

operator+

The ________ statement passes a value back to a function's caller. pass recover restore return

return

The ________, ________ and ________ are the only three forms of control necessary. break, continue, if...else sequence, selection, iteration switch, if, else for, while, do...while

sequence, selection, iteration

Which of the following gives the number of elements in the array int r[10]? sizeof (*r) sizeof r / sizeof (int) sizeof (*r) / sizeof (int) sizeof r

sizeof r / sizeof (int)

Given a built-in array of ints named values, which of the following statements would sort the array? sort(values.array_begin(), values.array_end()); sort(begin(values), end(values)); sort(array_begin(values), array_end(values)); sort(values.begin(), values.end());

sort(begin(values), end(values));

Which of the following is not a kind of inheritance in C++? private. protected. public. static.

static

Which of the following is not a syntax error? std:: cout << "Hello World! "; std:: cout << "Hello world! "; std:: cout << Hello world!; std:: cout << 'Hello world!';

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

Which of the following statements could potentially change the value of number2? std::cout<< number2; sum = number1+number2; number1=number2; std::cin>>number2;

std::cin >> number2;

Each class you create becomes a new ________ you can use to declare variables and create objects. access modifier object type variable

type

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++; y = x + 1 y = ++x; y = 5;

y = x++;


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

1.2.5 Gross Anatomy Examination Quiz - Biotechnology

View Set

Ch.8 Special Senses {HW and quiz}

View Set

Chapter 3: Social Beliefs and judgements

View Set

4.13 Unit Test: Chemical Thermodynamics - Part 1 (actual correct answers)

View Set

Path to Field Tech I and II (to advance to FT III)

View Set

Mitral stenosis and mitral regurgitation

View Set