Final Exam
In the following code, assume the myQueue object is a queue that can hold integers, and that value is an int variable. (The lines are numbered for reference purposes.) 1 myQueue.enqueue(0); 2 myQueue.enqueue(1); 3 myQueue.enqueue(2); 4 myQueue.dequeue(value); 5 myQueue.dequeue(value); 6 myQueue.dequeue(value); 7 cout << value << endl; Assume that the dequeue function, called in lines 4, 5, and 6, stores the number removed from the queue in the value variable. What will the statement in line 7 display?
2
In the following code, assume the myStack object is a stack that can hold integers, and that value is an int variable. (The lines are numbered for reference purposes.) 1 myStack.push(0); 2 myStack.push(1); 3 myStack.push(2); 4 myStack.pop(value); 5 cout << value << endl; Assume that the pop function, called in line 4, stores the number popped from the stack in the value variable. What will the statement in line 5 display?
2
Select one that apply. Given: x = 5, y = 6, z = 8. Which of the following is false? 1. x == 5; 2. z <= 4; 3. y > (z - x); 4. y <= 6
2
Using a linear search to find a value that is stored in the last element of an array of 20,000 elements, ____________ element(s) must be compared
20,000
Using a linear search to find a value that is stored in the last element of an array that contains 20,000 elements, __________ elements must be compared. a. 20,000 b. only the first two c. only half d. 2,000 e. None of these
20,000
What is the output after the following code executes? int numerator = 5; int denominator = 25; int temp = 0; temp = numerator; numerator = denominator; denominator = temp; cout << numerator << "/" << denominator << " = " << (numerator/denominator) << endl; a. 5/25 = numerator/denominator b. 5/25 = 0 c. 5/25 = 0.2 d. 25/5 = 5 e. 25/5 = 25/5
25/5 = 5
In the following code, assume the myStack object is a stack that can hold integers, and that value is an int variable. (The lines are numbered for reference purposes.) 1 myStack.push(0); 2 myStack.push(1); 3 myStack.push(2); 4 myStack.pop(value); 5 myStack.push(3); 6 myStack.pop(value); 7 cout << value << endl; Assume that the pop function, called in lines 4 and 6, stores the number popped from the stack in the value variable. What will the statement in line 7 display?
3
How many times will the following function call itself, if 5 is passed as the argument? void showMessage(int n) { if (n>0) { cout << "Good day!" << endl; showMessage(n-1); } } a) 5 b) 1 c) 4 d) An infinite number of times
5
31) 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 test(77); return 0; } A) The program runs, but with no output. B) 77 C) Hello! D) The program will not compile.
77
Which value can be entered to cause the following code segment to display the message "That number is acceptable"? int number; cin >> number; if (number > 10 && number < 100) cout << "That number is acceptable.\n"; else cout << "That number is not acceptable.\n";
99
22) To use the strlen function in a program, you must also write #include ________. A) <strlen> B) <iostring> C) <cstring> D) <stringlib> E) None of these
<cstring>
The __________ is an equality (or comparison) operator.
==
How many characters will the following statement read into the variable myString? cin >> setw(10) >> myString; a. 9 b. 10 c. 11 d. however many characters are in myString e. None of these
A
To use the rand()function, you must include the __________ header file? a. cstdlib b. cstring c. iostream d. cmath e. iomanip
A
What is true about the following statement? cout << setw(4) << num4 << " "; a. It allows four spaces for the value in num4. b. It outputs "setw(4)" before the value in num4. c. It is incorrect because it should use setw(10). d. It is incorrect because it should use setw(num4).
A
Which of the following functions tells the cin object to skip one or more characters in the keyboard buffer? a. cin.ignore b. cin.jump c. cin.hop d. cin.skip e. None of these
A
Which statement is equivalent to the following? number += 1; a. number = number + 1; b. number = 1; c. number + 1; d. number =+ 1; e. None of these
A
You can control the number of significant digits in your output with the __________ manipulator. a. setprecision b. set_precision c. to_fixed d. setfixed() e. None of these
A
structure
A C++ class is similar to one of these.
constructor, created
A ________ is a member function that is automatically called when a class object is ________.
Deleting a node that has two children offers an opportunity to use:
A and B and C
Methods of traversing a binary tree are:
A and B and C
data type
A class is a(n) ________ that is defined by the programmer.
only one
A class may have this many default constructor(s).
The advantage a linked list has over a vector is:
A node can be inserted into or removed from a linked list faster than from a vector
15) A practical application of this function is to allow a user to enter a response of 'y' or 'Y' to a prompt. A) tolower B) toupper C) A or B D) ignorecase E) None of these
A or B
Given the if/else statement: if (a < 5) b = 12; else d = 30; Which of the following performs the same operation?
A) a < 5 ? b = 12 : d = 30;
5) ________ can be used as pointers. A) Array names B) Numeric constants C) Punctuation marks D) All of these E) None of these
A) Array names
8) The ________ marker is the character that marks the end of a file, and is automatically written when the file is closed. A) End of File (EOF) B) No More Data (NMD) C) Data Stream Close (DSC) D) Data Read Stop (DRS) E) None of these
A) End of File (EOF)
6) What is true about the following statement? out.open("values.dat", ios::app); A) If the file already exists, its contents are preserved and all output is written to the end of the file. B) If the file exists, it should be replaced with a new copy of values.dat. C) If the file exists, it can be opened but not modified. D) None of these
A) If the file already exists, its contents are preserved and all output is written to the end of the file.
6) What is true about the following statement? out.open("values.dat", ios::app); A) If the file already exists, its contents are preserved and all output is written to the end of the file. B) If the file exists, it should be replaced with a new copy of values.dat. C) If the file exists, it can be opened but not modified. D) None of these
A) If the file already exists, its contents are preserved and all output is written to the end of the file.
32) What will the following code output? int number = 22; int *var = &number; cout << var << endl; A) The address of the number variable B) 22 C) An asterisk followed by 22 D) An asterisk followed by the address of the number variable
A) The address of the number variable
19) Assuming ptr is a pointer variable, what will the following statement output? cout << *ptr; A) The value stored in the variable whose address is contained in ptr. B) The string "*ptr". C) The address of the variable stored in ptr. D) The address of the variable whose address is stored in ptr. E) None of these
A) The value stored in the variable whose address is contained in ptr.
7) An insertion or deletion routine requires that you create this many pointers for use during the traversal process. A) Two—one for the node being inspected, and one for the previous node. B) Two—one for the node being inspected, and one for the next node. C) One—for the node being inserted or deleted D) Three—one for the inspected node, one for the next node, and one for the following node
A) Two—one for the node being inspected, and one for the previous node.
17) The last node in a linked list points to ________. A) a null pointer B) the previous node C) the first node in the list D) nothing. It does not contain a pointer. E) None of these
A) a null pointer
13) If new data needs to be added to a linked list, the program simply ________ and inserts it into the series. A) allocates another node B) removes a node C) borrows a node from the compiler D) Either B or C E) None of these
A) allocates another node
24) This type of list does not contain a null pointer at the end of the list. A) circular-linked B) doubly-linked C) backwards-linked D) null-linked E) None of these
A) circular-linked
22) All stream objects have ________, which indicate the condition of the stream. A) error state bits B) condition statements C) markers D) intrinsic error messages E) None of these
A) error state bits
23) This state bit is set when an attempted operation has failed. A) ios::failbit B) ios::badbit C) ios::hardfail D) ios::goodbit E) None of these
A) ios::failbit
The QuickSort algorithm is used to sort ________. A) lists stored in arrays or linear linked lists B) tree data structures C) randomly-ordered files D) All of these E) None of these
A) lists stored in arrays or linear linked lists
21) Not all arithmetic operations may be performed on pointers. For example, you cannot ________ or ________ a pointer. A) multiply, divide B) add, subtract C) +=, -= D) increment, decrement E) None of these
A) multiply, divide
7) In C++ 11, the ________ key word was introduced to represent the address 0. A) nullptr B) NULL C) weak_ptr D) All of these E) None of these
A) nullptr
3) This data type can be used to create files and write information to them but cannot be used to read information from them. A) ofstream B) ifstream C) afstream D) outstream E) None of these
A) ofstream
This data type can be used to create files and write information to them but cannot be used to read information from them. A) ofstream B) ifstream C) afstream D) outstream E) None of these
A) ofstream
19) Closing a file causes any unsaved information still held in the file buffer to be ________. A) saved to the file B) deleted C) retained in the buffer for safekeeping D) duplicated E) None of these
A) saved to the file
12) A function may return a pointer, but the programmer must ensure that the pointer ________. A) still points to a valid object after the function ends B) has not been assigned an address C) was received as a parameter by the function D) has not previously been returned by another function E) None of these
A) still points to a valid object after the function ends
26) If you are using an older compiler that does not support the C++ 11 standard, you should initialize pointers with ________. A) the integer 0, or the value NULL B) the null terminator '\0' C) a nonzero value D) All of these E) None of these
A) the integer 0, or the value NULL
An operation that can be performed on a binary search tree is:
A. B. and C
AA Final
AA Exam
ADT stands for:
Abstract Data Type
14) "Whitespace" encompasses which of the following? A) tab B) newline C) space D) All of these E) None of these
All of these
A practical application of the stack data type in a computer system is:
All of these
Data structures that can dynamically store elements and can grow and shrink in size are:
All of these
Input values should always be checked for
All of these
Binary trees may be implemented as templates, but any data types used with them must support the ________ operator.
All of these < > ==
Multiple inheritance opens the opportunity for a derived class to have ________ members.
Ambiguous
How many times will the following function call itself, if 5 is passed as the argument? void showMessage(int n) { if (n>0) { cout << "Good day!" << endl; showMessage(n+1); } } a) 5 b) 1 c) 4 d) An infinite number of times
An infinite number of times
myCar.accelerate();
Assume that myCar is an instance of the Car class, and that the Car class has a member function named accelerate. Which of the following is a valid call to the accelerate member function?
In the following statement, what will be executed first according to the order of precedence? result = 6 - 3 * 2 + 7 - 10 / 2; a. 6 - 3 b. 3 * 2 c. 2 + 7 d. 10 / 2 e. 7 - 10
B
The __________ causes a program to wait until information is typed at the keyboard and the [Enter] key is pressed. a. output stream b. cin object c. cout object d. preprocessor e. None of these
B
What is the value of result after the following statement executes? result = (3 * 5) % 4 + 24 / (15 - (7 - 4)); a. -6.4 b. 5 c. 1.6 d. 2.25 e. None of these
B
What is the value of x after the following code executes? int x; x = 3 / static_cast<int>(4.5 + 6.4); a. 0.3 b. 0 c. 0.275229 d. 3.3 e. None of these
B
When C++ is working with an operator, it strives to convert operands to the same type. This is known as a. type correction b. type conversion c. promotion d. demotion e. None of these
B
When a variable is assigned a number that is too large for its data type, it a. underflows b. overflows c. reverses d. converts e. None of these
B
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 } a. line 6 b. line 7 c. line 8 d. line 9 e. there will be no compiler error
B
Which of the following must be included in any program that uses the cin object? a. compiler b. the header file iostream c. linker d. brackets e. None of these
B
Which statement is equivalent to the following? number = number * 2; a. number = pow(number, 2); b. number *= 2; c. number = number * number; d. number * 2 = number; e. None of these
B
__________ reads a line of input, including leading and embedded spaces, and stores it in a string object. a. cin.get b. getline c. cin.getline d. get e. None of these
B
31) What will the following code output? int number = 22; int *var = &number; cout << *var << endl; A) The address of the number variable B) 22 C) An asterisk followed by 22 D) An asterisk followed by the address of the number variable
B) 22
16) What will the following statement output? cout << &num1; A) The value stored in the variable called num1 B) The memory address of the variable called num1 C) The number 1 D) The string "&num1" E) None of these
B) The memory address of the variable called num1
29) A pointer variable may be initialized with ________. A) any non-zero integer value B) a valid address in the computer's memory C) an address less than 0 D) A and C only E) None of these
B) a valid address in the computer's memory
27) Every byte in the computer's memory is assigned a unique ________. A) pointer B) address C) dynamic allocation D) name E) None of these
B) address
1) The ________, also known as the address operator, returns the memory address of a variable. A) asterisk ( * ) B) ampersand ( & ) C) percent sign (%) D) exclamation point ( ! ) E) None of these
B) ampersand ( & )
20) To build a list initially, you can use a(n) ________ routine. A) build B) append C) constructor D) initialization E) None of these
B) append
25) To insert a new node in ascending order into a list, the list must be: A) arranged in descending order B) arranged in ascending order C) randomly ordered D) empty
B) arranged in ascending order
21) When a file is opened, the file stream object's "read position" is ________. A) at the end of the file B) at the beginning of the file C) nonexistent, until the programmer declares it D) in the middle of the file E) None of these
B) at the beginning of the file
A recursive function is designed to terminate when it reaches its ________. A) return statement B) base case C) closing curly brace D) last parameter E) None of these
B) base case
18) Which statement opens a file in such a way that information will only be written to its end? A) dataFile(open.append("info.dat")); B) dataFile.open("info.dat", ios::out | ios::app); C) dataFile.open = "C:\\info.dat" ios:append; D) open(dataFile.append); E) None of these
B) dataFile.open("info.dat", ios::out | ios::app);
10) The list container provided by the Standard Template Library is a template version of a ________. A) singly-linked list B) doubly-linked list C) circular-linked list D) backward-linked list E) None of these
B) doubly-linked list
5) Which statement opens a file and links it to a file stream object? A) open(aFile) = link(anObject); B) file.open("c:\\filename.txt"); C) linkstream("filename.txt"); D) link(open(filename.txt")); E) None of these
B) file.open("c:\\filename.txt");
10) This member function reads a single character from a file. A) read B) get C) put D) input E) None of these
B) get
3) The ________ of a linked list points to the first node in the list. A) starter B) head C) tail D) declaration E) None of these
B) head
1) Data stored here disappears once the program stops running or the computer is powered down. A) on a CD B) in RAM C) on a backup tape D) on the disk drive E) None of these
B) in RAM
When function A calls function B, which in turn calls function A, this is known as: A) direct recursion B) indirect recursion C) function swapping D) perfect recursion E) None of these
B) indirect recursion
9) This state bit can be tested to see if the end of an input stream is encountered. A) ios::eof B) ios::eofbit C) ios::failbit D) ios::badbit E) None of these
B) ios::eofbit
19) While traversing a list, a node pointer knows when it has reached the end of a list when: A) it encounters the newline character B) it encounters a null pointer C) it finds itself back at the beginning of the list D) it encounters a sentinel, usually 9999 E) None of these
B) it encounters a null pointer
13) To set up a file to perform file I/O, you must declare: A) at least one variable, the contents of which will be written to the file B) one or more file stream objects C) a string object to store the file contents D) All of these E) None of these
B) one or more file stream objects
18) A ________ is used to travel through a linked list and search for data. A) node B) pointer C) null pointer D) traversal operator E) None of these
B) pointer
The ________ algorithm uses recursion to efficiently sort a list. A) shell sort B) quicksort C) binary sort D) red/black sort E) None of these
B) quicksort
35) To help prevent memory leaks from occurring in C++ 11, a ________ automatically deletes a chunk of dynamically allocated memory when the memory is no longer being used. A) null pointer B) smart pointer C) dereferenced pointer D) A and C only E) None of these
B) smart pointer
22) A linked list class must take care of removing the dynamically allocated nodes. This is done by ________. A) the constructor function B) the destructor function C) overriding the removal function D) overloading the memory persistence operator E) None of these
B) the destructor function
5) The process of moving through a linked list is referred to as ________ the list. A) cruising B) traversing C) node-hopping D) alternating E) None of these
B) traversing
The QuickSort algorithm works on the basis of A) three sublists B) two sublists and a pivot C) two pivots and a sublist D) three pivots E) None of these
B) two sublists and a pivot
8) How many steps are involved in the process of deleting a node? A) one—delete the node from memory B) two—remove the node without breaking links, then delete it from memory C) three—create a blank node, remove the node being deleted, insert the blank, then delete the node D) four—create a blank, remove the node being deleted, insert the blank, delete the node, delete the blank E) None of these
B) two—remove the node without breaking links, then delete it from memory
24) Dynamic memory allocation occurs ________. A) when a new variable is created by the compiler B) when a new variable is created at runtime C) when a pointer fails to dereference the right variable D) when a pointer is assigned an incorrect address E) None of these
B) when a new variable is created at runtime
11) This member function can be used to store binary data to a file. A) binary.out B) write C) put << D) dataout(binary) E) None of these
B) write
The head pointer, anchored at the top of a binary tree, is called the ________.
B. tree pointer
A recursive function should be designed to stop making recursive calls when it reaches its ________.
Base case
What will be displayed after the following statements execute? int num1 = 5; int num2 = 3; cout << "The result is " << (num1 * num2 + 10) << endl; a. The result is 5 * 3 + 10 b. The result is (num1 * num2 + 10) c. The result is 25 d. The result is 65 e. None of these
C
When a user types values at the keyboard, those values are first stored a. as ASCII characters b. in the header file iostream c. in the keyboard buffer d. as integers e. None of these
C
When the final value of an expression is assigned to a variable, it will be converted to a. the smallest C++ data type b. the largest C++ data type c. the data type of the variable d. the data type of the expression e. None of these
C
Which of the following statements will allow the user to enter three values to be stored in variables length, width, and height, in that order? a. cin << length, width, height; b. cin.get(height, width, length); c. cin.get(length, width, height); d. cin >> length; width; height; e. cin.get(length >> width >> height);
C
Which of the following statements will pause the screen until the [Enter] key is pressed? a. cin; b. cin.getline(); c. cin.get(); d. cin.ignore(); e. cin.input();
C
Which of the following will allow the user to input the values 15 and 20 and have them stored in variables named base and height, respectively? a. cin << base << height; b. cin base, height; c. cin >> base >> height; d. cin base >> cin height; e. None of these
C
12) To access files from a C++ program, you must use this directive: A) #include<fileaccess> B) #include <filestream> C) #include <fstream> D) #include <iostream> E) None of these
C) #include <fstream>
20) The ________ and ________ operators can be used to increment or decrement a pointer variable. A) addition, subtraction B) modulus, division C) ++, -- D) All of these E) None of these
C) ++, --
How many times will the following function call itself, if the value 5 is passed as the argument? void showMessage(int n) { if (n > 0) { cout << "Good day!" << endl; showMessage(n - 1); } } A) 1 B) 4 C) 5 D) An infinite number of times
C) 5
14) The advantage a linked list has over a vector is: A) A linked list can dynamically shrink or grow, and a vector cannot B) A linked list is smaller than a vector C) A node can be inserted into or removed from a linked list faster than from a vector D) Data removal and insertion are more accurate with a linked list than with a vector E) None of these
C) A node can be inserted into or removed from a linked list faster than from a vector
1) ADT stands for: A) Algorithm Dependent Template B) Algorithm Driven Template C) Abstract Data Type D) Automatic Data Type E) None of these
C) Abstract Data Type
The QuickSort algorithm was developed in 1960 by ________. A) Bjarne Stroustrup B) Tony Gaddis C) C.A.R. Hoare D) C.M. Turner E) None of these
C) C.A.R. Hoare
2) In order, the three-step process of using a file in a C++ program involves: A) Insert a disk, open a file, remove the disk B) Create the file contents, close the file, name the file C) Open the file, read/write/save data, close the file D) Name the file, open the file, delete the file E) None of these
C) Open the file, read/write/save data, close the file
In order, the three-step process of using a file in a C++ program involves: A) Insert a disk, open a file, remove the disk B) Create the file contents, close the file, name the file C) Open the file, read/write/save data, close the file D) Name the file, open the file, delete the file E) None of these
C) Open the file, read/write/save data, close the file
17) A pointer variable is designed to store ________. A) any legal C++ value B) only floating-point values C) a memory address D) an integer E) None of these
C) a memory address
6) The contents of pointer variables may be changed with mathematical statements that perform ________. A) all mathematical operations that are legal in C++ B) multiplication and division C) addition and subtraction D) B and C E) None of these
C) addition and subtraction
15) When this is placed in front of a variable name, it returns the address of that variable. A) asterisk ( * ) B) conditional operator C) ampersand ( & ) D) semicolon ( ; ) E) None of these
C) ampersand ( & )
The programmer must ensure that a recursive function does not become: A) a static function B) a virtual function C) an endless loop D) a dynamic function E) None of these
C) an endless loop
25) The following statement: int *ptr = new int; A) results in a compiler error B) assigns an integer less than 32767 to the variable named ptr C) assigns an address to the variable named ptr D) creates a new pointer named int E) None of these
C) assigns an address to the variable named ptr
10) Look at the following statement: sum += *array++; This statement ________. A) is illegal in C++ B) will always result in a compiler error C) assigns the dereferenced pointer's value, then increments the pointer's address D) increments the dereferenced pointer's value by one, then assigns that value E) None of these
C) assigns the dereferenced pointer's value, then increments the pointer's address
11) Use the delete operator only on pointers that were ________. A) never used B) not correctly initialized C) created with the new operator D) dereferenced inappropriately E) None of these
C) created with the new operator
14) ofstream, ifstream, and fstream are: A) header files B) libraries C) data types D) string arrays E) None of these
C) data types
14) Which of the following statements deletes memory that has been dynamically allocated for an array? A) int array = delete memory; B) int delete[ ]; C) delete [] array; D) new array = delete; E) None of these
C) delete [] array;
12) In a circular-linked list, the last node points to the ________. A) head pointer B) tail pointer C) first node D) closing curly brace of the original structure declaration E) None of these
C) first node
4) This data type can be used to create files, read data from them, and write data to them. A) ofstream B) iftream C) fstream D) stream E) None of these
C) fstream
15) This data type can be used to create files and read information from them into memory. A) ofstream B) istream C) ifstream D) instream E) None of these
C) ifstream
2) With pointer variables, you can ________ manipulate data stored in other variables. A) never B) seldom C) indirectly D) All of these E) None of these
C) indirectly
17) When used by itself, this access flag causes a file's contents to be deleted if the file already exists. A) ios::app B) ios::in C) ios::out D) All of these E) None of these
C) ios::out
18) Look at the following statement: int *ptr = nullptr; In this statement, what does the word int mean? A) The variable named *ptr will store an integer value. B) The variable named *ptr will store an asterisk and an integer value. C) ptr is a pointer variable that will store the address of an integer variable. D) All of these E) None of these
C) ptr is a pointer variable that will store the address of an integer variable.
34) Look at the following code: int numbers[] = {0, 1, 2, 3, 4 }; int *ptr = numbers; ptr++; After this code executes, which of the following statements is true? A) ptr will hold the address of numbers[0]. B) ptr will hold the address of the 2nd byte within the element numbers[0]. C) ptr will hold the address of numbers[1]. D) This code will not compile.
C) ptr will hold the address of numbers[1].
24) This member function writes a single character to a file. A) get B) write C) put D) insert E) None of these
C) put
25) This term means non-sequentially accessing information in a file. A) linear access B) incremented access C) random access D) protected access E) None of these
C) random access
A ________ function is one that calls itself A) dynamic B) static C) recursive D) data validation E) None of these
C) recursive
4) When you work with a dereferenced pointer, you are actually working with ________. A) a variable whose memory has been allocated B) a copy of the value pointed to by the pointer variable C) the actual value of the variable whose address is stored in the pointer variable D) All of these E) None of these
C) the actual value of the variable whose address is stored in the pointer variable
30) If a variable uses more than one byte of memory, for pointer purposes its address is ________. A) the address of the last byte of storage B) the average of the addresses used to store the variable C) the address of the first byte of storage D) general delivery E) None of these
C) the address of the first byte of storage
9) When the less than ( < ) operator is used between two pointer variables, the expression is testing whether ________. A) the value pointed to by the first is less than the value pointed to by the second B) the value pointed to by the first is greater than the value pointed to by the second C) the address of the first variable comes before the address of the second variable in the computer's memory D) the first variable was declared before the second variable E) None of these
C) the address of the first variable comes before the address of the second variable in the computer's memory
6) If the head pointer points to nullptr, this indicates ________. A) the list has been previously created and then destroyed B) the list needs to be destroyed C) there are no nodes in the list D) the list is full and cannot accept any new nodes E) None of these
C) there are no nodes in the list
If a recursive function does not contain a base case, it ________. A) returns 0 and stops B) returns false and stops C) uses up all available stack memory, causing the program to crash D) reaches the recursive case and stops E) None of these
C) uses up all available stack memory, causing the program to crash
20) The end-of-file marker is automatically written ________. A) when a file is opened with ios::eof B) when a file is opened with ios::app C) when a file is closed D) when the program ends E) None of these
C) when a file is closed
In a procedural program, you typically have __________stored in a collection of variables, and a set of __________ that perform operations on the data. a) numbers, arguments b) parameters, arguments c) strings, operators d) data, functions
Data functions
A class is a(n) _____________ that is defined by the programmer. a) data type b) function c) method d) attribute
Data type
When a constructor function accepts no arguments, or does not have to accept arguments because of default arguments, it is called a(n): a) empty constructor b) default constructor c) stand-alone function d) arbitrator function
Default constructor
In an inheritance situation, the new class that you create from an existing class is known as the ________.
Derived Class and Child Class
Multiple inheritance is when a ________ class has ________ base classes.
Derived, two or more
________ queues are more intuitive and easier to understand than ________ queues.
Dynamic, static
13) Which of the following statements is not valid C++ code? A) int ptr = &num1; B) int ptr = int *num1; C) float num1 = &ptr2; D) All of these are valid. E) All of these are invalid.
E) All of these are invalid.
28) When you pass a pointer as an argument to a function, you must ________. A) declare the pointer variable again in the function call B) dereference the pointer variable in the function prototype C) use the #include<func_ptr.h> statement D) not dereference the pointer in the function's body E) None of these
E) None of these
This operator may be used to assign one object to another. (a) = (b) == (c) <> (d) @ (e) None of these
(a) =
Like ____, a recursive method must have some way to control the number of times it repeats. (a) A loop (b) Any method (c) A GUI method (d) A rumor
(a) A loop
The depth of recursion is (a) The number of times that a method calls itself (b) The value returned from the last recursive call (c) The value that will terminate the recursive calls (d) There is no such term
(a) The number of times that a method calls itself
If a member variable is declared ________, all objects of that class have access to that variable. (a) static (b) dynamic (c) inline (d) default (e) None of these
(a) static
The number of times that a method calls itself is known as the (a) Height of recursion (b) Depth of recursion (c) Widthofrecursion (d) Length of recursion
(b) Depth of recursion
The actions that the JVM must performed any time a method is called is called (a) Stack frame (b) Overhead (c) Housekeeping (d) Method calls
(b) Overhead
Like a loop, a recursive method must have (a) A counter (b) Some way to control the number of times it repeats itself (c) A return statement (d) A predetermined number of times it will execute before terminating
(b) Some way to control the number of times it repeats itself
When objects contain pointers, it is a good idea to create an explicit ________ function. (a) destructor (b) copy constructor (c) static constructor (d) inline constructor (e) None of these
(b) copy constructor
Each object of a class has its own copy of the class's ________. (a) member functions (b) member variables (c) constructor and destructor functions (d) All of these (e) None of these
(b) member variables
To overload the + operator, you would write a function named ________. (a) overload + (b) operator + (c) function + (d) operator.overload(+) (e) None of these
(b) operator +
If you do not furnish one of these, an automatic memberwise copy will be performed when one object is assigned to another object. (a) overloaded constructor function (b) overloaded assignment operator (c) default constructor function (d) overloaded copy operator (e) None of these
(b) overloaded assignment operator
This is a special built-in pointer that is available to a class's member functions. (a) overloaded -> operator (b) this pointer (c) &constructor pointer (d) ~destructor *ptr (d) None of these
(b) this pointer
A good reason for overloading an operator is to enable it to ________. (a) outperform its C language counterparts (b) work in its usual way, but with programmer-defined data types (c) operate on more operands than in its standard definition (d) operate on no operands (e) None of these
(b) work in its usual way, but with programmer-defined data types
A recursive method is a method that (a) Uses four-letter words to tell you when you have an error (b) Keeps recurring in your program code (c) Calls itself (d) Is a method that has a loop in it
(c) Calls itself
A ____ method is a method that calls itself. (a) Looping (b) Circular (c) Recursive (d) Reoccurring
(c) Recursive
Which of the following does the JVM not have to perform when a method is called? (a) Allocate memory for parameters (b) Store the address of the program location where to return after the method terminates (c) Terminate the calling program (d) Allocate memory for local variables
(c) Terminate the calling program
To solve a program recursively, you need to identify at least one case in which the problem can be solved without recursion—this is known as (a) The recursive case (b) The terminal case (c) The base case (d) The final case
(c) The base case
It is a good idea to make a copy constructor's parameters ________ by specifying the ________ key word in the parameter list. (a) inline, inline (b) static, static (c) constant, const (d) global, global (e) None of these
(c) constant, const
This is a special function that is called whenever a new object is created and initialized with another object's data. (a) destructor (b) static function (c) copy constructor (d) assignment function (e) None of these
(c) copy constructor
In the following function header: FeetInches FeetInches : : operator++(int) the word (int) is known as a(n): (a) parameterless data type (b) incomplete argument (c) dummy parameter (d) incomplete parameter (e) None of these
(c) dummy parameter
A(n) ________ informs the compiler that a class will be declared later in the program. (a) static function (b) private data member (c) forward declaration (d) object conversion (e) None of these
(c) forward declaration
Object composition is useful for creating this type of relationship between classes. (a) friend (b) static (c) has a (d) conditional (e) None of these
(c) has a
When a class contains an instance of another class, it is known as ________. (a) object overloading (b) operator overloading (c) object composition (d) dynamic composition (e) None of these
(c) object composition
An ________ operator can work with programmer-defined data types. (a) inline (b) unconditional (c) overloaded (d) undefined (e) None of these
(c) overloaded
When you redefine the way a standard operator works when it is used with class objects, you have ________ the operator. (a) reassigned (b) reformatted (c) overloaded (d) overwhelmed (e) None of these
(c) overloaded
A reason to overload the ________ is to write classes that have array-like behaviors. (a) parentheses ( ) operator (b) curly braces { } operator (c) square brackets [ ] operator (d) colon : : operator (e) None of these
(c) square brackets [ ] operator
C++ allows you to redefine the way ________ work when used with class objects. (a) compiler errors (b) preprocessor directives (c) standard operators (d) undefined variables (e) None of these
(c) standard operators
A member function that is declared ________ may not access any non-static data members in the class. (a) private (b) public (c) static (d) inline (e) None of these
(c) static
Which of the following cannot be programmed recursively? (a) Towers of Hanoi (b) Greatest Common Denominator (c) Binary Search (d) All of the above can be programmed recursively.
(d) All of the above can be programmed recursively
How many times will the following method call itself, if 10 is passed as the argument public static void message(int n) { if (n 0) { System.out.println("Print this line.\n"); message(n 1); } } (a) 1 (b) 9 (c) 10 (d) An infinite number of times
(d) An infinite number of ti
If you do not furnish one of these a default will be provided for you by the compiler. (a) copy constructor (b) constructor (c) destructor (d) All of these (e) None of these
(d) all of these
This type of function is not a member of a class, but it has access to the private members of the class. (a) static (b) constructor (c) destructor (d) friend (e) None of these
(d) friend
When you overload an operator, you cannot change the number of ________ taken by the operator. (a) arguments (b) parameters (c) operations (d) operands (e) None of these
(d) operands
C++ requires that a copy constructor's parameter be a(n) ________. (a) integer data type (b) floating point data type (c) pointer variable (d) reference object (e) None of these
(d) reference object
This type of member variable may be accessed before any objects of the class have been created. (a) private (b) public (c) inline (d) static (e) None of these
(d) static
The ______ and _______ operators can respectively be used to increment and decrement a pointer variable.
++ and --
19) When you dereference an object pointer, use the ________. A) -> operator B) <> operator C) dot operator D) & operator E) None of these
-> operator
When you dereference an object pointer, use the
-> operator
This data type can be used to create files and write information to them but cannot be used to read information from them: a) ifstream b) outstream c) ofstream d) afstream e) none of these
...
4) The null terminator stands for this ASCII code. A) 57 B) 100 C) 1000 D) 0 E) None of these
0
In the following code, assume the myQueue object is a queue that can hold integers, and that value is an int variable. (The lines are numbered for reference purposes.) 1 myQueue.enqueue(0); 2 myQueue.enqueue(1); 3 myQueue.enqueue(2); 4 myQueue.dequeue(value); 5 cout << value << endl; Assume that the dequeue function, called in line 4, stores the number removed from the queue in the value variable. What will the statement in line 5 display?
0
In the following code, assume the myStack object is a stack that can hold integers, and that value is an int variable. (The lines are numbered for reference purposes.) 1 myStack.push(0); 2 myStack.push(1); 3 myStack.push(2); 4 myStack.pop(value); 5 myStack.pop(value); 6 myStack.pop(value); 7 cout << value << endl; Assume that the pop function, called in lines 4, 5, and 6, stores the number popped from the stack in the value variable. What will the statement in line 7 display?
0
When a relational expression is false, it has the value
0
the null terminator is ASCII code
0
After the following statement executes, what value will the MAPLE enumerator be stored as, in memory? enum Tree { OAK, MAPLE, PINE }; a. "MAPLE" b. 2 c. 'M' d. 1 e. 1.0
1
In the following code, assume the myQueue object is a queue that can hold integers, and that value is an int variable. (The lines are numbered for reference purposes.) 1 myQueue.enqueue(0); 2 myQueue.enqueue(1); 3 myQueue.enqueue(2); 4 myQueue.dequeue(value); 5 myQueue.enqueue(3); 6 myQueue.dequeue(value); 7 cout << value << endl; Assume that the dequeue function, called in lines 4, and 6, stores the number removed from the queue in the value variable. What will the statement in line 7 display?
1
What is assigned to the variable result given the statement below with the following assumptions: x = 10, y = 7, and x, result, and y are all int variables. result = x >= y;
1
What is assigned to the variable resultgiven the statement below with the following assumptions:x = 10, y = 7, andx, result,andyare all int variables. result = x >= y;
1
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; }
1
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 << eendl; }
1
The _________ marker is the character that marks the end of a file, and is automatically written when the file is closed. a) Data Read Stop (DRS) b) No More Data (NMD) c) End of File (EOF) d) Data Stream Close (DSC)
End of File (EOF)
A linear search can only be implemented with integer values
False
A linear search can only be implemented with integer values.
False
A list that contains pointers to the previous node, the next node, and a node in the third dimension is known as a triple-linked list.
False
A new node cannot become the first node in the list.
False
A new node must always be made the last node in the list.
False
A non-static member function may not access a static member variable.
False
A program may not contain both a "regular" version of a function and a template version of the function.
False
A public data member may be declared a friend of a private function.
False
A real-world example of the queue data structure can be seen in a stack of cafeteria trays, where the last tray pushed onto the stack is the first tray removed.
False
A recursive function cannot call another function T/F
False
A recursive function cannot call another function.
False
A stack that is implemented as a linked list is known as a deque.
False
Before you can perform a bubble sort, the data must be stored in descending order
False
Before you can perform a bubble sort, the data must be stored in descending order.
False
Before you can perform a selection sort, the data must be stored in ascending order.
False
Deleting an entire list simply requires the use of the delete operator.
False
Endeque and deque are the two most common queue operations.
False
If an exception is not caught, it is stored for later use.
False
If there are no nodes in a linked list, you cannot append a node to the list.
False
If you are using a compiler that is older than C++ 11, be sure to put spaces between the angled brackets that appear next to each other when defining a stack.
False
If you overload the prefix ++ operator, the postfix ++ operator is automatically overloaded.
False
In C++, if you overload the < operator, you must also overload the > operator.
False
In a binary tree, each node must have a minimum of two children.
False
Indirect recursion means that a function calls itself n number of times, then processing of the function starts from the first call
False
Linked lists are less complex to code and manage than arrays.
False
Nodes in a linked list are stored in contiguous memory.
False
Output will be the same if you use inorder, postorder, or preorder traversals of the same binary tree.
False
Push and pop are the two most common queue operations
False
The bubble sort is an easy way to arrange data in ascending order but it cannot arrange data in descending order.
False
The bubble sort is an easy way to arrange data into ascending order, but it cannot arrange data into descending order.
False
The conditional operator takes two operands.
False
The defaultsection is required in a switchstatement.
False
The following code correctly determines whether xcontains a value in the range of 0through 100, inclusive. if (x > 0 && <= 100)
False
The linear search repeatedly divides the portion of an array being searched in half.
False
The programmer must declare in advance the size of a dynamic stack or queue.
False
The try/catch/throw construct is able to handle only one type of exception in a try block.
False
There is no difference between declaring an object of an ordinary class and an object of a template class.
False
To remove a node that has children, you must first remove the children.
False
True/False - A problem can be solved recursively if it can be broken down into successive smaller problems that are unique within the overall problem.
False
True/False: A derived class may not have any classes derived from it.
False
True/False: A member function of a derived class may not have the same name as a member function of a base class.
False
True/False: A non-static member function may not access a static member variable.
False
True/False: A public data member may be declared a friend of a private function.
False
True/False: C++ permits you to overload the sizeof operator and the this pointer.
False
True/False: If you overload the prefix ++ operator, the postfix ++ operator is automatically overloaded.
False
True/False: In C++, if you overload the < operator, you must also overload the > operator.
False
True/False: In an inheritance situation, you may not pass arguments to a base class constructor.
False
True/False: The ampersand (&) is used to dereference a pointer variable in C++.
False
True/False: When a class declares an entire class as its friend, the friendship status is reciprocal. That is, each class's member functions have free access to the other's private members.
False
True/False: When you overload the << operator, you must also overload the >> operator.
False
True/False: You can overload the conditional operator to make it function as an unconditional operator.
False
True/False: You may overload any C++ operator, and you may use the operator function to define non-standard operators, such as @ and ^.
False
Using a binary search, you are more likely to find an item than if you use a linear search
False
When a class declares an entire class as its friend, the friendship status is reciprocal. That is, each class's member functions have free access to the other's private members.
False
When recursion is used on a linked list, it will always display the contents of the list in reverse order.
False
When the program knows the exact contents of a list and can access any element on demand, the data structure is known as a stacked deque.
False
When you create a linked list, you must know in advance how many nodes the list will contain.
False
When you overload the << operator, you must also overload the >> operator.
False
You are more likely to find an item by using a binary search than by using a linear search.
False
You can overload the conditional operator to make it function as an unconditional operator.
False
z is available to code that is written outside the class.
For the following code, which statement is not true? class Point { private: double y; double z; public: double x; };
A(n) ___ informs the compiler that a class will be declared later in the program.
Forward declaration
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 test; return 0; }
Hello!
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 test; return 0; }
Hello!
What is the output of the following code segment if the user enters 23? int number; cout << "Enter a number: "; cin >> number; if (number > 0) cout << "Hi, there!" << endl; else cout << "Good-bye." << endl;
Hi, there!
In the following statement: class car : protected vehicle ________ is the derived class.
Car
In the following statement: class car : protected vehicle ________ is the derived class.
Car
A recursive function that does not have a termination will eventually: a) return 0 and stop b) reach the Null terminator and stop c) return false and stop d) cause the program to crash e) None of these
Cause the program to crash
It is a good idea to make a copy constructor's parameters ________ by specifying the ________ key word in the parameter list.
Constant,const
A ___________ is a member function that is automatically called when a class object is ___________. a) destructor, created b) constructor, created c) static function, deallocated d) utility function, declared
Constructor, created
If you do not furnish one of these a default will be provided for you by the compiler.
Constructor,deconstructor, and copy constructor
The function pow(x, y), requires which header file? a. cstdlib b. cstring c. iostream d. cmath e. iomanip
D
Which of the following functions will return the value of x, rounded to the nearest whole number? a. abs(x) b. fmod(x) c. sqrt(x) d. round(x) e. whole(x)
D
Which of the following statements will read an entire line of input into the string object, address? a. cin << address; b. cin address; c. cin.get(address); d. getline(cin, address); e. cin.get(length >> width >> height);
D
33) What will the following code output? int *numbers = new int[5]; for (int i = 0; i <= 4; i++) *(numbers + i) = i; cout << numbers[2] << endl; A) Five memory addresses B) 0 C) 3 D) 2 E) 1
D) 2
21) Variations of the linked list are: A) doubly-linked list B) circular linked list C) backward linked list D) A and B E) None of these
D) A and B
16) Which of the following is a basic linked list operation? A) appending a node B) traversing the list C) inserting or deleting a node D) All of these E) None of these
D) All of these
Recursion can be used to: A) compute factorials B) find GCD's C) traverse linked lists D) All of these E) None of these
D) All of these
How many times will the following function call itself, if the value 5 is passed as the argument? void showMessage(int n) { if (n > 0) { cout << "Good day!" << endl; showMessage(n + 1); } } A) 1 B) 4 C) 5 D) An infinite number of times
D) An infinite number of times
23) A ________ list contains pointers to the nodes before it and after it. A) singly-linked B) doubly-linked C) circular-linked D) B and C E) None of these
D) B and C
8) What does the following statement do? double *num2; A) Declares a double variable named num2. B) Declares and initializes an pointer variable named num2. C) Initializes a variable named *num2. D) Declares a pointer variable named num2. E) None of these
D) Declares a pointer variable named num2.
4) To append a node to a list means to ________. A) delete a node from the beginning of the list B) delete a node from the end of the list C) add a node to the beginning of the list D) add a node to the end of the list E) None of these
D) add a node to the end of the list
22) Which statement displays the address of the variable num1? A) cout << num1; B) cout << *num1; C) cin >> &num1; D) cout << &num1; E) None of these
D) cout << &num1;
7) Which of the following statements opens the file info.txt for both input and output? A) dataFile.open("info.txt", ios::in && ios::out); B) dataFile.open("info.txt", ios::in , ios::out); C) dataFile.open("info.txt", input || output); D) dataFile.open("info.txt", ios::in | ios::out);
D) dataFile.open("info.txt", ios::in | ios::out);
The ________ of recursion is the number of times a recursive function calls itself. A) level B) breadth C) type D) depth E) None of these
D) depth
11) Appending a node means adding it to the end of a list, and ________ a node means putting a new node in the list, but not necessarily at the end. A) concatenating B) popping C) clamping D) inserting E) None of these
D) inserting
3) The statement: int *ptr = nullptr; has the same meaning as ________. A) int ptr = nullptr; B) *int ptr = nullptr; C) int ptr* = nullptr; D) int* ptr = nullptr; E) None of these
D) int* ptr = nullptr;
16) Outside of a C++ program, a file is identified by its ________. Inside a C++ program, a file is identified by a(n) ________. A) file number, file name B) file name, file number C) name, address D) name, file stream object E) None of these
D) name, file stream object
2) A linked list is a series of connected ________. A) ADTs B) vectors C) algorithms D) nodes E) None of these
D) nodes
23) The following statement: cin >> *num3; A) stores the keyboard input into the variable num3 B) stores the keyboard input into the pointer called num3 C) is illegal in C++ D) stores the keyboard input into the variable pointed to by num3 E) None of these
D) stores the keyboard input into the variable pointed to by num3
15) To create a linked list, you must first create a(n) ________. A) header file B) function template C) exception D) struct E) None of these
D) struct
9) A doubly-linked list keeps track of the next node in the list, as well as: A) itself B) the head node C) the tail node D) the previous node E) None of these
D) the previous node
The recursive factorial function calculates the factorial of its parameter. Its base case is when the parameter is ________. A) returned B) received C) amortized D) zero E) None of these
D) zero
25) The process of object-oriented analysis can be viewed as the following steps: A) Identify objects, then define objects' attributes, behaviors, and relationships B) Define data members and member functions, then assign a class name C) Declare private and public variables, prototype functions, then write code D) Write the main() function, then determine which classes are needed E) None of these
Identify objects, then define objects' attributes, behaviors, and relationships
The process of object-oriented analysis can be viewed as the following steps:
Identify objects, then define objects' attributes, behaviors, and relationships
The programmer must ensure that a recursive function does not become ________. a) a static function b) a prototyped function c) like an endless loop d) a dynamic function e) None of the above
Like an endless loop
Polymorphism is when ________ in a class hierarchy perform differently, depending upon which object performs the call.
Member Functions
dot operator
Members of a class object are accessed with the ________.
How much memory is reserved for a function template?
No Memory
In a binary tree, each node may point to ________ other nodes.
No, One or Two
10) The constructor function's return type is ________. A) int B) float C) char D) structure pointer E) None of these
None of these
27) This library function reverses the order of a C-string. A) reverstr B) strrev C) reversit D) backward E) None of these
None of these
Arguments are passed to the base class destructor function by the ________ class ________ function. (a)derived, constructor (b)derived, destructor (c)base, constructor (d)base, destructor (e)None of these
None of these
Regardless of the algorithm being used, a search through an array is always performed
None of these
The following statement: class Car : private Vehicle allows the ________ members of the Car class to access ________ members of the Vehicle class. (a) private, private (b) public, private (c) protected, private (d) public, protected (e) None of these
None of these
When more than one class is derived from a base class, the situation is called: (a)polymorphism (b)population (c)multiplicity (d)encapsulation (e)None of these
None of these
11) The destructor function's return type is ________. A) tilde B) int C) float D) Nothing. Destructors have no return type. E) None of the above
Nothing. Destructors have no return type.
When a class contains an instance of another class, it is known as
Object compensation
data, functions
Objects are created from abstract data types that encapsulate ________ and ________ together.
subscripts
Objects in an array are accessed with ________, just like any other data type in an array.
To set up a file to perform file i/o you must declare: a) one or more file stream objects b) at least one variable, the contents of which will be written to the file c) a string array to store the file contents d) all of these e) none of these
One or more file stream objects
In order, the three-step process of using a file in a C++ program involves: a) open the file, read/write/save data, close the file b) name the file, open the file, delete the file c) create the file contents, close the file, name the file d) insert a disk, open a file, remove the disk e) none of these
Open the file, read/write/save data, close the file
When you overload an operator, you cannot change the number of ________ taken by the operator.
Operands
A virtual function is a member function that expects to be ________ in a derived class.
Overridden
C++ 11 introduces the ________ key word to help prevent subtle errors when overriding virtual functions.
Override
______ to a base class may be assigned the address of a derived class object.
Pointers
If you do not declare an access specification, the default for members of a class is: a) inline b) global c) private d) public e) none of these
Private
_______ members of a base class are never accessible to a derived class.
Private
This is used to protect important data. a) public access specifier b) private access specifier c) protect() member function d) class protection operator, @
Private access specifier
Examples of access specifiers are the keywords: a) near and far b) opened and closed c) private and public d) table and row
Private and public
Protected members of a base class are like ________, but they may be accessed by derived classes.
Private members
A member function that is declared ________ may not access any non-static data members in the class.
Static
If a member variable is declared ________, all objects of that class have access to that variable.
Static
This type of member variable may be accessed before any objects of the class have been created.
Static
A C++ class is similar to one of these. a) inline function b) header file c) library function d) structure
Structure
Both of the following if statements perform the same operation. 1. if (sales > 10000) commissionRate = 0.15; 2. if (sales > 10000) commissionRate = 0.15;
T
If the expression on the left side of the following is true, the expression on the right side will not be checked. (a > = b) || (c == d)
T
The cin << statement will stop reading input when it encounters a newline character. T/F
T
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. T/F
T
When C++ is working with an operator, it strives to convert the operands to the same type. T/F
T
When the fixed manipulator is used, the value specified by the setprecision manipulator will be the number of digits to appear after the decimal point. T/F
T
the class
The constructor function always has the same name as ________.
None of these
The constructor function's return type is ________. int float char structure pointer
Nothing. Destructors have no return type.
The destructor function's return type is ________.
Identify objects, then define objects' attributes, behaviors, and relationships
The process of object-oriented analysis can be viewed as the following steps:
32) What is the output of the following program? #include <iostream> using namespace std; class TestClass { private: int val; void showVal() { cout << val << endl; } public: TestClass(int x) { val = x; } }; int main() { TestClass test(77); test.showVal(); return 0; } A) The program runs, but with no output. B) 77 C) 0 D) The program will not compile.
The program will not compile
The following function should swap the values contained in two integer variables, num1 and num2. What, if anything, is wrong with this function? void swap(int num1, int num2) { int temp = num2; num2 = num1; num1 = temp; } a. You must first initalize temp to 0 before using it. b. The variable temp should first be set to num1, not num2. c. The swap function must use reference parameters. d. The last line should be temp = num1. e. Nothing is wrong with this function.
The swap function must use reference parameters
#ifndef
This directive is used to create an "include guard," which allows a program to be conditionally compiled. This prevents a header file from accidentally being included more than once.
What is the output of the following code segment? int x = 5; if (x = 2) cout << "This is true!" << endl; else cout << "This is false!" << endl; cout << "That's all, folks!" << endl;
This is true! That's all folks
What is the output of the following code segment? int x = 5; if (x = 2)cout << "This is true!" << end1; else cout << "This is false!" << end1; cout << "That's all, folks!" << endl;
This is true! That's all folks
private access specifier
This is used to protect important data.
: When a recursive function directly calls itself, this is known as direct recursion.
True
A dynamic stack starts as an empty linked list.
True
A linked list can consist of structs, objects, or other abstract data types.
True
A linked list can grow and shrink as a program runs.
True
A linked list is called "linked" because each node in the series has a pointer that points to the next node in the list.
True
A selection sort and a binary search can be applied to STL vectors as well as arrays.
True
A sequence container organizes data in a sequential fashion, similar to an array.
True
A static member function does not need to be called by a specific object of the class.
True
A static member variable can be used when there are no objects of the class in existence.
True
A subtree is an entire branch of a tree, from one particular node down.
True
All nodes to the right of a node hold values greater than the node's value.
True
An expression that has any value other than 0is considered trueby an if statement.
True
Any algorithm that can be coded with recursion can also be coded with an iterative structure.
True
Any algorithm that can be coded with recursion can also be coded with interative structure T/F
True
As a rule of style, when writing an ifstatement you should indent the conditionally-executed statements.
True
Binary trees are commonly used to organize key values that index database records.
True
By default, when an object is assigned to another, each member of one object is copied to its counterpart in the other object.
True
Deleting a leaf node from a binary tree is not difficult. Deleting a non-leaf node requires several steps.
True
Deleting an entire list requires traversing the list, deleting each node one by one.
True
Dereferencing a pointer to a pointer gives you another pointer.
True
Function templates allow you to write a single function definition that works with many different data types.
True
If the expression on the left side of the following is false, the expression on the right side will not be checked. (a > = b) && (c == d)
True
If the expression on the left side of the following is true, the expression on the right side will not be checked. (a > = b) || (c == d)
True
If you are using the bubble sort algorithm to sort an array in descending order, the smaller values move toward the end.
True
In a static stack class, the constructor function can dynamically allocate memory for the stack array.
True
In the average case, an item is just as likely to be found near the beginning of an array as near the end
True
Like a loop, a recursive function must have some method to control the number of times it repeats.
True
On average, an item is just as likely to be found near the beginning of an array as near the end.
True
Recursive algorithms are less efficient than iterative algorithms.
True
Stacks and queues can be implemented as arrays or linked lists.
True
The STL provides containers for deque and queue.
True
The Standard Template Library (STL) contains templates for useful algorithms and data structures.
True
The Standard Template Library (STL) provides a linked list container.
True
The binary tree structure is called a "tree" because it resembles an upside-down tree.
True
The first item placed onto a stack is always the last item removed from the stack.
True
The height of a tree describes how many levels there are in the tree.
True
The inorder method of traversing a binary tree involves traversing the node's left subtree, processing the node's data, and then traversing the node's right subtree.
True
The line containing a throw statement is known as the throw point.
True
The number of comparisons made by a binary search is expressed in powers of two
True
The number of comparisons made by a binary search is expressed in powers of two.
True
The pop function in the stack template does not retrieve the value from the top of the stack. It merely removes it.
True
The pop function in the stack template of the STL does not retrieve the value from the top of the stack.
True
The preorder method of traversing a binary tree involves processing the node's data, traversing the node's left subtree, then traversing the node's right subtree.
True
The speed and amount of memory available to modern computers diminishes the performance impact of recursion so much that inefficiency is no longer a strong argument against it.
True
The this pointer is a special built-in pointer that is automatically passed as a hidden argument to all non-static member functions.
True
The this pointer is automatically passed to non-static member functions of a class.
True
The width of a tree is the largest number of nodes in the same level.
True
True or False: Any algorithm that can be coded with recursion can also be coded with an iterative structure.
True
True/False Any problem that can be solved recursively can also be solved iteratively.
True
True/False: A derived class may become a base class, if another class is derived from it.
True
True/False: A static member function does not need to be called by a specific object of the class.
True
True/False: A static member variable can be used when there are no objects of the class in existence.
True
True/False: An thrown exception for which there is no matching catch block will cause the execution of the program to abort.
True
True/False: By default, when an object is assigned to another, each member of one object is copied to its counterpart in the other object.
True
True/False: If Method A calls Method B which in turn calls method A, it is called indirect recursion
True
True/False: In C++ 11, if a derived class attempts to override a final member function, the compiler generates an error.
True
True/False: It is possible to declare an entire class as a friend of another class.
True
True/False: More than one class may be derived from a base class.
True
True/False: Pointers to a base class may be assigned the address of a derived class object.
True
True/False: Recursive algorithms tend to be less efficient than iterative algorithms.
True
True/False: Recusrive algorithms are usually less efficient than iterative algorithms
True
True/False: Static binding occurs when the compiler binds a function call with the function call that resides in the same class as the call itself.
True
True/False: The base class access specification can be viewed as a filter that base class members must pass through when becoming inherited members of a derived class.
True
True/False: The speed and amount of memory available to modern computers diminishes the performance impact of recursion so much that inefficiency is no longer as strong an argument against it as it used to be.
True
True/False: The this pointer is a special built-in pointer that is automatically passed as a hidden argument to all non-static member functions.
True
True/False: The this pointer is automatically passed to non-static member functions of a class.
True
True/False: When a recursive function directly calls itself, this is known as direct recursion.
True
True/False: When arguments must be passed to the base class constructor, they are passed from the derived class constructor's header line.
True
True/False: When you overload an operator, you can change the operator's original meaning to something entirely different.
True
Using a function template requires less code than overloading a function.
True
When a recursive function directly calls itself, this is known as direct recursion. T/F
True
When working with a linked list, one of the basic operations you can perform is to destroy the list.
True
When you declare an iterator to work with a container, the compiler automatically chooses the right type.
True
When you delete a node from a list, you must ensure that the links in the list are not permanently broken.
True
You should be careful when using the equality operator to compare floating point values because of potential round-off errors.
True
False
True/False: A destructor function can have zero to many parameters.
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.
False
True/False: Class objects can be defined prior to the class declaration.
True
True/False: If you do not declare a destructor function, the compiler will furnish one automatically.
True
True/False: More than one constructor function may be defined for a class.
False
True/False: More than one destructor function may be defined for a class.
True
True/False: Object-oriented programming is centered around the object, which encapsulate together both the data and the functions that operate on the data.
True
True/False: One purpose that constructor functions are often used for is to allocate memory that will be needed by the object.
True
True/False: One purpose that destructor functions are often used for is to free memory that was allocated by the object.
False
True/False: The constructor function may not accept arguments.
True
True/False: When an object is defined without an argument list for its constructor, the compiler automatically calls the object's default constructor.
True
True/False: When using smart pointers to dynamically allocate objects in C++ 11, it is unnecessary to delete the dynamically allocated objects because the smart pointer will automatically delete them.
True
True/False: Whereas object-oriented programming centers on the object, procedural programming centers on functions.
False
True/False: You must declare all data members of a class before you declare member functions.
False
True/False: You must use the private access specification for all data members of a class.
An insertion or deletion routine requires that you create this many pointers for use during the traversal process.
Two—one for the node being inspected, and one for the previous node.
In the following statement: class car : public vehicle ________ is the base class.
Vehicle
A virtual function is declared by placing the key word ________ in front of the return type in the base class's function declaration.
Virtual
________ functions are dynamically bound by the compiler.
Virtual
A ________ of a base class expects to be overridden in a derived class.
Virtual Function
The program will not compile.
What is the output of the following program? #include <iostream> using namespace std; class TestClass { private: int val; void showVal() { cout << val << endl; } public: TestClass(int x) {val = x;} }; int main() { TestClass test(77); test.showVal(); return 0; }
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 test(77); return 0; }
Hello!
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 test; return 0; }
default constructor
When a constructor function accepts no arguments, or does not have to accept arguments because of default arguments, it is called a(n) ________.
inline
When the body of a member function is defined inside a class declaration, it is said to be ________.
-> operator
When you dereference an object pointer, use the ________.
What is the output of the following code segment if the user enters 90for the score? cout << "Enter your test score: "; cin >> test_score; if (test_score < 60) cout << "You failed the test." << endl; if (test_score > 60) cout <<"You passed the test." else cout << "You need to study harder next time." << endl;
You passed the test
ZZ
ZZ
Types of iterators are [ A ] .
[ A ] All of these
A linked list class must take care of removing the dynamically allocated nodes. This is done by [ A ] .
[ A ] None of these
An actual instance of the function is created in memory when the compiler encounters [ A ] .
[ A ] a call to the template function
The last node in a linked list points to [ A ] .
[ A ] a null pointer
To build a list initially, you can use a(n) [ A ] routine.
[ A ] append
A function template prefix is placed before the function header. A class template prefix is placed [ A ] .
[ A ] before the class declaration
The try block is immediately followed by one or more [ A ] .
[ A ] catch blocks
A static queue can be implemented as a [ A ] .
[ A ] circular array
A _______ list contains pointers to the nodes before it and after it.
[ A ] circular-linked [ B ] doubly-linked
A(n) [ A ] is a class that stores data and organizes it in some fashion.
[ A ] container
The most important data structures in the STL are [ A ] and [ B ] .
[ A ] containers [ B ] iterators
To append a node to a list means to [ A ] .
[ A ] delete a node from the beginning of the list
If an exception is thrown by a member function of a class object, then the class [ A ] is called.
[ A ] destructor
The list container provided by the Standard Template Library is a template version of a [ A ]
[ A ] doubly-linked list
Variations of the linked list are:
[ A ] doubly-linked list [ B ] circular linked list
Class templates allow you to create one general version of a class without having to [ A ] .
[ A ] duplicate code to handle multiple data types
A [ A ] stack or queue is built around the linked-list.
[ A ] dynamic
A dynamic queue can be implemented as a [ A ] .
[ A ] dynamic linked list
A(n) [ A ] is a value or an object that signals an error.
[ A ] exception
Stacks are useful data structures for algorithms that work [ A ] with the [ B ] saved element in the series.
[ A ] first [ B ] last
In a circular-linked list, the last node points to the [ A ] .
[ A ] first node
Static stacks have a [ A ] size, and are implemented as [ B ] .
[ A ] fixed [ B ] arrays
All type parameters defined in a function template must appear at least once in the [ A ] .
[ A ] function parameter list
The algorithms provided by the STL are implemented as [ A ] , and perform various operations on elements of containers.
[ A ] function templates
The [ A ] of a linked list points to the first node in the list.
[ A ] head
Appending a node means adding it to the end of a list, and [ A ] a node means putting a new node in the list, but not necessarily at the end.
[ A ] inserting
Which of the following is a basic linked list operation?
[ A ] inserting a node [ B ] appending a node [ C ] traversing the list
A(n) [ A ] is like a pointer. It is used to access the individual data elements in a container.
[ A ] iterator
An associative container uses [ A ] to access elements rapidly.
[ A ] keys
The Standard Template Library offers a stack template that may be implemented as a:
[ A ] linked list [ B ] vector [ C ] deque
A linked list is a series of connected [ A ]
[ A ] nodes
A function template's prefix contains [ A ] enclosed in angled brackets.
[ A ] one or more generic data types
In a function template, the programmer substitutes [ A ] for [ B ] .
[ A ] parameters [ B ] data types
A [ A] is used to travel through a linked list and search for data.
[ A ] pointer
The [ A ] operation allows an item to be removed from a stack.
[ A ] pop
The [ A ] operation allows an item to be stored on a stack.
[ A ] push
A [ A ] is processed in a manner similar to customers standing in a grocery check-out line—the first customer in line is the first served.
[ A ] queue
If data is transmitted faster than it can be processed, it can be held in a [ A ] for processing.
[ A ] queue
A(n) [ A ] is an abstract data type that stores and retrieves items in a last-in-first-out manner.
[ A ] stack
Queues that are implemented as arrays are called [ A ] queues.
[ A ] static
To create a linked list, you must first create a(n) [ A ] .
[ A ] struct
The beginning of a function template is marked by a [ A ]
[ A ] template prefix
If the head pointer points to nullptr, this indicates [ A ]
[ A ] there are no nodes in the list
When an error occurs, an exception is [ A ]
[ A ] thrown
The process of moving through a linked list is referred to as [ A ] the list.
[ A ] traversing
The [ A ] starts with the key word try, and is followed by a block of code executing any statements that might cause an exception to be thrown.
[ A ] try block
To handle an exception that has been thrown, a program must have a(n) [ A ] .
[ A ] try/catch construct
A(n) [ A ] is used in a function template to specify a generic data type.
[ A ] type parameter
A dynamic stack has a [ A ] size, and is implemented as a(n) [ B ] .
[ A ] variable [ B ] linked list
An exception thrown from outside a try block [ A ] .
[ A ] will cause the program to abort execution
3) This is the escape sequence representing the null terminator. A) \n B) \t C) \0 D) nullptr E) None of these
\0
the escape sequence that represents the null terminator is:
\0
An actual instance of a template function is created in memory when the compiler encounters _____________.
a call to the template function
In the following statement: template < class T > What does T represent?
a generic data type that is used in a function template
Given the following structure decaration, idNum is struct Employee { string name; int idNum; }; a. a member b. an array c. a tag d. None of these
a member
A pointer variable is designed to store ________.
a memory address
The following statement indicates: stack< int, vector<int> > iStack;
a new stack of integers, implemented as a vector
All node pointers that do not point to other nodes are set to:
a null pointer
Given the following structure decaration, Employee is struct Employee { string name; int idNum; }; a. a member b. an array c. a tag d. None of these
a tag
Input values should always be checked for
a. an appropriate range b. reasonableness c. division by zero, if division is taking place
In C++11 you can have one constructor call another constructor in the same class by using a. constructor delegation b. a member initialization list c. in-place initialization d. None of these
a. constructor delegation
A ________ is a member function that is automatically called when a class object is ________. a. constructor, created b. None of these c. destructor, created d. utility function, declared e. static function, deallocated
a. constructor, created
Objects are created from abstract data types that encapsulate ________ and ________ together. a. data, functions b. numbers, characters c. addresses, pointers d. None of these e. integers, floating-point numbers
a. data, functions
When the body of a member function is defined inside a class declaration, it is said to be a. inline b. static c. global d. conditional e. None of these
a. inline
When an object contains an instance of another class, it is known as __. a. object composition b. dynamic composition c. operator overloading d. object overloading e. None of these
a. object composition
An ________ operator can work with programmer-defined data types. a. overloaded b. unconditional c. None of these d. inline e. undefined
a. overloaded
When you redefine the way a standard operator works when it is used with class objects, you have ________ the operator. a. overloaded b. reassigned c. referenced d. reformatted e. None of these
a. overloaded
If you do NOT declare an access specification, the default for members of a class is a. private b. inline c. None of these d. global e. public
a. private
In C++11, reference variables that can refer only to temporary object that would otherwise have no name are called ___ and are declared with a ___. a. rvalues, double ampersand (&&) b. lvalues, ampersand (&) c. lvalues, double ampersand (&&) d. None of these e. rvalues, ampersand (&)
a. rvalues, double ampersand (&&).
A C++ class is similar to a(n) a. structure b. header file c. inline function d. None of these e. library function
a. structure
Objects in an array are accessed with ________. a. subscripts b. parentheses c. output format manipulators d. None of these e. #include statements
a. subscripts
Data types that are created by the programmer are known as a. variables b. abstract data types (ADTs) c. functions d. parameters e. None of these
abstract data types (ADTs)
Which of the following describes only the general characteristics of an object? a. initialization b. abstraction c. detailed specification d. initiation e. None of these
abstraction
The base class's ________ affects the way its members are inherited by the derived class.
access specification
The term pointer can be used interchangeably with
address
A stack can be adapted to store [ A ] data types.
all
Which of the following is an example of a C++ primitive data type? a. unsigned short int b. long double c. unsigned char d. All of these e. None of these
all of these
You may use a pointer to a structure as a a. function parameter b. structure member c. function return type d. All of these e. None of these
all of these
If new data needs to be added to a linked list, the program simply ________ and inserts it into the series.
allocates another node
Multiple inheritance opens the opportunity for a derived class to have _______ members.
ambiguous
Multiple inheritance opens the opportunity for a derived class to have ________ members.
ambiguous
A class with at least one pure virtual function is called
an abstract class
The programmer must ensure that a recursive function does not become:
an endless loop
When you dereference a pointer to a pointer, the result is:
another pointer
To insert a new node in ascending order into a list, the list must be:
arranged in ascending order
A dynamic stack may be implemented as a(n) [ Select ] , and expand or shrink with each push or pop operation.
array
16) This function accepts a C-string containing a number as its argument and returns the integer equivalent. A) strToInt B) itoa C) atoi D) int_from E) None of these
atoi
9) This function converts a C-string to an integer and returns the integer value. A) atoint B) strtoint C) strint D) atoi E) None of these
atoi
10) Which statement converts the string "10" to the integer value 10? A) itoa("ten") B) atoi("ten") C) atoi("10") D) itoa(10) E) None of these
atoi("10)
8) This function accepts a C-string as an argument and converts the string to a long integer. A) atol B) strlong C) strtolong D) stringlong E) None of these
atol
2) In OOP terminology, an object's member variables are often called its ________, and its member functions are sometimes referred to as its behaviors, or ________. A) values, morals B) data, activities C) attributes, activities D) attributes, methods E) None of these
attributes, methods
In OOP terminology, an object's member variables are often called its ___, and its member functions are sometimes referred to as its behaviors, or ___.
attributes, methods
In OOP terminology, an object's member variables are often called its _________, and its member functions are sometimes referred to as its behaviors, or ____________.
attributes, methods
Which of the following is a directive used to create an "include guard" that allows a program to be conditionally compiled to prevent a header file from accidentally being included more than once? a. None of these b. #ifndef c. #include d. #endif e. #guard
b. #ifndef
When you dereference an object pointer, use the a. dot operator b. -> operator c. None of these d. <>operator e. & operator
b. -> operator
How many default constructors can a class have? a. None of these b. only one c. only two d. two or more e. any number
b. Only one. (Otherwise you'd have a duplicate function, which is not allowed.)
Assuming that Rectangle is a class name, what can you say is TRUE, given the following statement? Rectangle *BoxPtr; a. The statement declares an object of the class Rectangle. b. The statement defines a Rectangle pointer variable named *BoxPtr. c. The statement is illegal in C++. d. None of these e. The statement assigns the value of *BoxPtr to the object Rectangle.
b. The statement defines a Rectangle pointer variable named *BoxPtr.
Where are class declarations usually stored? a. on separate disk volumes b. in their own header files c. under pseudonyms d. None of these e. in .cpp files, along with function definitions
b. in their own header files
In C++11 the ________ operator swaps the members of the object being assigned with the temporary object. a. swap assignment b. move assignment c. semantic assignment d. None of these e. temp assignment
b. move assignment
When you overload an operator, you cannot change the number of ________ taken by the operator. a. arguments b. operands c. parameters d. operations e. None of these
b. operands
If you do NOT furnish a(n) ________, an automatic memberwise copy will be performed when one object is assigned to another object. a. overloaded constructor function b. overloaded assignment operator c. None of these d. overloaded copy operator e. default constructor function
b. overloaded assignment operator
C++ requires that a copy constructor's parameter be a(n) a. None of these b. reference object c. integer data type d. floating-point data type e. pointer variable
b. reference object
What is the output of the following program? #include <iostream> using namespace std; class TestClass { private: int val; void showVal() { cout << val << endl; } public: TestClass(int x) { val = x; } }; int main() { TestClass test(77); test.showVal(); return 0; } a. 77 b. the program will not compile c. 0 d. the program runs but there is no output.
b. the program will not compile
For the following code, which statement is NOT true? class Point { private: double y; double z; public: double x; }; a. All of these are true. b. z is not available to code that is written outside the class. c. x is available to code that is written outside the class. d. x, y, and z are called members of the class. e. The name of the class is Point.
b. z is not available to code that is written outside the class.
In the following statement: class car : protected vehicle What is being protected?
base class members
The ________ constructor is called before the ________ constructor.
base, derived
The following code shows an example of ________ class Point { private: double y = 5.70; double z = 3.0; public: Public member functions go here... }; a. constructor delegation b. an illegal initialization c. a default constructor creation d. in-place initialization
d. in-place initialization
In C++11, values that persist beyond the statement that created them and have names that make them accessible to other program statements are called___. a. temporary values b. semantics c. None of these d. lvalues e. rvalues
d. lvalues (letter L, difficult to read in many fonts.)
Each object of a class has its own copy of the class's a. member functions b. constructor and destructor functions c. None of these d. member variables e. All of these
d. member variables
To overload the + operator, you'd write a function named ___. a. None of these b. function + c. operator.overload(+) d. operator + e. overload +
d. operator +
If a local variable and a global variable have the same name within the same program, the ___ resolution operator must be used. a. ambiguity b. variable c. None of these d. scope e. global
d. scope
If a member is declared ________, all objects of that class have access to that variable. a. dynamic b. default c. inline d. static e. None of these
d. static
17) Members of a class object are accessed with the ________. A) dot operator B) cin object C) extraction operator D) stream insertion operator E) None of these
dot operator
Members of a class object are accessed with the
dot operator
Members of a class object are accessed with the
dot operator.
The compiler performs ________ on virtual functions
dynamic binding
Which of the following operators may be used to assign one object to another? a. <> b. == c. None of these d. @ e. =
e. =
The process of object-orientated analysis can be viewed as the following steps: a. None of these b. declare public and private variables, prototype functions, and then write code c. write the main() function, then determine which classes are needed d. define data members and member functions, then assign the class name e. identify objects, then define each object's attributes, behaviors, and relationships
e. Identify objects, then define each object's attributes, behaviors, and relationships.
In C++11, you can use __ to initialize a member variable in its declaration statement. a. default initialization b. None of these c. initialization overload d. general member initialization e. In-place initialization
e. In-place initialization
The type of member function that may be called from a statement outside the class is a. global b. private c. undeclared d. None of these e. Public
e. Public
When a member function is defined outside of the class declaration, the function name must be qualified with the a. private access specifier b. None of these c. name of the first object d. class name, followed by a semicolon e. class name, followed by the scope resolution operator
e. class name, followed by the scope resolution operator
A class is a(n) ________ that is defined by the programmer. a. None of these b. function c. attribute d. method e. data type
e. data type
In the following function header, the word int is known as a(n) ________. FeetInches FeetInches::operator++(int) a. None of these b. incomplete argument c. incomplete parameter d. parameterless data type e. dummy parameter
e. dummy parameter
Which type of function is NOT a member of a class but has access to the private members of the class? a. constructor b. destructor c. None of these d. static e. friend
e. friend
Assume that myCar is an instance of the Car class and that the Car class has a member function named accelerate. Which of the following is a valid call to the accelerate member function? a. myCar::accelerate(); b. Car -> accelerate(); c. None of these d. myCar:accelerate(); e. myCar.accelerate();
e. myCar.accelerate();
A reason to overload the ________ is to allow you to write classes that have array-like behaviors. a. parentheses ( ) operator b. colon :: operator c. None of these d. curly braces { } operator e. square brackets [ ] operator
e. square brackets [ ] operator
The constructor function always has the same name as a. None of these b. the first private data member c. the first public data member d. the first object of the class e. the class
e. the class
Which of the following is automatically called when an object is destroyed? a. the specification deallocator b. None of these c. the constructor function d. the destruction function e. the destructor function
e. the destructor function
Which of the following is used to protect important data? a. the public access specifier b. None of these c. the protect member function d. the class protection operator, @ e. the private access specifier
e. the private access specifier
12) The C-string company[12] can hold ________. A) twelve characters B) thirteen characters C) eleven characters and the null terminator D) twelve characters and the null terminator E) None of the above
eleven characters and the null terminator
The C-string company[12] can hold:
eleven characters and the null terminator
Which of the following assigns a value to the hourlyWage member of employee[2]? a. employee[2] -> hourlyWage = 50.00; b. employee2.hourlyWage = 7.50; c. hourlyWage[2].employee = 29.75; d. employee[2].hourlyWage = 75.00; e. None of these
employee[2].hourlyWage = 75.00;
Two primary queue operations are:
enqueue and dequeue
A declaration for an enumerated type begins with the __________ key word. a. enumerated b. enum_type c. enum d. ENUM e. None of these
enum
A(n) ____________ is a value or an object that signals an error.
exception
Catch blocks serve as [ A ] .
exception handlers
1) True/False: A test using the isupper function will return false if the argument is an uppercase character.
false
12) True/False: Although C++ provides ample library functions to handle numeric values, we must write all of our own functions to manipulate character values.
false
2) True/False: Class objects can be defined prior to the class declaration.
false
3) True/False: The constructor function may not accept arguments.
false
4) True/False: A destructor function can have zero to many parameters.
false
4) True/False: The C++ compiler performs strict array bounds checking when it encounters an array of characters.
false
6) True/False: More than one destructor function may be defined for a class.
false
7) True/False: The strlen function returns a C-string's length and adds one for \0.
false
8) True/False: You must declare all data members of a class before you declare member functions.
false
9) True/False: The ftoa function converts a floating-point value to an ASCII value.
false
9) True/False: You must use the private access specification for all data members of a class.
false
A function cannot modify the members of a structure.
false
After the following code executes, what is the output if user enters 0? int x = -1; cout << "Enter a 0 or 1: "; cin >> x; if (c)cout << "true" << endl; elsecout << "false" << endl;
false
Before you can perform a selection sort, the data must be stored in ascending order.
false
Given the following decaration: enum Tree { OAK, MAPLE, PINE }; What is the value of the following relational expression? OAK > PINE a. true b. false c. This is an error. You cannot compare enumerators with relational operators.
false
Given the structure definition shown, assume that circle1 and circle2 are variables of the Circle type and their members have been initialized. struct Circle { double centerX; double centerY; double radius; }; Then, is it true or false that the following statement correctly determines whether the two variables' members contain the same data? if (circle1 == circle2)
false
It is possible to output the contents of all members of a structure variable using a cout << statement followed by the name of the structure variable.
false
The names of enumerators in an enumerated data type must be enclosed in quotation marks.
false
True/False: The ampersand (&) is used to dereference a pointer variable in C++.
false
True/False: With pointer variables you can access, but you cannot modify, data in other variables.
false
What is the value of the following expression? true && false
false
You cannot directly assign an enumerator to an int variable.
false
Which statement opens a file and links it to a file stream object? a) link(open(filename.txt")); b) open(aFile) = link(anObject); c) file.open("c:\\filename.txt"); d) linkstream("filename.txt"); e) none of these
file.open("c:\\filename.txt");
A queue is a data structure that stores and retrieves items in this manner.
first in, first out
A variable, usually a bool or an int, that signals when a condition exists is known as a(n)
flag
A(n) ________ informs the compiler that a class will be declared later in the program.
forward declaration
Data that is sorted in ascending order is ordered
from lowest to highest value
Data that is to be sorted in ascending order is ordered a. from lowest value to highest value b. from highest value to lowest value c. with a binary search algorithm d. by identifying the middle value and going up and down from there e. None of these
from lowest to highest value
In a dequeue operation, the element at the [ Select ] of the queue is removed.
front
When an element is added to a queue, it is added to the rear. When an element is removed, it is removed from the [ Select ] .
front
This data type can be used to create files, read information from them, and write data to them. a) stream b) fstream c) ifstream d) ofstream e) none of these
fstream
A _________ is a "generic" function that can work with different data types.
function template
This is a "generic" function that can work with any data type.
function template
The algorithms provided by the STL are implemented as _____________, and perform various operations on elements of containers.
function templates
This member function reads a single character from a file. a) read b) input c) get d) put e) none of these
get
Passing a structure as a constant reference parameter to a function a. can potentially result in changes to the structure's members b. guarantees not to result in changes to the structure's members c. will always change the structure's members d. None of these
guarantees not to result in changes to the structure's members
Object composition is useful for creating this type of relationship between classes.
has a
6) Class declarations are usually stored here. A) on separate disk volumes B) in their own header files C) in .cpp files, along with function definitions D) under pseudonyms E) None of these
in their own header files
Class declarations are usually stored here
in their own header files
When function A calls function B, which in turn calls function A, this is known as:
indirect recursion
_______ allows us to create new classes based on existing classes.
inheritance
8) When the body of a member function is defined inside a class declaration, it is said to be ________. A) static B) global C) inline D) conditional E) None of these
inline
An ________ operator can work with programmer-defined data types.
inline
When the body of a member function is defined inside a class declaration is it said to be
inline
When the body of a member function is defined inside a class declaration, it is said to be
inline
When a program lets the user know that an invalid choice has been made, this is known as:
input validation
Assume you have two integer variables, num1 and num2. Which of the following is the correct way to swap the values in these two variables? a. int temp = num1; num2 = num1; num1 = num2; b. int temp = num2; num2 = num1; num1 = temp; c. num1 = num2; num2 = num1; d. int temp = num1; num2 = temp; temp = num2; num1 = temp; e. None of these
int temp = num2; num2 = num1; num1 = temp;
The statement int *ptr; has the same meaning as
int* ptr
The constructor function's return type is not
int, float, char, or structure pointer (none of these)
With an enumerated data type, the enumerators are stored in memory as a. strings b. integers c. characters d. doubles
integers
When working with a binary tree, a node that has more than two children:
is theoretically impossible in a correctly-developed binary tree structure
17) To determine whether a character entered is a letter of the alphabet, use this function. A) isdigit B) fromkeyboard C) alphaok D) isalpha E) None of these
isalpha
1) To test whether a character is a numeric digit character, use this function. A) isnumber B) notAlpha C) isnumeric D) isdigit E) None of these
isdigit
2) To test whether a character is a printable character, use this function. A) isprint B) isprintable C) isprintok D) isoktoprint E) None of these
isprint
11) This function will return true if its argument is a printable character other than a digit, letter, or space. A) isprint B) ispunct C) ischar D) isnotdls E) None of these
ispunct
18) To determine whether a character is whitespace, use this function. A) iswhite B) isspace C) iswhitespace D) isblank E) None of these
isspace
to determine whether a character entered is whitespace, use the (blank) function
isspace
If Circle is a structure, what does the following statement do? Circle *pcirc = nullptr; a. It declares an empty structure variable named *pcirc. b. It declares a structure pointer called pcirc initialized with a null pointer. c. The statement is illegal in C++. d. It initializes a null pointer with the value of the Circle pointer. e. None of these
it declares a structure pointer called pcirc initialized with a null pointer
While traversing a list, a node pointer knows when it has reached the end of a list when:
it encounters a null pointer
A(n) _________ is like a pointer. It is used to access the individual data elements in a container.
iterator
A node that has no children is known as a ________.
leaf node
Values are typically stored in a binary search tree so that a node's ________ child holds data is less than the ________ data.
left, node's
Which line in the following program will cause a compiler error? 1 #include <iostream> 2 using namespace std; 3 int main() 4 { 5 int number = 5; 6 if (number >= 0 && <= 100) 7 cout << "passed.\n"; 8 else 9 cout << "failed.\n"; 10 return 0; 11 }
line 6
A(n) ________ search uses a loop to sequentially step through an array
linear
A(n) __________ search uses a loop to sequentially step through an array. a. binary b. unary c. linear d. relative e. None of these
linear
The _________ is adequate for searching through small arrays.
linear search
The following is the pseudocode for which type of algorithm? Set found to false Set position to -1 Set index to 0 While found is false and index < number of elements If list[index] is equal to search value found = true position = index End If Add 1 to index End While Return position a. linear sort b. linear search c. binary search d. selection sort e. None of these
linear search
These operators connect two or more relational expressions into one, or reverse the logic of an expression.
logical
20) What is the output of the following statement? cout << tolower(toupper('Z')) << endl; A) upper case Z B) lower case z C) a lower case z followed by an upper case Z D) a compiler error E) None of these
lower case z
A function __________ return a structure. a. may b. may not c. will always d. can never e. None of these
may
When you derive a class from an existing class, you ________ add new data and functions.
may
Polymorphism is when ________ in a class hierarchy perform differently, depending upon which object performs the call.
member functions
Polymorphism is when ____________ in a class hierarchy perform differently, depending upon which object performs the call.
member functions
Each object of a class has its own copy of the class's ________.
member variables
A binary search begins with the _________ element of an array
middle
A binary search begins with the __________ element of an array. a. first b. last c. largest d. middle e. None of these
middle
In a non-linear linked list, a node can point to:
more than one other node, plus the previous node in sequence
When a derived class has two or more base classes, the situation is known as ________.
multiple inheritance
When a derived class has two or more base classes, the situation is known as __________.
multiple inheritance
29) Assume that myCar is an instance of the Car class, and that the Car class has a member function named accelerate. Which of the following is a valid call to the accelerate member function? A) Car->accelerate(); B) myCar::accelerate(); C) myCar.accelerate(); D) myCar:accelerate();
myCar.accelerate();
Assume that myCar is an instance of the Car class, and that the Car class has a member function named accelerate. Which of the following is a valid call to the accelerate member function?
myCar.accelerate();
When an if statement is placed within the conditionally-executed code of another if statement, this is known as
nesting
When an ifstatement is placed within the conditionally-executed code of another ifstatement, this is known as
nesting
How much memory is reserved for a function template?
no memory
Regardless of the algorithm being used, a search through an array is always performed a. from lowest to highest element b. from highest to lowest element c. beginning with the middle element d. using a binary search algorithm e. None of these
none of these
The constructor function's return type is
none of these
The name of a structure is referred to as its a. data type b. argument c. parameter d. tag e. None of these
none of these
The destructor function's return type is
nothing. Destructors have no return type
The destructor function's return type is:
nothing. Destructors have no return type.
21) In C++, a C-string is a sequence of characters stored in consecutive memory, terminated by a ________. A) period B) space C) null character D) semicolon E) None of these
null terminator
23) A class may have this many default constructor(s). A) only one B) more than one C) a maximum of two D) any number E) None of these
only one
A class may have this many default constructor(s)
only one
A class may have this many default constructor(s).
only one
When you overload an operator, you cannot change the number of ________ taken by the operator.
operands
To overload the + operator, you would write a function named ________.
operator +
To overload the + operator, you would write a function named
operator.overload(+)
If A is a structure variable and P, a pointer, is a member of the structure, the statement cout << *A.P; will:
output the dereferenced value pointed to by P
If a is a structure variable and p, a pointer, is a member of the structure, what will the following statement do? cout << *a.p; a. output the dereferenced value pointed to by p b. result in a compiler error c. output the address stored in p d. output the value stored in a e. None of these
output the dereferenced value pointed to by p
An ________ operator can work with programmer-defined data types
overloaded
If you do not furnish one of these, an automatic memberwise copy will be performed when one object is assigned to another object.
overloaded assignment operator
A virtual function is a member function that expects to be ________ in a derived class.
overridden
C++ 11 introduces the ________ key word to help prevent subtle errors when overriding virtual functions.
override
The term ________ means the ability to take many forms.
polymorphism
When member functions behave differently, depending upon which object performed the call, this is an example of ________.
polymorphism
When member functions behave differently, depending upon which object performed the call, this is an example of ___________.
polymorphism
14) If you do not declare an access specification, the default for members of a class is ________. A) inline B) private C) public D) global E) None of these
private
20) This type of member function may be called only from a function that is a member of the same class. A) public B) private C) global D) local E) None of these
private
If you do not declare an access specification, the default for members of a class is
private
This type of member function may be called only from a function that is a member of the same class
private
This type of member function may be called only from a function that is a member of the same class.
private
5) This is used to protect important data. A) public access specifier B) private access specifier C) protect() member function D) class protection operator, @ E) None of these
private access specifier
This is used to protect important data
private access specifier
This is used to protect important data.
private access specifier
4) Examples of access specifiers are the key words: A) near and far B) opened and closed C) private and public D) table and row E) None of these
private and public
Examples of access specifiers are the keywords:
private and public
Protected members of a base class are like ________, but they may be accessed by derived classes.
private members
The base class access specification determines how ________ members in the base class may be accessed by derived classes.
private, public, and protected
13) This type of member function may be called from a statement outside the class. A) public B) private C) undeclared D) global E) None of these
public
This type of member function may be called from a statement outside the class.
public
A stack has two primary operations:
push and pop
The ________ algorithm uses recursion to efficiently sort a list. a) quicksort b) binary sort c) red/black sort d) shell sort e) none of these
quicksort
The inorder, preorder, and postorder traversals can be accomplished using ________.
recursion
Whereas<is called a relational operator,x < y is called a(n)
relational expression
Given the following code segment, what is the output? int x = 1, y = 1, z = 1; y = y + z; x = x + y; cout << "result = " << (x < y ? y : x) << endl;
result = 3
The first node in a binary tree list is called the ________.
root node
The ________ in a binary tree is similar to the head pointer in a linked list.
root pointer
27) If a local variable and a global variable have the same name within the same program, the ________ resolution operator must be used. A) variable B) ambiguity C) scope D) global E) None of these
scope
If a local variable and a global variable have the same name within the same program, the ___ resolution operator must be used.
scope
If a local variable and a global variable have the same name within the same program, the _______ resolution operator must be used.
scope
A ________ algorithm is a method of locating a specific item of information in a larger collection of data
search
A __________ algorithm is a method of locating a specific item of information in a larger collection of data. a. sort b. search c. standard d. linear e. None of these
search
The following is the pseudocode for which type of algorithm? For start = each array subscript, from the first to the next-to-last minIndex = start minValue = array[start] For index = start + 1 To size - 1 If array[index] < minValue minValue = array[index] minIndex = index End If End For swap array[minIndex] with array[start] End For a. bubble sort b. binary sort c. bubble search d. selection sort e. None of these
selection sort
The _________ sort usually performs fewer exchanges than the ________ sort
selection, bubble
The __________ sort usually performs fewer exchanges than the __________ sort. a. bubble, selection b. binary, linear c. selection, bubble d. ANSI, ASCII e. None of these
selection, bubble
Which of the following is required after the closing brace of the structure definition? a. square bracket b. period c. semicolon d. colon e. None of these
semicolon
Two types of container classes in the STL are:
sequence and associative
The advantage of a linear search is its a. complexity b. efficiency c. simplicity d. speed e. None of these
simplicity
The advantage of a linear search is its ____________
simplicity
Array elements must __________ before a binary search can be performed. a. summed b. set to zero c. positive integers d. sorted e. None of these
sorted
Array elements must be _________ before a binary search can be performed
sorted
Algorithms used to arrange random data in some order are __________ algorithms. a. standard search b. sorting c. linear d. binary search e. None of these
sorting
A reason to overload the ________ is to write classes that have array-like behaviors.
square brackets [ ] operator
C++ allows you to redefine the way ________ work when used with class objects.
standard operators
When the compiler binds a member function call with the version of the function that resides in the same class as the call itself, this is considered ________ binding.
static
23) This function concatenates the contents of one C-string with another C-string. A) strcopy B) strappend C) strcat D) stradd E) None of these
strcat
5) This function accepts a pointer to a C-string as an argument, and it returns the length of the C-string (not including the null terminator). A) numchar B) strlength C) strlen D) countstring E) None of these
strlen
24) This function accepts pointers to two C-strings and an integer argument, which indicates how many characters to copy from the second C-string to the first. A) strcpy B) strncpy C) copystring D) strintcpy E) None of these
strncpy
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. a. universal enum b. auto enum c. multi-cast enum d. strongly typed enum e. None of these
strongly typed enum
7) A library function that can find one C- string inside another is: A) strcmp B) strstr C) strfind D) strsearch E) None of these
strstr
3) A C++ class is similar to one of these. A) inline function B) header file C) library function D) structure E) None of these
structure
A C++ class is similar to one of these.
structure
a C++ class is similar to one of these.
structure
24) Objects in an array are accessed with ________, just like any other data type in an array. A) subscripts B) parentheses C) #include statements D) output format manipulators E) None of these
subscripts
Objects in an array are accessed with __, just like any other data type in an array
subscripts
Objects in an array are accessed with ___, just like any other data type in an array.
subscripts
Binary trees can be divided into:
subtrees
This statement uses the value of a variable or expression to determine where the program will branch to.
switch
If Circle is a structure tag, then the following statement can be the header line for a function that __________. Circle doSomething(Circle c2) a. determines and returns the area of a circle b. takes a Circle structure as a parameter, does something, and returns a Circle structure c. operates on a constant reference to a Circle structure d. takes two Circle parameters and does something e. None of these
takes a Circle structure as a parameter, does something, and returns a Circle structure
The beginning of a function template is marked by a ______________.
template prefix
To dereference a structure pointer, the appropriate operator is a. the ampersand (&) b. an asterisk (*) c. the -> operator d. the <- operator (<-) e. None of these
the -> operator
. A structure pointer contains a. the address of a structure variable b. the dereferenced address of a structure tag c. the name and address of the structure tag d. the address of a structure tag e. None of these
the address of a structure variable
21) The constructor function always has the same name as ________. A) the first private data member B) the first public data member C) the class D) the first object of the class E) None of these
the class
The constructor function always has the same name as
the class
If you place a semicolon after the statement: if (x < y)
the compiler will interpret the semicolon as a null statement
Which of the following will allow you to access structure members? a. the structure access operator b. the dot operator c. the #include<structaccess> directive d. the getmember function e. None of these
the dot operator
The __________ is adequate for searching through small arrays. a. binary search b. the linear search c. unary search d. bubble sort e. None of these
the linear search
A doubly-linked list keeps track of the next node in the list, as well as:
the previous node
When an application begins searching a binary tree, it starts at ________.
the root node
In a binary tree class, you usually have a pointer as a member that is set to ________.
the root of the tree
To dereference a structure pointer and simultaneously access a member of the structure, the appropriate operator to use is:
the structure pointer operator, ->
To dereference a structure pointer and simultaneously access a member of the structure, the appropriate operator to use is:
the structure pointer operator: ->
A binary tree with a height of three has:
three levels
A good reason to use the binary tree structure is:
to expedite the process of searching large sets of information
A good reason to pass a structure as a constant reference is a. to prevent changes to the structure's members b. to ensure changes to the structure's members c. to slow down the function's execution which helps prevent errors d. to speed up the function's modification of the structure's members e. None of these
to prevent changes to the structure's memebrs
the (blank) function will change a character argument from uppercase to lowercase
tolower
19) To change a character argument from lower to upper case, use this function. A) isupper B) toupper C) tolarge D) fromlower E) None of these
toupper
26) To change a lower case character to an upper case character, use this function. A) atoi B) itoa C) ltou D) toupper E) None of these
toupper
The default section of a switch statement performs a similar task similar to the __________ portion of an if/else if statement.
trailing else
The defaultsection of a switchstatement performs a similar task similar to the __________ portion of an if/elseifstatement.
trailing else
The process of stepping through the nodes of a binary tree is known as ________.
traversing
. A struct can contain members with varying data types.
true
1) True/False: Whereas object-oriented programming centers on the object, procedural programming centers on functions.
true
10) 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
10) True/False: If a C-string that cannot be converted to a numeric value is passed to the atoi function, the function's behavior is undefined by C++.
true
11) True/False: If an uppercase character is passed as an argument to toupper, the result will be an uppercase character.
true
11) True/False: If you do not declare a destructor function, the compiler will furnish one automatically.
true
12) True/False: When an object is defined without an argument list for its constructor, the compiler automatically calls the object's default constructor.
true
13) True/False: One purpose that constructor functions are often used for is to allocate memory that will be needed by the object.
true
13) True/False: You may use the <, >, <=, >=, ==, and != relational operators to compare string objects.
true
14) True/False: C++ 11 introduces a function named to_string that converts a numeric value to a string object.
true
14) True/False: One purpose that destructor functions are often used for is to free memory that was allocated by the object.
true
15) True/False: The string class's front and back member functions were introduced in C++ 11.
true
15) True/False: When using smart pointers to dynamically allocate objects in C++ 11, it is unnecessary to delete the dynamically allocated objects because the smart pointer will automatically delete them.
true
2) True/False: The isdigit function will return a true if its argument is a digit between 0 and 9.
true
3) True/False: When using the strcat function, you must be careful not to overwrite the bounds of an array.
true
5) True/False: More than one constructor function may be defined for a class.
true
5) True/False: The itoa function is similar to atoi, but it works in reverse.
true
6) True/False: By being able to pass arrays as arguments, you can write your own functions for processing C-strings.
true
7) True/False: Object-oriented programming is centered around the object, which encapsulate together both the data and the functions that operate on the data.
true
8) True/False: The C++ library provides functions for converting a string representation of a number to a numeric data type, and vice-versa.
true
Any mathematical operation that can be performed on regular C++ variables can be performed on structure members.
true
C++ 11 introduces a function named to_string that converts a numeric value to a string object
true
If a function is legally prototyped to return an integer value, it can return a structure member that is an integer data type.
true
In C++11 if you want to retrieve a strongly typed enumerator's underlying integer value, you must use a cast operator.
true
It is possible for a structure to contain, as a member, a pointer to its own structure type.
true
It is possible for a structure variable to be a member of another structure variable.
true
Structure variables may be passed as arguments to functions.
true
The expression *s->p; indicates that s is a structure pointer and p, which is also a pointer, is a member of the structure pointed to by s.
true
The expression s->m; indicates that s is a structure pointer and m is a structure member.
true
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: A pointer can be used as a function argument, giving the function access to the location of the actual parameter.
true
True/False: C++ does not perform array bounds checking, making it possible for you to assign a pointer the address of an element out of the boundaries of an array.
true
True/False: It is possible for a structure to contain as a member a pointer to its own structure type.
true
True/False: Not all arithmetic operations may be performed on pointers.
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: Variables cannot be created when a program is already running.
true
What is the value of the following expression? true && !false
true
What is the value of the following expression? true && true
true
What is the value of thefollowing expression? true || false
true
When a programmer creates an abstract data type, he or she can decide what values are acceptable for the data type, as well as what operations may be performed on the data type.
true
When you use a strongly typed enumerator in C++11 you must prefix the enumerator with the name of the enum followed by the :: operator.
true
You cannot directly assign an integer value to an enum variable.
true
the isdigit function will return true if the argument is a digit between 0 and 9
true
when using the strcat function you must be careful not to overwrite the bounds of an array
true
6) The strcpy function's arguments are: A) two C-strings B) two addresses C) three pointers D) one array and one pointer E) None of these
two addresses
the arguments of the strcpy function are:
two addresses
A binary tree can be created using a struct or class containing a data value and ________.
two pointers, one for the left child and one for the right child
How many steps are involved in the process of deleting a node?
two—remove the node without breaking links, then delete it from memory
Any time you use the new operator, it is good practice to:
use delete afterwards to free the memory allocated by new
30) The statement: char var1 = tolower('A'); will result in: A) var1 storing the character value 'A'. B) var1 storing the ASCII value for lower case 'a'. C) A is output to the monitor. D) a is output to the monitor. E) None of these
var1 storing the ASCII value for lower case 'a'.
The three sequence container objects provided by the STL are:
vector, deque, list
In the following statement: class car : public vehicle ________ is the base class.
vehicle
A virtual function is declared by placing the key word ________ in front of the return type in the base class's function declaration.
virtual
A virtual function is declared by placing the keyword _______ in front of the return type in the base class's function declaration.
virtual
Declaring a member function of a class to be a __________ will cause the C++ compiler to use dynamic binding.
virtual function
The delete operator should only be used on pointers that
were created with the new operator
The following statement __________. bookList[2].publisher[3] = 't'; a. is illegal in C++ b. will change the name of the second book in bookList to 't' c. will store the character 't' in the fourth element of the publisher member of bookList[2] d. will result in a runtime error e. None of these
will store the character 't' in the fourth element of the publisher member of bookList[2]
A good reason for overloading an operator is to enable it to ________.
work in its usual way, but with programmer-defined data types
This member function can be used to store binary data to a file. a) write b) put << c) dataout(binary) d) binary.out e) none of these
write
Which of the following expressions will determine whether xis less than or equal to y?
x <= y
For the following code, which statement is not true? class Point{ private: double y; double z; public: double x; };
z is available to code that is written outside the class
28) For the following code, which statement is not true? class Point { private: double y; double z; public: double x; }; A) x is available to code that is written outside the class. B) The name of the class is Point. C) x, y, and z are called members of the class. D) z is available to code that is written outside the class.
z is available to code that is written outside the class.
For the following code, which statement is not true? class Point { private: double y; double z; public: double x; };
z is available to code that is written outside the class. Answers: x is available to code that is written outside the class. The name of the class is Point. x, y, and z are called members of the class.
The recursive factorial function calculates the factorial of its parameter. Its base case is when the parameter is _______.
zero
This operator represents the logical OR:
||
The following is the pseudocode for which type of algorithm? Set first to 0 Set last to the last subscript in the array Set found to false Set position to -1 While found is not true and first is less than or equal to last Set middle to the subscript halfway between array[first] and array[last] If array[middle] equals the desired value Set found to true Set position to middle Else If array[middle] is greater than the desired value Set last to middle - 1 Else Set first to middle + 1 End If End While Return position a. linear sort b. linear search c. binary search d. selection sort e. None of these
binary search
When a binary tree is used to facilitate a search, it is referred to as a ________.
binary search tree
A __________ search is more efficient than a __________ search. a. character, string b. integer, double c. binary, linear d. linear, binary e. None of these
binary, linear
A(n) ________ search is more efficient than a(n) ________ search
binary, linear
13) Look at the following statement. if (!isdigit(var1)) The expression being tested by this statement will evaluate to true if var1 is: A) an alphabetic character B) 9 C) a symbol such as $ or & D) both A and C E) None of these
both A and C
Without this statement appearing in a switch construct, the program "falls through" all of the statements below the one with the matching case expression.
break
Without this statement appearing in aswitchconstruct, the program "falls through" all of the statements below the one with the matching case expression.
break
The following is the pseudocode for which type of algorithm? For maxElement = each subscript in the array, from the last to the first For index = 0 To maxElement - 1 If array[index] > array[index + 1] swap array[index] with array[index + 1] End If End For End For a. bubble sort b. binary sort c. bubble search d. selection sort e. None of these
bubble sort
When a structure is passed __________ to a function, its members are not copied. a. by reference b. by value c. Either of these d. Neither of these
by reference
The bad_alloc exception is thrown
by the new operator
Which statement allows you to properly check the char variable code to determine whether it is equal to a C and then output This is a check? Question options: A) if code is equal to C cout << "This is a check\n"; B) if (code = "C") cout << "This is a check\n"; C) if (code == 'C') cout << "This is a check\n"; D) if (code == C) cout << "This is a check" << endl;
c if (code == 'C') cout << "This is a check\n";
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 test; return 0; } a. the program runs but there is no output. b. 0 c. Hello! d. the program will not compile
c. Hello!
The constructor function's return type is a. char b. int c. None of these d. float e. structure pointer
c. None of these
When a constructor function accepts no arguments, or does NOT have to accept arguments because of default arguments, it is called a(n) a. stand-alone function b. arbitrator function c. default constructor d. None of these e. empty constructor
c. default constructor
Examples of access specifiers are the key words: a. opened and closed b. none of these c. private and public d. near and far e. table and row
c. private and public
C++ allows you to redefine the way ________ work when used with class objects. a. preprocessor directives b. undefined variables c. standard operators d. compiler errors e. None of these
c. standard operators
The ________ member variable may be accessed before any objects of the class have been created. a. private b. public c. static d. None of these e. Inline
c. static
A(n) ________ is a special built-in pointer that is available to a class's member functions. a. &constructor pointer b. None of these c. this pointer d. ~destructor *ptr e. overload operator, ->
c. this pointer
A good reason to overload an operator is to enable it to a. None of these b. operate on no operands c. work in its usual way, but with programmer-defined data types d. outperform its C language counterparts e. operate on more operands than in its standard definition
c. work in its usual way, but with programmer-defined data types
A structure __________ contain members of the same data type. a. cannot b. can c. shouldn't d. None of these
can
The try block is immediately followed by one or more _____________.
catch blocks
28) To define a C-string that will store students' last names of up to 25 characters in length, which is an appropriate statement? A) char lastName[25]; B) string lastName[25]; C) char lastName[26]; D) string lastName[24]; E) None of these
char lastName[26];
29) Which of the following lines of code defines an array of C-strings that will hold 49 characters and the null terminator? A) char [49]; B) char str[50]; C) char[50] str; D) character str[50]; E) None of the above
char str[50];
When the root node points to two other nodes, the nodes are referred to as ________.
child nodes, or children
This type of list does not contain a null pointer at the end of the list.
circular-linked
In the following statement: template <class T> What does the word class indicate?
class is a key word that is used to precede the type parameter T.
26) When a member function is defined outside of the class declaration, the function name must be qualified with the ________. A) class name, followed by a semicolon B) class name, followed by the scope resolution operator C) name of the first object D) private access specifier E) None of these
class name, followed by the scope resolution operator
When a member function is defined outside of the class declaration, the function name must be qualified with the:
class name, followed by the scope resolution operator
The queue data structure is commonly applied in connection with:
communications software managing the order of print jobs operating systems
Relational operators allow you to __________ numbers.
compare
Recursion can be used to:
compute factorials find GCD's
It is a good idea to make a copy constructor's parameters [ Select ] by specifying the [ Select ] key word in the parameter list.
constant const
9) A ________ is a member function that is automatically called when a class object is ________. A) destructor, created B) constructor, created C) static function, deallocated D) utility function, declared E) None of these
constructor, created
A ___ is a member function that is automatically called when a class object is ___
constructor, created
A _____ is a member function that is automatically called when a class object is ______
constructor, created
If you do not furnish one of these a default will be provided for you by the compiler.
copy constructor
This is a special function that is called whenever a new object is created and initialized with another object's data.
copy constructor
When objects contain pointers, it is a good idea to create an explicit ________ function.
copy constructor
Which of the following statements outputs the value of the gpa member of element [1] of the student array? a. cout << student1.gpa; b. cout << firstStudent.gpa; c. cout << student[1].gpa; d. cout << student1->gpa; e. None of these
cout << student[1].gpa;
If you do NOT furnish a ________, a default one will be provided by the compiler. a. constructor b. destructor c. copy constructor d. All of these e. None of these
d. All of these
The destructor function's return type is a. float b. None of these c. char d. Nothing; destructors have no return type e. int
d. Nothing; destructors have no return type
When a constructor has a member initialization list, the initializations take place a. after any statements in the body of the constructor execute b. None of these c. when a member is used in the execution of the program d. before any statements in the body of the constructor execute
d. before any statements in the body of the constructor execute.
In a procedural program you typically have ________ stored in a collection of variables and a set of ________ that perform operations on the data. a. numbers, arguments b. parameters, arguments c. None of these d. data, functions e. strings, operators
d. data, functions
This operator represents the logical AND:
&&
What is the value of average after the following code executes? double average; average = 1.0 + 2.0 + 3.0 / 3.0; a. 2.0 b. 3.0 c. 4.0 d. 2 e. unknown
C
What is the value of cube after the following code executes? double cube, side; side = 5.0; cube = pow(side, 3.0); a. 25.0 b. 15.0 c. 125.0 d. 8.0 e. unknown
C
What is the value of number after the following statements execute? int number = 10; number += 5; number -= 2; number *= 3; a. 3 b. 30 c. 39 d. 2 e. None of these
C
What is the value of x after the following code executes? int x = 0; int y = 5; int z = 4; x = x + y + z * 2; a. 18 b. 0 c. 13 d. 26 e. unknown
C
________ is commonly used to extend a class, or to give it additional capabilities.
Inheritance
In an inheritance situation, the new class that you create from an existing class is known as the ________.
derived class and child class
The ________ destructor is called before the ________ destructor.
derived, base
Multiple inheritance is when a ________ class has ________ base classes.
derived, two or more
When an array is sorted from highest to lowest, it is said to be in _____ order
descending
When an array is sorted from highest to lowest, it is said to be in a. reverse order b. forward order c. ascending order d. descending order e. None of these
descending order
22) This is automatically called when an object is destroyed. A) constructor function B) specification deallocator C) destructor function D) coroner function E) None of these
destructor function
This automatically called when an object is destroyed
destructor function
This is automatically called when an object is destroyed.
destructor function
The shape of a binary tree is ________.
determined by the order in which values are inserted
his operator takes an operand and reverses its truth or falsehood:
!
Which of the following is evaluated first, given the expression: A && B || C && !D
!D
Which of the following is evaluated first, given the expression: A && B || C && !D
!D (best guess)
7) This directive is used to create an "include guard," which allows a program to be conditionally compiled. This prevents a header file from accidentally being included more than once. A) #include B) #guard C) #ifndef D) #endif E) None of these
#ifndef
This directive is used to create an "include guard" which allows a program to be conditionally compiled. This prevents a header file from accidentally being included more than once
#ifndef
This directive is used to create an "include guard," which allows a program to be conditionally compiled. This prevents a header file from accidentally being included more than once.
#ifndef
to use the strlen function in a program you must include
#include <cstring>
What will be displayed after the following statements execute? int funny = 7, serious = 15; funny = serious % 2; if (funny != 1) { funny = 0; serious = 0; } else if (funny == 2) { funny = 10; serious = 10; } else { funny = 1; serious = 1; } cout << funny << " " << serious << endl;
10 10
25) After the following statement executes, what value is stored in the variable num? num = atoi("1000"); A) 1000 B) 999 (1000 minus 1 for the null terminator) C) "1000" D) "thousand" E) None of these
1000
What is the value of donutsafter the following statement executes? int donuts = 10; if (donuts != 10) donuts = 0; else donuts += 2;
12
What is the output of the following segment of code if the value 4 is input by the user? 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;
13
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
After the following code executes, what is the value of my_valueif 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
In the following statement: class car : protected vehicle What is being protected?
Base class members
The ________ constructor is called before the ________ constructor.
Base, Derived
A debugging process where you, the programmer, pretend you are a computer and step through each statement while recording the value of each variable at each step is known as a. error checking b. hand writing c. hand tracing d. error handling e. None of these
C
Associativity is either right to left or a. top to bottom b. front to back c. left to right d. undeterminable e. None of these
C
The __________ operator always follows the cin object, and the __________ operator follows the cout object. a. binary, unary b. conditional, binary c. >>, << d. <<, >> e. None of these
C
This manipulator causes the field to be left justified with padding spaces printed to the right: a. left_justify b. right c. left d. left_pad e. None of these
C
This manipulator forces cout to print digits in fixed-point notation: a. setprecision(2) b. setw(2) c. fixed d. setfixed(2) e. None of these
C
This manipulator is used to establish a field width for the value that follows it: a. field_width b. set_field c. setw d. iomanip e. None of these
C
private and public
Examples of access specifiers are the key words:
These are used to signal errors or unexpected events that occur while a program is running.
Exceptions
Arithmetic operators that share the same precedence have right to left associativity T/F
F
If the expression on the left side of the following is false, the expression on the right side will not be checked. (a > = b) && (c == d)
F
If you want to know the length of the string that is stored in a string object, you can call the object's size member function T/F
F
In C++, it is impossible to display the number 34.789 in a field of 9 spaces with 2 decimal places of precision. T/F
F
The conditional operator takes two operands
F
The default section is required in a switch statement
F
The fixed manipulator causes a number to be displayed in scientific notation
F
The following code correctly determines whether x contains a value in the range of 0 through 100, inclusive. if (x > 0 && <= 100)
F
The following statement will output $5.00 to the screen: cout << setprecision(5)<< dollars << endl T/F
F
The value of result in the following expression will be 0 if x has the value of 12. result = x > 100 ? 0 : 1;
F
When a program uses the setw manipulator, the iosetwidth header file must be included in a preprocessor directive. T/F
F
30) 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 test; return 0; } A) The program runs, but with no output. B) 0 C) Hello! D) The program will not compile.
Hello!
What is true about the following statement? out.open("values.dat", ios::app); a) If the file exists, it can be opened but not modified b) if the file exists, it should be replaced with a new copy of values.dat c) if the file already exists, its contents are preserved and all output is written to the end of the file d) None of these
If the file already exists, its contents are preserved and all output is written to the end of the file
private
If you do not declare an access specification, the default for members of a class is ________.
attributes, methods
In OOP terminology, an object's member variables are often called its ________, and its member functions are sometimes referred to as its behaviors, or ________.
data, functions
In a procedural program, you typically have ________ stored in a collection of variables, and a set of ________ that perform operations on the data.
Class declarations are usually stored here
In their own header files
When function A calls function B, which in turn calls function A, this is known as: a) perfect recursion b) direct recursion c) indirect recursion d) function swapping e) none of these
Indirect recursion
This type of member function may be called from a statement outside the class. a) public b) private c) undeclared d) global
Public
A _________ function is one that calls itself. a) static b) data validation c) dynamic d) recursive e) none of these
Recursive
___________ algorithms are used to arrange random data into some order
Sorting
In OOP terminology, an object's member variables are often called it's ___ and its member functions can be referred to as it behaviors or its ___. a. attributes, activities b. attributes, methods c. None of these d. data, activities e. values, morals
b. attributes, methods
It is a good idea to make a copy constructor's parameters ___ by specifying the ___ key word in the parameter list. a. inline, inline b. constant, const c. None of these d. global, global e. static, static
b. constant, const
A(n) ___ is a special function that is called whenever a new object is created and initialized with another object's data. a. None of these b. copy constructor c. static function d. assignment function e. Destructor
b. copy constructor
When objects contain pointers, it is a good idea to create an explicit ___ function. a. inline constructor b. copy constructor c. static constructor d. None of these e. destructor
b. copy constructor
Members of the class object are accessed with the __. a. cin object b. dot operator c. None of these d. extraction operator e. stream insertion operator
b. dot operator
A member function that is declared ________ may not access any non-static data members in the class. a. public b. inline c. private d. static e. None of these
d. static (Confusing wording on the question. When a variable is static, the value of that variable is THE SAME across all instances of a class, so all instances of that class have access to THE SAME VALUE stored in that variable. So, if one instance of a class sets a static variable to be, say, -1, then ALL instances of that class will have a -1 for that variable, regardless of whether or not they were created before or after the one object set it to -1.)
16) A class is a(n) ________ that is defined by the programmer. A) data type B) function C) method D) attribute E) None of these
data type
A class is a(n) __ that is defined by the programmer
data type
A class is a(n) ___ that is defined by the programmer.
data type
1) Objects are created from abstract data types that encapsulate ________ and ________ together. A) numbers, characters B) data, functions C) addresses, pointers D) integers, floats E) None of these
data, functions
15) In a procedural program, you typically have ________ stored in a collection of variables, and a set of ________ that perform operations on the data. A) numbers, arguments B) parameters, arguments C) strings, operators D) data, functions E) None of these
data, functions
In a procedural program, you typically have ___ stored in a collection of variables, and a set of ___ that perform operations on the data.
data, functions
Objects are created from abstract data types that encapsulate ___ and ___ together.
data, functions
Objects are created from abstract data types that encapsulate _______ and _______ together. a) numbers, characters b) data, functions c) addresses, pointers d) integers, floats
data, functions
In a procedural program, you typically have __ stored in a collection of variables, and a set of __ that perform operations on data
data,functions
Which of the following statements opens the file info.txt for both input and output? a) dataFile.open("info.txt", ios::in, ios::out); b) dataFile.open("info.txt", ios::in | ios::out); c) dataFile.open("info.txt", ios::in || ios::out); d) dataFile.open("info.txt", ios::in && ios::out);
dataFile.open("info.txt", ios::in | ios::out);
Before a structure can be used it must be a. declared b. dereferenced c. initialized d. All of these e. None of these
declared
12) When a constructor function accepts no arguments, or does not have to accept arguments because of default arguments, it is called a(n) ________. A) empty constructor B) default constructor C) stand-alone function D) arbitrator function E) None of these
default constructor
When a constructor function accepts no arguments, or does not have to accept arguments because of default arguments, it is called a(n):
default constructor
18) Assuming that Rectangle is a class name, the statement: Rectangle *BoxPtr; A) declares an object of class Rectangle B) assigns the value of *BoxPtr to the object Rectangle C) defines a Rectangle pointer variable called BoxPtr D) is illegal in C++ E) None of these
defines a Rectangle pointer variable called BoxPtr
Assuming that Rectangle is a class name the statement Rectangle *BoxPtr
defines a Rectangle pointer variable called BoxPtr
Assuming that Rectangle is a class name, the statement Rectangle *BoxPtr;
defines a Rectangle pointer variable called BoxPtr
If Circle is a structure type, the statement Circle *pcirc;
defines a structure pointer called pcirc
Which of the following statements deletes memory that has been dynamically allocated for an array?
delete [] array;
The base case of a recursive function
depends on the problem being solved
This is a container that provides quick access to elements at the front and the back of the list.
deque
This is a double-ended queue.
deque