C++ Final

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

What will the value of x be after the following statements execute? int x; x = 18 % 4;

2

search

A ________ algorithm is a method of locating a specific item of information in a larger collection of data.

default

A ________ argument is passed to a parameter when the actual argument is left out of the function call.

buffer

A file ________ is a small holding section of memory that file-bound information is first written to.

only one

A function can have zero to many parameters, and it can return this many values.

still points to a valid object after the function ends

A function may return a pointer, but the programmer must ensure that the pointer ________.

to prevent changes to the structure members

A good reason to pass a structure as a constant reference is ________.

Preprocessor directive

A statement that starts with a # symbol is called a:

can

A structure ________ contain members of the same data type.

rows, columns

A two-dimensional array can be viewed as ________ and ________.

several identical arrays

A two-dimensional array is like ________ put together.

binary, linear

A(n) ________ search is more efficient than a ________ search.

Linear

A(n) ________ search uses a loop to sequentially step through an array.

string names[5];

An array of string objects that will hold 5 names would be declared using which statement?

sorted

Array elements must be ________ before a binary search can be performed.

initialized, declared

Arrays may be ________ at the time they are ________.

left to right

Associativity is either right to left or:

-3

Assume that x is an int variable. What value is assigned to x after the following assignment statement is executed?

saved to the file

Closing a file causes any unsaved information still held in the file buffer to be ________.

from lowest to highest value

Data that is sorted in ascending order is ordered ________.

abstract data types (ADT)

Data types that are created by the programmer are known as ________.

EXIT_SUCCESS

EXIT_FAILURE and ________ are named constants that may be used to indicate success or failure when the exit() function is called.

computeValue(10);

Here is the header for a function named computeValue: void computeValue (int value)

1000

How many elements does the following array have? int bugs[1000]

19

How many times will the following loop display "Hello"? for (int i = 1; i < 20; i++) cout << "Hello!" << endl;

Curly braces { }

If you intend to place a block of statements within an if statement, you must place these around the block.

for

If you want a user to enter exactly 20 values, which loop would be the best to use?

strongly typed enum

In C++ 11 you can use a new type of enum, known as a(n) ________, (also known as an enum class) to have multiple enumerators with the same name, within the same scope.

initialization

In a for statement, this expression is executed only once.

assigns the dereferenced pointer's value, then increments the pointer's address

Look at the following statement: sum += *array++;

a member

Look at the following structure declaration. struct Employee { string Employee string name; int idNum; }; In this declaration, idNum is:

Subscripts

Objects in an array are accessed with ________, just like any other data type in an array.

guarantees not to result in changes to the structure's members

Passing a structure as a constant reference parameter to a function ________.

None of These

Regardless of the algorithm being used, a search through an array is always performed ________.

null terminator

The ________ is automatically appended to a character array when it is initialized with a string constant.

cout object

The ________ is/are used to display information on the computer's screen.

selection, bubble

The ________ sort usually performs fewer exchanges than the ________ sort.

addition and subtraction

The contents of pointer variables may be changed with mathematical statements that perform ________.

Logical

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

Default

These types of arguments are passed to parameters automatically if no argument is provided in the function call.

dot operator

This allows you to access structure members.

ifstream

This data type can be used to create files and read information from them into memory.

ofstream

This data type can be used to create files and write information to them but cannot be used to read information from them.

function

This is a collection of statements that performs a specific task.

stub

This is a dummy function that is called instead of the actual function it represents.

for

This loop is a good choice when you know how many times you want the loop to iterate in advance of entering the loop.

Left

This manipulator causes the field to be left-justified with padding spaces printed to the right.

ios::failbit

This state bit is set when an attempted operation has failed.

Private

This type of member function may be called only from a function that is a member of the same class.

local

This type of variable is defined inside a function and is not accessible outside the function.

push_back

This vector function is used to insert an item into a vector.

pop_back

This vector function removes an item from a vector.

a loop to assign the elements of one array to the other array

To assign the contents of one array to another, you must use ________.

one or more file stream objects

To set up a file to perform file I/O, you must declare:

True

True/False: A preprocessor directive does not require a semicolon at the end.

True

True/False: A private member function is useful for tasks that are internal to the class, but is not directly called by statements outside the class.

True

True/False: A while loop's body can contain multiple statements, as long as they are enclosed in braces.

False

True/False: Although two-dimensional arrays are a novel idea, there is no known way to pass one to a function.

True

True/False: Any mathematical operations that can be performed on regular C++ variables can be performed on structure members.

True

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

False

True/False: Assume array1 and array2 are the names of arrays. To assign the contents of array2 to array1, you would use the following statement. array1 = array2;

False

True/False: Before you can perform a selection sort, the data must be stored in ascending order.

False

True/False: By default, files are opened in binary mode.

True

True/False: C++ does not have a built in data type for storing strings of characters.

True

True/False: If you do not declare a destructor function, the compiler will furnish one automatically.

True

True/False: In C++ 11, you can use smart pointers to dynamically allocate memory and not worry about deleting the memory when you are finished using it.

False

True/False: In C++, it is impossible to display the number 34.789 in a field of 9 spaces with 2 decimal places of precision.

True

True/False: It is legal to subtract a pointer variable from another pointer variable.

False

True/False: Local variables are initialized to zero by default.

False

True/False: The default section is required in a switch statement.

True

True/False: The number of comparisons made by a binary search is expressed in powers of two.

True

True/False: The only difference between the get function and the >> operator is that get reads the first character typed, even if it is a space, tab, or the [Enter] key.

False

True/False: The setprecision manipulator cannot be used to format data written to a file.

True

True/False: The structure pointer operator is used to dereference a pointer to a structure, not a pointer that is a member of a structure.

True

True/False: You may use the exit() function to terminate a program, regardless of which control mechanism is executing.

True

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

Declares a pointer variable named num2

What does the following statement do? double *num2;

1

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;

%

What is the modulus operator?

1 1 1 ... and on forever

What is the output of the following code segment? n = 1; for ( ; n <=5 ) cout << n << ' '; n++;

77

What is the output of the following program? #include <iostream> using namespace std; class TestClass { public: TestClass(int x) {cout << x << endl; } TestClass( ) { cout << "Hello!" << endl; } }; int main ( ) { TestClass(77); return 0; }

13

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;

False

What is the value of the following expression? true && false

True

What is the value of the following expression? true && true

6

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

The number is number

What will the following code display? int number = 7; cout << " The number is " << "number" << endl;

The address of the number variable

What will the following code output? int number = 22 int *var = &number; cout << var << endl;

4

What will the value of x be after the following statements execute? int x; x = 18 / 4;

at the beginning of the file

When a file is opened, the file stream object's "read position" is ________.

Inline

When the body of a member function is defined inside a class declaration, it is said to be ________.

cmath

When using the sqrt function you must include this header file.

10

Which line in the following program contains a call to 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( ) 11 cout << x << endl; 12 return 0; 13 } 14 15 void showDub(int num) 16 { 17 cout << (num * 2) << endl; 18 }

6

Which line in the following program will cause a compiler error? 1 #include <iostream> 2 using namespace std; 3 4 int main( ) 5{ 6 const int MY_VAL; 7 MY_VAL = 77; 8 cout << MY_VAL << enl; 9 return 0; 10}

7

Which line in the following program will cause a compiler error? 1 #include <iostream> 2 using namespace std; 3 4 int main ( ) 5 { 6 const int MY_VAL = 77; 7 MY_VAL == 99; 8 cout << MY_VAL << endl 9 return 0; 10 }

dataFile.open("info.dat", ios::out | ios::app);

Which statement opens a file in such a way that information will only be written to its end?

99

Which value can be entered to cause the following code segment to display the message: "That number is acceptable."

indirectly

With pointer variables, you can ________ manipulate data stored in other variables.

Array Names

________ can be used as pointers.

getline

________ reads a line of input, including leading and embedded spaces, and stores it in a string object.

Variable

________ represent storage locations in the computer's memory.


Set pelajaran terkait

Contreras Macroeconomics Exam 2 - Auburn

View Set

Chp 39 PrepU-Oxygenation and Perfusion

View Set

Supply Chain Chapter 9: Logistics

View Set