BTE320 Chapter 8, BTE320 Chapter 9, BTE320 Chapter 10, BTE320 Chapter 12, BTE320 Chapter 15
Consider the following statements: void pointerParameters(int* &p, double *q) { . . . } In the function pointerParameters, the parameter q is a(n) ____________________ parameter.
value
If a class object is passed by ____________________, the contents of the member variables of the actual parameter are copied into the corresponding member variables of the formal parameter.
value
The copy constructor automatically executes when, as a parameter, an object is passed by ____________________.
value
The ____________________ of a base class automatically makes the destructor of a derived class virtual.
virtual destructor
Arrays can be passed as parameters to a function by value, but it is faster to pass them by reference. a. True b. False
False
Given the declaration int list[20]; the statement list[12] = list[5] + list[7]; updates the content of the twelfth component of the array list. a. True b. False
False
If an array index goes out of bounds, the program always terminates in an error. a. True b. False
False
The statement that declares board to be an array of six pointers wherein each pointer is of type int is: int ____________________;
*board[6]
The following statement defines a struct houseType with a total of ____________________ member(s). struct houseType { string style; int numOfBedrooms; int numOfBathrooms; int numOfCarsGarage; int yearBuilt; };
5
In the Tower of Hanoi recursive program, if needle 1 contains three disks, then the number of moves required to move all three disks from needle 1 to needle 3 is 8. a. True b. False
False
Infinite recursions execute forever on a computer. a. True b. False
False
Suppose list is a one dimensional array of size 25, wherein each component is of type int. Further, suppose that sum is an int variable. The following for loop correctly finds the sum of the elements of list. sum = 0; for (int i = 0; i < 25; i++) sum = sum + list; a. True b. False
False
The array index can be any integer less than the array size. a. True b. False
False
The following is an example of a recursive function, where nextNum is a function such that nextNum(x) = x + 1. int recFunc(int x) { return nextNum(nextNum(x)); } a. True b. False
False
The ____________________ of an array is the address (that is, the memory location) of the first array component.
Base address
A class and its members can be described graphically using a notation known as the ____ notation. a. OON b. OOD c. UML d. OOP
C. UML
The statement int list[25]; declares list to be an array of 26 components, since the array index starts at 0. a. True b. False
False
With recursion, the base case must eventually be reduced to a general case. a. True b. False
False
Consider the following recursive definition, where n is a positive integer. F(1) = 3 F(n) = F(n - 1) + 1 if n > 1 The value of F(3) is ____________________.
ANSWER: 5
In the Tower of Hanoi problem, if needle 1 contains three disks, then the number of moves required to move all three disks from needle 1 to needle 3 is ____________________.
ANSWER: 7
The recursive algorithm must have one or more base cases, and the general solution must eventually be reduced to a(n) ____________________.
ANSWER: base case
The ____________________ Fibonacci number in a sequence is the sum of the second and third Fibonacci numbers.
ANSWER: fourth 4th
If a function A calls a function B and function B calls function A, then function A is ____________________ recursive.
ANSWER: indirectly
Suppose that function A calls function B, function B calls function C, function C calls function D, and function D calls function A. Function A is then ____________________ recursive.
ANSWER: indirectly
If you execute an infinite recursive function on a computer, the function executes until the system runs out of ____________________.
ANSWER: memory
Recursive algorithms are implemented using ____________________ functions.
ANSWER: recursive
Consider the following code. int fact(int num) { if (num == 0) return 1; else return num * fact(num - 1); } The function fact is an example of a(n) ____________________ recursive function.
ANSWER: tail
The code int *p; declares p to be a(n) ____ variable. a. new b. num c. pointer d. address
c. pointer
In a(n) ____________________ data type, each data item is a collection of other data items.
Structured
In C++, the ____ is called the member access operator. a. . b. , c. :: d. #
a. .
The syntax for accessing a struct member is structVariableName____. a. .memberName b. *memberName c. [memberName] d. $memberName
a. .memberName
If a member of a class is ____, you cannot access it outside the class. a. public b. automatic c. private d. static
c. private
All components of an array are of the same data type. a. True b. False
True
Every call to a recursive function requires the system to allocate memory for the local variables and formal parameters. a. True b. False
True
In a recursive function, the base case stops the recursion. a. True b. False
True
In a two-dimensional array, the elements are arranged in a table form. a. True b. False
True
The following is a valid recursive definition to determine the factorial of a non-negative integer. 0! = 1 1! = 1 n! = n * (n - 1)! if n > 0 a. True b. False
True
The following is an example of a recursive function. void print(int x) { if (x > 0) { cout << x << " " ; print (x - 1); } } a. True b. False
True
The one place where C++ allows aggregate operations on arrays is the input and output of C-strings. a. True b. False
True
To design a recursive function, you must determine the limiting conditions. a. True b. False
True
When you pass an array as a parameter, the base address of the actual array is passed to the formal parameter. a. True b. False
True
You can use a recursive algorithm to find the largest element in an array. a. True b. False
True
In C++, ____ is called the address of operator. a. & b. * c. # d. ->
a. &
In C++, the null character is represented as ____. a. '\0' b. "\0" c. '0' d. "0"
a. '\0'
In C++, you declare a pointer variable by using the ____ symbol. a. * b. & c. # d. @
a. *
A ____ sign in front of a member name on a UML diagram indicates that this member is a public member. a. + b. - c. # d. $
a. +
Assume you have the following declaration char nameList[100];. Which of the following ranges is valid for the index of the array nameList? a. 0 through 99 b. 0 through 100 c. 1 through 100 d. 1 through 101
a. 0 through 99
Assume you have the following declaration double salesData[1000];. Which of the following ranges is valid for the index of the array salesData? a. 0 through 999 b. 0 through 1000 c. 1 through 1001 d. 1 through 1000
a. 0 through 999
Consider the accompanying definition of a recursive function. What is the output of the following statement? cout << recFunc(10) << endl; a. 10 b. 11 c. 100 d. 110
a. 10
Consider the following definition of the recursive function mystery. int mystery(int num) { if (num <= 0) return 0; else if (num % 2 == 0) return num + mystery(num - 1); else return num * mystery(num - 1); } What is the output of the following statement? cout << mystery(5) << endl; a. 50 b. 65 c. 120 d. 180
a. 50
int puzzle(int start, int end) { if (start > end) return start - end; else if (start == end) return start + end; else return end * puzzle(start + 1, end - 1); } Consider the accompanying definition of a recursive function. What is the output of the following statement? cout << puzzle(5, 10) << endl; a. 720 b. 5040 c. 5760 d. 10800
a. 720
Which of the following is true about classes and structs? a. By default, all members of a struct are public and all members of a class are private. b. A struct variable is passed by value only, and a class variable is passed by reference only. c. An assignment operator is allowed on class variables, but not on struct variables. d. You cannot use the member access specifier private in a struct.
a. By default, all members of a struct are public and all members of a class are private.
Which of the following arithmetic operations is allowed on pointer variables? a. Increment b. Modulus c. Multiplication d. Division
a. Increment
Which of the following solution methods would be the best choice for a mission control system? a. Iterative b. Direct recursive c. Indirect recursive d. Infinite recursive
a. Iterative
____ control structures use a looping structure, such as while, for, or do...while, to repeat a set of statements. a. Iterative b. Recursive c. Procedural d. Object
a. Iterative
Which of the following solutions is easier to construct for the Tower of Hanoi problem? a. Recursive b. Iterative c. Procedural d. Step-by-step
a. Recursive
Consider the following statement: int alpha[25][10];. Which of the following statements about alpha is true? a. Rows of alpha are numbered 0...24 and columns are numbered 0...9. b. Rows of alpha are numbered 0...24 and columns are numbered 1...10. c. Rows of alpha are numbered 1...24 and columns are numbered 0...9. d. Rows of alpha are numbered 1...25 and columns are numbered 1...10.
a. Rows of alpha are numbered 0...24 and columns are numbered 0...9.
A class is an example of a structured data type. a. True b. False
a. True
A function can return a value of the type struct. a. True b. False
a. True
A memory leak is an unused memory space that cannot be allocated. a. True b. False
a. True
A pointer variable is a variable whose content is a memory address. a. True b. False
a. True
Data in a struct variable must be read one member at a time. a. True b. False
a. True
Given the declaration int *p; The statement p = new int[50]; dynamically allocates an array of 50 components of type int and p contains the base address of the array. a. True b. False
a. True
If an object is declared in the definition of a member function of the class, then the object can access both the public and private members of the class. a. True b. False
a. True
If p is a pointer variable, the statement p = p + 1; is valid in C++. a. True b. False
a. True
In C++ terminology, a class object is the same as a class instance. a. True b. False
a. True
In C++, class is a reserved word and it defines only a data type. a. True b. False
a. True
The dereferencing operator is also known as the indirection operator and refers to the object to which its operand points. a. True b. False
a. True
To access a structure member (component), you use the struct variable name together with the member name; these names are separated by a dot (period). a. True b. False
a. True
You can declare struct variables when you define a struct. a. True b. False
a. True
You can use an assignment statement to copy the contents of one struct into another struct of the same type. a. True b. False
a. True
A member function of a class that only accesses the value(s) of the data member(s) is called a(n) ____ function. a. accessor b. mutator c. constructor d. destructor
a. accessor
Which of the following class definitions is correct in C++? a. class studentType { public: void setData(string, double, int); private: string name; }; b. class studentType { public: void setData(string, double, int); void print() const; private: string name; double gpa; } c. class studentType { public void setData(string, double, int); private string name; }; d. studentType class { public: void setData(string, double, int); private: string name; };
a. class studentType { public: void setData(string, double, int); private: string name; };
In row order form, the ____. a. first row is stored first b. first row is stored last c. first column is stored first d. first column is stored last
a. first row is stored first
Given the declaration int *a;, the statement a = new int[50]; dynamically allocates an array of 50 components of the type ____. a. int b. int* c. pointer d. address
a. int
Which of the following statements declares alpha to be an array of 25 components of the type int? a. int alpha[25]; b. int array alpha[25]; c. int alpha[2][5]; d. int array alpha[25][25];
a. int alpha[25];
Consider the following declaration: int alpha[5] = {3, 5, 7, 9, 11};. Which of the following is equivalent to this statement? a. int alpha[] = {3, 5, 7, 9, 11}; b. int alpha[] = {3 5 7 9 11}; c. int alpha[5] = [3, 5, 7, 9, 11]; d. int alpha[] = (3, 5, 7, 9, 11);
a. int alpha[] = {3, 5, 7, 9, 11};
Consider the statement int list[10][8];. Which of the following about list is true? a. list has 10 rows and 8 columns. b. list has 8 rows and 10 columns. c. list has a total of 18 components. d. list has a total of 108 components.
a. list has 10 rows and 8 columns.
A class object can be ____. That is, it can be created once, when the control reaches its declaration, and destroyed when the program terminates. a. static b. automatic c. local d. public
a. static
In ____ binding, the necessary code to call a specific function is generated by the compiler. a. static b. dynamic c. shallow d. deep
a. static
Which of the following struct definitions is correct in C++? a. struct studentType { int ID; }; b. struct studentType { string name; int ID; double gpa; } c. int struct studentType { ID; } d. struct studentType { int ID = 1; };
a. struct studentType { int ID; };
In C++, virtual functions are declared using the reserved word ____. a. virtual b. private c. public d. struct
a. virtual
Consider the following statements: class shape { public: virtual void draw() = 0; virtual void move(double x, double y) = 0; . . . }; The code above is an example of a(n) ____________________ class definition.
abstract
In C++, the ____ symbol is an operator, called the member access operator. a. :(colon) b. .(dot) c. ,(comma) d. $ (dollar sign)
b. .(dot)
What is the output of the following code? int *p; int x; x = 12; p = &x; cout << x << ", "; *p = 81; cout << *p << endl; a. 12, 12 b. 12, 81 c. 81, 12 d. 81, 81
b. 12, 81
Consider the following definition of the recursive function mystery. int mystery(int first, int last) { if (first > last) return 0; else if (first == last) return first; else return first + mystery(first + 1, last - 1); } What is the output of the following statement? cout << mystery(6, 10) << endl; a. 13 b. 21 c. 40 d. 42
b. 21
Consider the following statement: double alpha[10][5];. The number of components of alpha is ____. a. 15 b. 50 c. 100 d. 150
b. 50
In C++, the scope resolution operator is ____. a. : b. :: c. $ d. .
b. ::
Which of the following is an allowable aggregate operation on a struct? a. Arithmetic b. Assignment c. Input/output d. Comparison
b. Assignment
A function can return a value of the type array. a. True b. False
b. False
Aggregate input/output operations are allowed on a struct variable. a. True b. False
b. False
As parameters to a function, class objects can be passed by reference only. a. True b. False
b. False
Given the declaration class myClass { public: void print(); //Output the value of x; MyClass(); private: int x; }; myClass myObject; The following statement is legal. myObject.x = 10; a. True b. False
b. False
If an object is created in a user program, then the object can access both the public and private members of the class. a. True b. False
b. False
If the heading of a member function of a class ends with the word const, then the function member cannot modify the private member variables, but it can modify the public member variables. a. True b. False
b. False
In C++, pointer variables are declared using the reserved word pointer. a. True b. False
b. False
In C++, the dot operator has a lower precedence than the dereferencing operator. a. True b. False
b. False
In C++, the member access operator arrow is >>. a. True b. False
b. False
In structs, you access a component by using the struct name together with the relative position of the component. a. True b. False
b. False
In the statement int* p, q; p and q are pointer variables. a. True b. False
b. False
Relational operations can be used on struct variables. a. True b. False
b. False
The public members of a class must be declared before the private members. a. True b. False
b. False
Variables that are created during program execution are called static variables. a. True b. False
b. False
You can use arithmetic operators to perform arithmetic operations on class objects. a. True b. False
b. False
int foo(int n) //Line 1 { //Line 2 if (n == 0) //Line 3 return 0; //Line 4 else //Line 5 return n + foo(n - 1); //Line 6 } //Line 7 Consider the accompanying definition of a recursive function. Which of the statements represents the base case? a. Statements in Lines 1-6. b. Statements in Lines 3 and 4. c. Statements in Lines 5 and 6. d. Statements in Lines 3, 4, and 5.
b. Statements in Lines 3 and 4.
A class object can be ____. That is, it is created each time the control reaches its declaration, and destroyed when the control exits the surrounding block. a. static b. automatic c. local d. public
b. automatic
The ____ case is the case for which the solution to an equation is obtained directly. a. general b. base c. direct d. tail
b. base
Typically, in a program, a struct is defined ____ in the program. a. in the main function b. before the definitions of all the functions c. after the definitions of all the functions d. in any function
b. before the definitions of all the functions
Consider the following statements: struct rectangleData { double length; double width; double area; double perimeter; }; rectangleData bigRect; Which of the following statements correctly initializes the component length of bigRect? a. bigRect = {10}; b. bigRect.length = 10; c. length[0]= 10; d. bigRect[0]= 10
b. bigRect.length = 10;
Consider the accompanying class definition, and the object declaration: rectangleType bigRect(14,10); Which of the following statements is correct? a. bigRect.setLengthWidth(); b. bigRect.setLengthWidth(3.0, 2.0); c. bigRect.length = 2.0; d. bigRect.length = bigRect.width;
b. bigRect.setLengthWidth(3.0, 2.0);
Consider the following statements: struct rectangleData { double length; double width; double area; double perimeter; }; rectangleData bigRect; Which of the following statements is valid in C++? a. cin >> bigRect; b. cin >> bigRect.length; c. perimeter = 2 * (length + width); d. area = length * width;
b. cin >> bigRect.length;
Consider the UML class diagram shown in the accompanying figure. Which of the following is the name of the class? a. clock b. clockType c. Type d. +clockType
b. clockType
clockType -hr: int -min: int -sec: int +setTime(int, int, int): void +getTime(int&, int&, int&) const: void +printTime() const: void +incrementSeconds(): int +incrementMinutes(): int +incrementHours(): int +equalTime(const clockType&) const: bool 15. The word ____ at the end of several the member functions in the accompanying figure class clockType specifies that these functions cannot modify the member variables of a clockType object. a. static b. const c. automatic d. private
b. const
The ____ constructor is executed when an object is declared and initialized by using the value of another object. a. default b. copy c. struct d. class
b. copy
Consider the following statements: struct rectangleData { double length; double width; double area; double perimeter; }; rectangleData bigRect; Which of the following statements is valid in C++? a. cin >> bigRect.length >> width; b. cout << bigRect.length; c. cout << bigRect; d. cout << length;
b. cout << bigRect.length;
In a ____ copy, two or more pointers have their own data. a. shallow b. deep c. static d. dynamic
b. deep
The C++ operator ____ is used to destroy dynamic variables. a. destroy b. delete c. * d. ~
b. delete
A class ____ automatically executes whenever a class object goes out of scope. a. constructor b. destructor c. pointer d. exception
b. destructor
Suppose that list is an array of 10 components of type int. Which of the following codes correctly outputs all the elements of list? a. for (int j = 1; j < 10; j++) cout << list[j] << " "; cout << endl; b. for (int j = 0; j <= 9; j++) cout << list[j] << " "; cout << endl; c. for (int j = 1; j < 11; j++) cout << list[j] << " "; cout << endl; d. for (int j = 1; j <= 10; j++) cout << list[j] << " "; cout << endl;
b. for (int j = 0; j <= 9; j++) cout << list[j] << " "; cout << endl;
Tracing through ____ recursion is more tedious than tracing other recursive forms. a. direct b. indirect c. tail d. iterative
b. indirect
The components of a class are called the ____ of the class. a. elements b. members c. objects d. properties
b. members
The C++ operator ____ is used to create dynamic variables. a. dynamic b. new c. virtual d. dereferencing
b. new
Which of the following can be used to initialize a pointer variable? a. 1 b. nullptr c. "0" d. '0'
b. nullptr
How many destructors can a class have? a. no explicit destructors b. one c. two d. any number
b. one
Consider the following statements: struct personalInfo { string name; int age; double height; double weight; }; struct commonInfo { string name; int age; }; personalInfo person1, person2; commonInfo person3, person4; Which of the following statements is valid in C++? a. person1 = person3; b. person2 = person1; c. person2 = person3; d. person2 = person4;
b. person2 = person1;
A definition in which something is defined in terms of a smaller version of itself is called a(n) ____ definition. a. step-wise b. recursive c. member-wise d. iterative
b. recursive
In a ____ copy, two or more pointers of the same type point to the same memory. a. static b. shallow c. dynamic d. deep
b. shallow
An array name and index are separated using ____. a. curly brackets b. square brackets c. a dot d. a comma
b. square brackets
Given the following declaration: int j; int sum; double sale[10][7]; which of the following correctly finds the sum of the elements of the fifth row of sale? a. sum = 0; for(j = 0; j < 7; j++) sum = sum + sale[5][j]; b. sum = 0; for(j = 0; j < 7; j++) sum = sum + sale[4][j]; c. sum = 0; for(j = 0; j < 10; j++) sum = sum + sale[5][j]; d. sum = 0; for(j = 0; j < 10; j++) sum = sum + sale[4][j];
b. sum = 0; for(j = 0; j < 7; j++) sum = sum + sale[4][j];
A recursive function in which the last statement executed is the recursive call is called a(n) ____ recursive function. a. direct b. tail c. indefinite d. indirect
b. tail
You can assign the value of one struct variable to another struct variable of ____ type. a. a simple data b. the same c. an array d. any
b. the same
A ____ sign in front of a member name on a UML diagram indicates that this member is a protected member. a. + b. - c. # d. $
c. #
A collection of a fixed number of elements (called components) arranged in n dimensions (n>=1) is called a(n) ____. a. matrix b. vector c. n-dimensional array d. parallel array
c. n-dimensional array
After the following statements execute, what are the contents of matrix? int matrix[3][2]; int j, k; for (j = 0; j < 3; j++) for (k = 0; k < 2; k++) matrix[j][k] = j + k; a. 0 0 1 1 2 2 b. 0 1 2 3 4 5 c. 0 1 1 2 2 3 d. 1 1 2 2 3 3
c. 0 1 1 2 2 3
What is the output of the following C++ code? int list[5] = {0, 5, 10, 15, 20}; int j; for (j = 0; j < 5; j++) cout << list[j] << " "; cout << endl; a. 0 1 2 3 4 b. 0 5 10 15 c. 0 5 10 15 20 d. 5 10 15 20
c. 0 5 10 15 20
int mystery(int list[], int first, int last) { if (first == last) return list[first]; else return list[first] + mystery(list, first + 1, last); } Consider the accompanying definition of the recursive function mystery. Given the declaration: int alpha[5] = {1, 4, 5, 8, 9}; what is the output of the following statement? cout << mystery(alpha, 0, 4) << endl; a. 1 b. 18 c. 27 d. 35
c. 27
Consider the following definition of the recursive function print. void print(int num) { if (num > 0) { cout << num << " "; print(num - 1); } } What is the output of the following statement? print(4); a. 0 1 2 3 4 b. 1 2 3 4 c. 4 3 2 1 d. 4 3 2 1 0
c. 4 3 2 1
Consider the accompanying definition of a recursive function. What is the output of the following statement? cout << puzzle(3, 7) << endl; a. 10 b. 21 c. 42 d. 420
c. 42
What is the value of alpha[2] after the following code executes? int alpha[5]; int j; for (j = 0; j < 5; j++) alpha[j] = 2 * j + 1; a. 1 b. 4 c. 5 d. 6
c. 5
Which of the following operations is allowed on pointer variables? a. exp b. % c. == d. /
c. ==
Consider the following statements: struct supplierType { string name; int supplierID; }; struct applianceType { supplierType supplier; string modelNo; double cost; }; applianceType applianceList[25]; Which of the following best describes applianceList? a. It is a multidimensional array. b. It is a struct. c. It is an array of structs. d. It is a struct of arrays.
c. It is an array of structs.
void printNum(int num) //Line 1 { //Line 2 if (n < 0) //Line 3 cout << "Num is negative" << endl; //Line 4 else if (num == 0) //Line 5 cout << "Num is zero" << endl; //Line 6 else //Line 7 { //Line 8 cout << num << " "; //Line 9 printNum(num - 1); //Line 10 } //Line 11 } //Line 12 Consider the accompanying definition of a recursive function. Which of the statements represent the base case? a. Statements in Lines 3 and 4 b. Statements in Lines 5 and 6 c. Statements in Lines 3-6 d. Statements in Lines 5-10
c. Statements in Lines 3-6
What does ADT stand for? a. abstract definition type b. asynchronous data transfer c. abstract data type d. alternative definition type
c. abstract data type
The ____ operator can be used to return the address of a private data member of a class. a. dereferencing b. destructor c. address of d. member access
c. address of
Assume you have the following declaration int beta[50];. Which of the following is a valid element of beta? a. beta['2'] b. beta['50'] c. beta[0] d. beta[50]
c. beta[0]
Consider the accompanying class definition, and the declaration: rectangleType bigRect; Which of the following statements is correct? a. rectangleType.print(); b. rectangleType::print(); c. bigRect.print(); d. bigRect::print();
c. bigRect.print();
Which of the following correctly declares name to be a character array and stores "William" in it? a. char name[6] = "William"; b. char name[7] = "William"; c. char name[8] = "William"; d. char name[8] = 'William';
c. char name[8] = "William";
To guarantee that the member variables of a class are initialized, you use ____. a. accessors b. mutators c. constructors d. destructor
c. constructors
A function is called ____ if it calls itself. a. directly iterative b. indirectly iterative c. directly recursive d. indirectly recursive
c. directly recursive
Consider the following declaration: char charArray[51]; char discard; Assume that the input is: Hello There! How are you? What is the value of discard after the following statements execute? cin.get(charArray, 51); cin.get(discard); a. discard = ' ' (Space) b. discard = '!' c. discard = '\n' d. discard = '\0'
c. discard = '\n'
Run-time binding is also known as ____ binding. a. static b. shallow c. dynamic d. deep
c. dynamic
Suppose that sales is an array of 50 components of type double. Which of the following correctly initializes the array sales? a. for (int 1 = 1; j <= 49; j++) sales[j] = 0; b. for (int j = 1; j <= 50; j++) sales[j] = 0; c. for (int j = 0; j <= 49; j++) sales[j] = 0.0; d. for (int j = 0; j <= 50; j++) sales[j] = 0.0;
c. for (int j = 0; j <= 49; j++) sales[j] = 0.0;
Suppose that gamma is an array of 50 components of type int and j is an int variable. Which of the following for loops sets the index of gamma out of bounds? a. for (j = 0; j <= 49; j++) cout << gamma[j] << " "; b. for (j = 1; j < 50; j++) cout << gamma[j] << " "; c. for (j = 0; j <= 50; j++) cout << gamma[j] << " "; d. for (j = 0; j <= 48; j++) cout << gamma[j] << " ";
c. for (j = 0; j <= 50; j++) cout << gamma[j] << " ";
If a function of a class is static, it is declared in the class definition using the keyword static in its ____. a. return type b. parameters c. heading d. main function
c. heading
A struct is typically a ____ data structure. a. simple b. dynamic c. heterogeneous d. linked
c. heterogeneous
If every recursive call results in another recursive call, then the recursive function (algorithm) is said to have ____ recursion. a. unlimited b. indefinite c. infinite d. tail
c. infinite
Consider the following function prototype: int seqSearch(const listType& list, int searchItem); The actual parameter cannot be modified by ____. a. seqSearch b. listType c. list d. searchItem
c. list
Consider the following statement: ptrMemberVarType objectThree(objectOne); The values of the member variables of objectOne are being copied into the corresponding member variables of objectThree. This initialization is called the ____. a. member-wise assignment b. default assignment c. member-wise initialization d. default initialization
c. member-wise initialization
Consider the following struct definition: struct rectangleData { double length; double width; double area; double perimeter; }; Which of the following variable declarations is correct? a. rectangle rectangleData; b. struct rectangleData(); c. rectangleData myRectangle; d. rectangleData rectangle = new rectangleData();
c. rectangleData myRectangle;
class rectangleType { public: void setLengthWidth(double x, double y); //Postcondition: length = x; width = y; void print() const; //Output length and width; double area(); //Calculate and return the area of the rectangle; double perimeter(); //Calculate and return the parameter; rectangleType(); //Postcondition: length = 0; width = 0; rectangleType(double x, double y); //Postcondition: length = x; width = y; private: double length; double width; }; 20. Consider the accompanying class definition. Which of the following variable declarations is correct? a. rectangle rectangleType; b. class rectangleType rectangle; c. rectangleType rectangle; d. rectangle rectangleType.area;
c. rectangleType rectangle;
Which of the following would be appropriate syntax for the heading of a copy constructor for a class called rulerType? a. rulerType(int inches, int centimeters) b. rulerType() c. rulerType(const rulerType& myRuler) d. copy rulerType(int inches, int centimeters)
c. rulerType(const rulerType& myRuler)
Consider the following declaration: char str[15];. Which of the following statements stores "Blue Sky" into str? a. str = "Blue Sky"; b. str[15] = "Blue Sky"; c. strcpy(str, "Blue Sky"); d. strcpy("Blue Sky");
c. strcpy(str, "Blue Sky");
Consider the following statements: struct supplierType { string name; int supplierID; }; struct paintType { supplierType supplier; string color; string paintID; }; paintType paint; What is the data type of paint.supplier? a. string b. paintType c. supplierType d. struct
c. supplierType
How many needles are used in the Tower of Hanoi problem? a. one b. two c. three d. four
c. three
class secretType { public: static int count; static int z; secretType(); secretType(int a); void print(); static void incrementY(); private: int x; static int y; }; secretType::secretType() { x = 1; } secretType::secretType(int a) { x = a; } void secretType::print() { cout << "x = " << x << ", y = " << y << "z = " << z << ", count = " << count << endl; } static void secretType::incrementY() { y++; } Consider the accompanying class and member functions definitions. How many constructors are present in the class definition? a. none b. one c. two d. three
c. two
A program or software that uses and manipulates the objects of a class is called a(n) ____________________ of that class.
client
The word ____________________ is used before the array declaration in a function heading to prevent the function from modifying the array.
const
What is the output of the following C++ code? int alpha[5] = {2, 4, 6, 8, 10}; int j; for (j = 4; j >= 0; j--) cout << alpha[j] << " "; cout << endl; a. 2 4 6 8 10 b. 4 3 2 1 0 c. 8 6 4 2 0 d. 10 8 6 4 2
d. 10 8 6 4 2
What is the output of the following statements? int x = 33; int *q; q = &x; cout << *q << endl; a. nullptr b. 0 c. 3 d. 33
d. 33
What is the output of the following code? int *p; int x; x = 76; p = &x; *p = 43; cout << x << ", " << *p << endl; a. 76, 76 b. 76, 43 c. 43, 76 d. 43, 43
d. 43, 43
What is the value of x after the following statements execute? int x = 25; int *p; p = &x; *p = 46; a. nullptr b. 0 c. 25 d. 46
d. 46
int mystery(int list[], int first, int last) { if (first == last) return list[first]; else return list[first] + mystery(list, first + 1, last); } Consider the accompanying definition of the recursive function mystery. Given the declaration: int beta[10] = {2, 5, 8, 9, 13, 15, 18, 20, 23, 25}; What is the output of the following statement? cout << mystery(beta, 4, 7) << endl; a. 27 b. 33 c. 55 d. 66
d. 66
int recFunc(int num) { if (num >= 10) return 10; else return num * recFunc(num + 1); } Consider the accompanying definition of a recursive function. What is the output of the following statement? cout << recFunc(8) << endl; a. 4 b. 8 c. 72 d. 720
d. 720
Which of the following rules should you follow to solve the Tower of Hanoi problem? a. Only two disks can be moved at a time. b. You can remove disks only from the first needle. c. The removed disk must be placed on a smaller disk. d. A smaller disk can be placed on top of a larger disk.
d. A smaller disk can be placed on top of a larger disk.
What is the output of the following C++ code? int list[5] = {0, 5, 10, 15, 20}; int j; for (j = 1; j <= 5; j++) cout << list[j] << " "; cout << endl; a. 0 5 10 15 20 b. 5 10 15 20 0 c. 5 10 15 20 20 d. Code results in index out-of-bounds
d. Code results in index out-of-bounds
Which of the following aggregate operations can be executed on array variables? a. Arithmetic b. Assignment c. Function returning a value d. Parameter passing by reference
d. Parameter passing by reference
int foo(int n) //Line 1 { //Line 2 if (n == 0) //Line 3 return 0; //Line 4 else //Line 5 return n + foo(n - 1); //Line 6 } //Line 7 Consider the accompanying definition of a recursive function. Which of the statements represent the general case? a. Statements in Lines 1-6 b. Statements in Lines 3 and 4 c. Statements in Lines 4, 5, and 6 d. Statements in Lines 5 and 6
d. Statements in Lines 5 and 6
void printNum(int num) //Line 1 { //Line 2 if (n < 0) //Line 3 cout << "Num is negative" << endl; //Line 4 else if (num == 0) //Line 5 cout << "Num is zero" << endl; //Line 6 else //Line 7 { //Line 8 cout << num << " "; //Line 9 printNum(num - 1); //Line 10 } //Line 11 } //Line 12 Consider the accompanying definition of a recursive function. Which of the statements represent the general case? a. Statements in Lines 3-11 b. Statements in Lines 5-6 c. Statements in Lines 5-11 d. Statements in Lines 7-11
d. Statements in Lines 7-11
Consider the following statements. struct circleData { double radius; double area; double circumference; }; circleData circle; Which of the following statements is valid in C++? a. cin >> circle.radius; circle.area = 3.14 * radius * radius; b. cin >> circle.radius; circle.area = 3.14 * circle.radius * radius; c. cin >> circle; d. cin >> circle.radius;
d. cin >> circle.radius;
In C++, you can pass a variable by reference and still prevent the function from changing its value by using the keyword ____ in the formal parameter declaration. a. automatic b. private c. static d. const
d. const
An array created during the execution of a program is called a(n) ____ array. a. list b. static c. execution d. dynamic
d. dynamic
Given the statement double *p;, the statement p++; will increment the value of p by ____ byte(s). a. one b. two c. four d. eight
d. eight
A struct variable can be passed as a parameter ____. a. only by const b. only by reference c. only by value d. either by value or by reference
d. either by value or by reference
Consider the following statements: struct supplierType { string name; int supplierID; }; struct applianceType { supplierType supplier; string modelNo; double cost; }; applianceType applianceList[25]; Which of the following statements correctly initializes the cost of each appliance to 0? a. applianceList.cost = 0; b. applianceList.cost[25] = 0; c. for (int j = 1; j < 25; j++) applianceList.cost[j] = 0; d. for (int j = 0; j < 25; j++) applianceList.cost[j] = 0;
d. for (int j = 0; j < 25; j++) applianceList.cost[j] = 0;
Consider the following statements: struct rectangleData { double length; double width; double area; double perimeter; }; rectangleData bigRect; rectangleData smallRect; Which of the following statements is legal in C++? a. if (bigRect == smallRect) b. if (bigRect != smallRect) c. if (bigRect.length == width) d. if (bigRect.length == smallRect.width)
d. if (bigRect.length == smallRect.width)
Which of the following correctly declares and initializes alpha to be an array of four rows and three columns with the component type int? a. int alpha[4][3] = {{0,1,2} {1,2,3} {2,3,4} {3,4,5}}; b. int alpha[4][3] = {0,1,2; 1,2,3; 2,3,4; 3,4,5}; c. int alpha[4][3] = {0,1,2: 1,2,3: 2,3,4: 3,4,5}; d. int alpha[4][3] = {{0,1,2}, {1,2,3}, {2,3,4}, {3,4,5}};
d. int alpha[4][3] = {{0,1,2}, {1,2,3}, {2,3,4}, {3,4,5}};
Which of the following function headings can be used for a recursive definition of a function to calculate the nth Fibonacci number? a. void rFibNum(int a, int b) b. bool rFibNum(int a, int b) c. bool rFibNum(int a, int b, int n) d. int rFibNum(int a, int b, int n)
d. int rFibNum(int a, int b, int n)
To compare struct variables, you compare them ____. a. by reference b. by value c. index-wise d. member-wise
d. member-wise
The components of a struct are called the ____ of the struct. a. variables b. identifiers c. elements d. members
d. members
Consider the following statements: struct studentType1 { string name; int ID; double gpa; }; studentType1 student1, student2; struct studentType2 { string name; int ID; double gpa; }; studentType2 student3, student4; Which of the following statements is valid in C++? a. student2 = student3; b. student1 = student4; c. student2.ID = ID; d. student1.ID = student3.ID;
d. student1.ID = student3.ID
Given the following declaration: int j; int sum; double sale[10][7]; which of the following correctly finds the sum of the elements of the fourth column of sale? a. sum = 0; for(j = 0; j < 7; j++) sum = sum + sale[j][3]; b. sum = 0; for(j = 0; j < 7; j++) sum = sum + sale[j][4]; c. sum = 0; for(j = 0; j < 10; j++) sum = sum + sale[j][4]; d. sum = 0; for(j = 0; j < 10; j++) sum = sum + sale[j][3];
d. sum = 0; for(j = 0; j < 10; j++) sum = sum + sale[j][3];
A list has two items associated with it: ____. a. the length and the references b. the values and the references c. the indexes and the length d. the values and the length
d. the values and the length
Consider the UML class diagram shown in the accompanying figure. According to the UML class diagram, how many private members are in the class? a. none b. zero c. two d. three
d. three
A destructor has the character ____, followed by the name of the class. a. . b. :: c. # d. ~
d. ~
Memory is allocated for struct variables only when you ____________________ them.
declare
A struct is a(n) ____________________, not a declaration.
definition
The binding of virtual functions occurs at program ____________________ time.
execution
A(n) ____________________ contains the definitions of the functions to implement the operations of an object.
implementation file
Non-static member variables of a class are called the ____________________ variables of the class.
instance
The statement int *p; is equivalent to int * p;, which is also equivalent to the statement ____________________.
int* p;
The header file is also known as the ____________________.
interface file
Consider the following struct definition: const int ARRAY_SIZE = 1000; struct listType { int listElem[ARRAY_SIZE]; int listLength; }; The statement that declares intList to be a struct variable of type listType is ____________________.
listType intList
A(n) ____________________ function of a class changes the values of the member variable(s) of the class.
mutator
A(n) ____________________ is a statement specifying the condition(s) that must be true before the function is called.
precondition
By default, all members of a class are ____________________.
private
The form of the for loop shown below is called a(n) ____________________ for loop. for (dataType identifier : arrayName) statements
range-based
Arrays are passed by ____________________ only.
reference
Consider the following statements: void pointerParameters(int* &p, double *q) { . . . } In the function pointerParameters, the parameter p is a(n) ____________________ parameter.
reference
If a variable is passed by ____________________, then when the formal parameter changes, the actual parameter also changes.
reference
For a list of length n, the ____________________ sort makes exactly (n(n - 1))/2 key comparisons and 3(n-1) item assignments.
selection
Consider the following declaration of a struct: struct studentType { char name[26]; double gpa; int sID; char grade; }; studentType student; studentType *studentPtr; The statement (*studentPtr).gpa = 2.5; is equivalent to ___________________ = 2.5;.
studentPtr->gpa