CMPSC Exam 2 Quiz Practice

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

unique_ptr<int> uniq( new int );

&

elect all that apply. Select as many of the following options that make this sentence true: The contents of pointer variables may be changed with mathematical statements that perform

+ -

Select all that apply. The motivation for modular programming include:

- Code reusibilty - Improves maintainability of programs.

Select all that apply. Which of the following must be included in a function header?

-Name of Function -Data Type of each Parameter -Names of parameter variables

What will the following code display? int numbers[] = {99, 87, 66, 55, 101};cout << numbers[3] << endl;

55

What will the following code display? int number = 6;cout << number++ << " " << number << endl;

6 7

What will the following code display? #include <iostream>using namespace std; void doSomething(int);int main(){ int x = 7; cout << x << endl; doSomething(x+2); cout << x << endl; return 0;}void doSomething(int num){ cout << num << endl;num += 2;}

7 9 7

What will be displayed after the following statements execute? int funny = 9, serious = 17;funny = serious % 3;if (funny != 1){ funny = 9; serious = 9;}else if (funny >= 2){ funny = 8; serious = 8;}else{ funny = 1; serious = 1;}cout << funny << " " << serious << endl;

9 9

An expression that has any value other than 0 is considered false by an if statement.

False

In the following statements, no short circuit will occur int x = 12, y = 5, z = -4; x >= 10 || y > z || x >= y

False

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

False

The setprecision(n) manipulator causes a number to be displayed decimal notation for floating-point values.

False

The update expression of a for loop cannot contain multiple statements, for example: for (int k = 1, total = 100; total < 10000 && k <= 100; n++, total += k * 2)

False

You may nest while and do-while loops but you may not nest for loops.

False

This operator uses the value in context and then decrements the value of its operand.

Postfix Decrement

A function ___________ eliminates the need to place a function definition before all calls to the function.

Prototype

A vector object automatically expands in size to accommodate the items stored in it.

True

The value of the result in the following expression will be 100 if x has the value of 110. result = x >= 110 ? 100 : 110;

True

Using reference variables as parameters provides a way for the function to 'return' more than one value

True

For the following C++ types, which type has the lowest ranking for type conversion?

int

Which of the following function prototype is incorrectly defined?

long thatFunct (Long =0, int, int , short int)

Which of the following manipulators is used to establish a field width for the value that follows it?

setw

Use the delete operator only on pointers that were

Created with the new operator

Given the following function: void sum(int a, int& b, int c){ int d; d = a + c; b = d * 4; a = a + d;c = c + a;} What is the output of the following code segment that invokes calc(): int x = 1;int y = 2;int z = 1;calc(x, y, z);cout << x << " " << y << " " << z << endl;

1 8 1

Select all that apply. Given: x = 5, y = 6, z = 8. Which of the following are true? x == 5; x < (y + 2); z <= 4; y > (z - x); z >= (y + x)

1, 2, 4

What is the value of the number after the following statements execute? int number = 12; number *= 3; number %= 13; number /= 2; number += 7;

12

What is the value of the cube after the following code executes? double cube, side; side = 5.0; cube = pow(side, 3.0)

125

After the following code executes, what is the value of my_value if the user enters 0? cin >> my_value; if (my_value > 5) my_value = my_value + 5; else if (my_value > 2) my_value = my_value + 10; else my_value = my_value + 15;

15

What is the value of w after the following code executes? double w; z = 7 / (int)9.5 + 18.5;

18.5

How many times will the following loop display "Looping!"? for (int i = 20; i > 0; i--) cout << "Looping!" << endl;

20

How many times will the following loop display "Ok!"? for (row = 1; row <= 4; row++) for (col = 1; col <= 7; col++) cout << "Ok!" << endl

28

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;}

99

Which of the following statements is invalid C++ code?

All are invalid

Unlike regular variables, __________ can hold multiple values.

Arrays

Subscript numbering in C++ array

Begins with zero

What does the following statement mean? double *num2;

Declares a pointer variable named num2

A collection of statements that performs a specific task is a(n)

Function

Something within a do-while loop must eventually cause the condition to become false or a(n) __________ results. (assuming no break statement is used)

Infinite Loop

In a for statement, which of the following expression is executed only once?

Initialization

What does the following statement do? vector<int> v(10, 2);

It creates a vector object with a starting size of 10 and initializes all the elements with the value 2.

These operators connect two or more relational expressions into one or reverse the logic of the expression.

Logical

The name of an array store the __________ of the first array element.

Memory Address

An array can store a group of values, but the values must be

Same data type

Assuming ptr is a pointer variable, what will the following statement output? cout << *ptr;

The value stored in the variable whose address is contained in ptr

What is the output of the following code segment? int x = 5 - 3;if (x = 2) cout << "This is true!" << endl;else cout << "This is false!" << endl; cout << "That's all, folks!" << endl;

This is true! Thats all Folks!

A pointer can be used as a function argument, giving the function access to the original argument.

True

Global variables are initialized to zero or NULL by default.

True

When using the rand() function alone will always generate the same series of random numbers.

True

cin will stop reading if the variable and the input have mismatch types.

True

Which of the following return value in a function's return statement is incorrect?

Void

To read and write data from and to a file, you define an object of the __________ data type.

fstream

Which of the following statements will read an entire line of input into the string object address?

get line (cin, address);

Which of the following is a valid C++ array definition?

int size [10];

To use setprecision(2), which header file is required?

iomanip

In C++11, the __________ keyword was introduced to represent address 0.

nullptr

When the less than operator (<) is used between two pointer values, the expression is testing whether

the address of the first variable comes before the address of the second variable in the computer's memory

Which of the following defines a unique_ptr named uniqthat points to a dynamically allocated int?

unique_ptr<int> uniq( new int );

Which statement correctly uses C++11 to initialize a vector of ints named n with the values 10 and 20?

vector<int> n {10, 20};

Which of the following expressions will determine whether y is less than x?

x > y

If you leave out the size declarator in an array definition

you must furnish an initialization list


Ensembles d'études connexes

Environmental Policy Midterm- Dr. King

View Set

Chapter 3: Vectors and Coordinate Systems

View Set