O(n log n)

1. Add variable x to variable sum and assign the result to variable sum

o sum+=x;

2. An expression containing the || operator is true if either or both of its operands are true

o true

3. A function is invoked with a(n) ________.

o function call

4. A variable that is known only within the function in which it is defined is called a(n) ________.

o local variable

5. A(n)________ allows the compiler to check the number, types and order of the arguments passed to a function.

o function prototype

6. A variable declared outside any block or function is a(n) ________ variable

o global

7. A function that calls itself either directly or indirectly (i.e., through another function) is a(n) ________ function

o recursive

8. A recursive function typically has two components: One that provides a means for the recursion to terminate by testing for a(n) ________ case and one that expresses the problem as a recursive call for a slightly simpler problem than the original call

Base

9. All programs can be written in terms of three types of control structures:_________, __________and_________.

o Sequence, selection and repetition

10. Any source-code file that contains int main() can be used to execute a program

o true

11. A class definition is typically stored in a file with the _________ filename extension

o.h

12. A house is to a blueprint as a(n) _________ is to a class

o object

13. A C++ program that prints three lines of output must contain three statements using cout and the stream insertion operator

o false

14. All variables must be given a type when they are declared

o true

15. All variables must be declared before they are used

o true

16. A function ________ enables a single function to be defined to perform a task on many different data types

o template

17. All arguments to function calls in C++ are passed by value

o false

18. A(n) __________ should be used to declare the size of an array, because it makes the program more scalable

o constant variable

19. An array that uses two subscripts is referred to as a(n) _________ array

o two-dimensional

20. An array can store many different types of values

o false

21. An array subscript should normally be of data type float

False

22. An individual array element that is passed to a function and modified in that function will contain the modified value when the called function completes execution

o false

23. A pointer is a variable that contains as its value the____________ of another variable

o address

24. A pointer that is declared to be of type void * can be dereferenced

o false

25. Assuming that nPtr points to the beginning of array numbers (the starting address of the array is at location 1002500 in memory), what address is referenced by nPtr + 8?

o The address is 1002500 + 8 * 8 = 1002564

26. A nonmember function must be declared as a(n) __________ of a class to have access to that class's private data members.

o friend

27. A constant object must be __________; it cannot be modified after it is created

o initialized

28. A(n) __________ data member represents class-wide information

o static

29. An object's non-static member functions have access to a "self pointer" to the object called the __________ pointer

o this

30. A member function should be declared static if it does not access __________ class members

non-static

31. A program must call function close explicitly to close a file associated with an ifstream, ofstream or fstream object.

o false

32. A selection sort application would take approximately ________ times as long to run on a 128-element vector as on a 32-element vector.

o 16, because an O(n2) algorithm takes 16 times as long to sort four times as much information

33. By convention, function names begin with a capital letter and all subsequent words in the name begin with a capital letter

o false

34. By default, memory addresses are displayed as long integers

o false

35. Class members specified as _________ are accessible only to member functions of the class and friends of the class

o private

36. Class members specified as _________ are accessible anywhere an object of the class is in scope

o public

37. __________ can be used to assign an object of a class to another object of the same class

o Default memberwise assignment (performed by the assignment operator).

38. Class members are accessed via the ________ operator in conjunction with the name of an object (or reference to an object) of the class or via the ___________ operator in conjunction with a pointer to an object of the class

o dot (.), arrow (->)

39. Comments cause the computer to print the text after the // on the screen when the program is executed

o false

40. C++ considers the variables number and NuMbEr to be identical

o false

41. Calculate the remainder after q is divided by divisor and assign the result to q. Write this statement two different ways

o q %= divisor;
q = q % divisor;

42. Repeating a set of instructions a specific number of times is called_________repetition

o Counter-controlled or definite

43. Return type _________ indicates that a function will perform a task but will not return any information when it completes its task

o void

44. Read an integer from the user at the keyboard and store the value entered in integer variable age.

o std::cin >> age;

45. Refer to the fourth element of array numbers using array subscript notation, pointer/offset notation with the array name as the pointer, pointer subscript notation with nPtr and pointer/offset notation with nPtr

o numbers[ 3 ]
*(numbers + 3)
nPtr[ 3 ]
*(nPtr + 3)

46. Read an integer from the user at the keyboard and store the value entered in integer variable age.

o std::cin >> age;

47. Refer to the fourth element of array numbers using array subscript notation, pointer/offset notation with the array name as the pointer, pointer subscript notation with nPtr and pointer/offset notation with nPtr

o numbers[ 3 ]
*(numbers + 3)
nPtr[ 3 ]
*(nPtr + 3)

48. Records in random-access files must be of uniform length

o false

49. Declare variables sum and x to be of type int

o int sum, x;

50. Determine whether the value of the variable count is greater than 10. If it is, print "Count is greater than 10."

o if (count > 10) cout << "Count is greater than 10" << endl;

51. Data members or member functions declared with access specifier private are accessible to member functions of the class in which they are declared

o true

52. Declare the variables c, thisIsAVariable, q76354 and number to be of type int.

o int c, thisIsAVariable, q76354, number;

53. Declarations can appear almost anywhere in the body of a C++ function

o true

54. Declare the array to be an integer array and to have 3 rows and 3 columns. Assume that the constant variable arraySize has been defined to be 3:

o int table[ arraySize ][ arraySize];

55. Declare an array of type double called numbers with 10 elements, and initialize the elements to the values 0.0, 1.1, 2.2,..., 9.9. Assume that the symbolic constant SIZE has been defined as 10

o double numbers[ SIZE ] = { 0.0, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9 };

56. Declare a pointer nPtr that points to a variable of type double

o double *nPtr;

57. Data in sequential files always is updated without overwriting nearby data

o false

58. Set variable x to 1

o x=1;

59. Set variable sum to 0

o sum=0;

60. State the values of the variable after the calculation is performed. Assume that, when a statement begins executing, all variables have the integer value 5:
product *= x++;

o product = 25, x = 6;

61. State the values of the variable after the calculation is performed. Assume that, when a statement begins executing, all variables have the integer value 5:
quotient /= ++x;

o quotient = 0, x = 6;

62. Storage-class specifier ________ is a recommendation to the compiler to store a variable in one of the computer's registers

o register

63. Stream manipulator showpoint forces floating-point values to print with the default six digits of precision unless the precision value has been changed, in which case floating-point values print with the specified precision

o true

64. Searching all records in a random-access file to find a specific record is unnecessary

o true

65. Print "The sum is: " followed by the value of variable sum

o cout << "The sum is: " << sum << end1;

66. Predecrement the variable x by 1, then subtract it from the variable total

o total -= --x;

67. Print the message "This is a C++ program" with each word separated from the next by a tab

std::cout << "This\tis\ta\tC++\tprogram\n";

Program components in C++ are called ________ and ________.

o functions, classes

68. Print the message "This is a C++ program" with each word on a separate line

o std::cout << "This\nis\na\nC++\nprogram\n";

69. Print the message "This is a C++ program" on one line

o std::cout << "This is a C++ program\n";

70. Prompt the user to enter an integer. End your prompting message with a colon (:) followed by a space and leave the cursor positioned after the space

71. Pointers of different types can never be assigned to one another without a cast operation

o false

72. Write single C++ statements that input integer variable x with cin and >>

o cin>>x;

73. Write single C++ statements that input integer variable y with cin and >>.

o cin >> y;

74. Write single C++ statements that postincrement variable i by 1

o i++;

75. Write single C++ statements that determine whether i is less than or equal to y

o if (i<=y)

76. Write single C++ statements that output integer variable power with cout and <<

o cout << power << endl;

77. What is wrong with the following while repetition statement?
while (z >= 0)
sum += z;

o The value of the variable z is never changed in the while statement. Therefore, if the loop continuation condition (z >= 0) is initially true, an infinite loop is created. To prevent the infinite loop, z must be decremented so that it eventually becomes less than 0.

78. Write a C++ statement or a set of C++ statements to sum the odd integers between 1 and 99 using a for statement. Assume the integer variables sum and count have been declared

o sum = 0;
for (count = 1; count <= 99; count += 2) sum += count;

79. Write a C++ statement or a set of C++ statements to print the value 333.546372 in a field width of 15 characters with precisions of 1, 2 and 3. Print each number on the same line. Left-justify each number in its field.

o cout << fixed << left
<< setprecision(1) << setw(15) << 333.546372
<< setprecision(2) << setw(15) << 333.546372
<< setprecision(3) << setw(15) << 333.546372
<< endl;

80. Write a C++ statement or a set of C++ statements to calculate the value of 2.5 raised to the power 3 using function pow. Print the result with a precision of 2 in a field width of 10 positions

o cout << fixed << setprecision(2) << setw(10) << pow(2.5, 3) << endl;

81. Write a C++ statement or a set of C++ statements to print the integers from 1 to 20 using a while loop and the counter variable x. Assume that the variable x has been declared, but not initialized. Print only 5 integers per line. [Hint: Use the calculation x % 5. When the value of this is 0, print a newline character; otherwise, print a tab character.]

o x = 1;
while (x <= 20)
{
cout << x;
if (x % 5 == 0)
cout << endl;
else
cout << '\t';
x++;
}

82. What variable is?

o named part in a memory

83. Write four different C++ statements that each add 1 to integer variable x

o x =+ 1; x += 1; ++x; x++;

84. When it is not known in advance how many times a set of statements will be repeated, a(n)_________value can be used to terminate the repetition

o Sentinel, signal, flag or dummy

85. What is the difference between a local variable and a data member?

o A local variable is declared in the body of a function and can be used only from the point at which it is declared to the immediately following closing brace. A data member is declared in a class definition, but not in the body of any of the class's member functions. Every object (instance) of a class has a separate copy of the class's data members. Also, data members are accessible to all member functions of the class.

86. When a member function is defined outside the class definition, the function header must include the class name and the _________, followed by the function name to "tie" the member function to the class definition

o binary scope resolution operator (::)

87. When each object of a class maintains its own copy of an attribute, the variable that represents the attribute is also known as a(n) _________.

o data member

88. What statement is used to make decisions:

o if

89. Write a declaration for the following: Integer count that should be maintained in a register. Initialize count to 0.

o register int count = 0;

90. Write a declaration for the following: Double-precision, floating-point variable lastVal that is to retain its value between calls to the function in which it is defined.

o static double lastVal;

91. Why would a function prototype contain a parameter type declaration such as double &?

o This creates a reference parameter of type "reference to double" that enables the function to modify the original variable in the calling function

92. Write one or more statements that perform the following task for and array called “fractions”. Define a constant variable arraySize initialized to 10.

o const int arraySize = 10;

93. Write one or more statements that perform the following task for and array called “fractions”. Declare an array with arraySize elements of type double, and initialize the elements to 0.

o double fractions[ arraySize ] = { 0.0};

94. Write one or more statements that perform the following task for and array called “fractions”. Name the fourth element of the array

o fractions[ 3 ]

95. Write one or more statements that perform the following task for and array called “fractions”. Refer to array element 4

o fractions[ 4 ]

96. Write one or more statements that perform the following task for and array called “fractions”. Assign the value 1.667 to array element 9

o fractions[ 9 ] = 1.667;

97. Write one or more statements that perform the following task for and array called “fractions”. Assign the value 3.333 to the seventh element of the array

o fractions[ 6 ] = 3.333;

98. Write one or more statements that perform the following task for and array called “fractions”. Print array elements 6 and 9 with two digits of precision to the right of the decimal point.

o cout << fixed << setprecision (2); cout << fractions[ 6 ] < < ' ' fractions[ 9 ] << endl;

99. Write one or more statements that perform the following task for and array called “fractions”. Print all the array elements using a for statement. Define the integer variable i as a control variable for the loop.

o for (int i = 0; < arraySize; i++) cout << "fractions[" < i << "] = " << fractions[ i ] << endl;

100. Write a program segment to print the values of each element of array table in tabular format with 3 rows and 3 columns. Assume that the array was initialized with the declaration
int table[ arraySize ][ arraySize ] = { { 1, 8 }, { 2, 4, 6 }, { 5 } };
and the integer variables i and j are declared as control variables.

o cout << " [0] [1] [2]" << endl;
for (int i = 0; i < arraySize; i++) {
cout << '[' << i << "] ";
for (int j = 0; j < arraySize; j++)
cout << setw(3) << table[ i ][ j ] << " ";
cout << endl;

101. Write two separate statements that each assign the starting address of array numbers to the pointer variable nPtr.

o nPtr = numbers;
nPtr = &numbers[ 0 ];

102. Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Declare the variable fPtr to be a pointer to an object of type double.

o double *fPtr;

103. Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Print the value of the object pointed to by fPtr.

o cout << "The value of *fPtr is " << *fPtr << endl;

104. Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Assign the value of the object pointed to by fPtr to variable number2.

o number2 = *fPtr;

105. Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Print the value of number2.

o cout << "The value of number2 is " << number2 << endl;

106. Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Print the address of number1.

o cout << "The address of number1 is " << &number1 << endl;

107. Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Print the address stored in fPtr.

o cout << "The address stored in fPtr is " << fPtr << endl;

108. Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Copy the string stored in array s2 into array s1.

o strcpy(s1, s2);

109. Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Compare the string in s1 with the string in s2, and print the result.

o cout << "strcmp(s1, s2) = " << strcmp(s1, s2) << endl;

110. Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Append the first 10 characters from the string in s2 to the string in s1.

o strncat(s1, s2, 10);

111. Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Determine the length of the string in s1, and print the result.

o cout << "strlen(s1) = " << strlen(s1) << endl;

112. Write a single statement that performs the specified task. Assume that floating-point variables number1 and number2 have been declared and that number1 has been initialized to 7.3. Assume that variable ptr is of type char *. Assume that arrays s1 and s2 are each 100-element char arrays that are initialized with string literals. Assign to ptr the location of the first token in s2. The tokens delimiters are commas (,).

o ptr = strtok(s2, ",");

113. Write the function header for a function called exchange that takes two pointers to double-precision, floating-point numbers x and y as parameters and does not return a value

o void exchange(double *x, double *y)

114. Write the function header for a function called evaluate that returns an integer and that takes as parameters integer x and a pointer to function poly. Function poly takes an integer parameter and returns an integer.

o int evaluate(int x, int (*poly)(int))

115. Write two statements that each initialize character array vowel with the string of vowels, "AEIOU".

o char vowel[] = "AEIOU";
char vowel[] = { 'A', 'E', 'I', 'O', 'U', '\0' };

116. What (if anything) prints when the following statement is performed?Assume the following variable declarations:
char s1[ 50 ] = "jack";
char s2[ 50 ] = "jill";
char s3[ 50 ];
cout << strcpy(s3, s2) << endl;

o jill

117. What (if anything) prints when the following statement is performed?Assume the following variable declarations:
char s1[ 50 ] = "jack";
char s2[ 50 ] = "jill";
char s3[ 50 ];
cout << strcat(strcat(strcpy(s3, s1), " and "), s2) << endl;

o jack and jill

118. What (if anything) prints when the following statement is performed?Assume the following variable declarations:
char s1[ 50 ] = "jack";
char s2[ 50 ] = "jill";
char s3[ 50 ];
cout << strlen(s1) + strlen(s2) << endl;

o 8

119. What (if anything) prints when the following statement is performed?Assume the following variable declarations:
char s1[ 50 ] = "jack";
char s2[ 50 ] = "jill";
char s3[ 50 ];
cout << strlen(s3) << endl;

o 13

120. When used, the _________ stream manipulator causes positive numbers to display with a plus sign.

o showpos

121. Identify and correct the errors in the following code:
while (c <= 5)
{
product *= c;
c++;

o while (c <= 5)
{
product *= c;
c++;
}

122. Identify and correct the errors in the following code:
if (gender == 1)
cout << "Woman" << endl;
else;
cout << "Man" << endl;

o if (gender == 1)
cout << "Woman" << endl;
else
cout << "Man" << endl;

123. Identify and correct the errors in the following code:
cin << value;

o cin >> value;

124. In C++, it is possible to have various functions with the same name that operate on different types or numbers of arguments. This is called function ________.

o overloading

125. In one statement, assign the sum of the current value of x and y to z and postincrement the value of x

o z = x++ + y;

126. Identify and correct the errors in the following statement (assume that the statement using std::cout; is used):
if (c => 7) cout << "c is equal to or greater than 7\n";

o if (c >= 7) cout << "c is equal to or greater than 7\n";

127. Identify and correct the errors in the following statement (assume that the statement using std::cout; is used):
if (c < 7);
cout << "c is less than 7\n";

o if (c < 7) cout << "c is less than 7\n";

128. If the variable number is not equal to 7, print "The variable number is not equal to 7"

o if (number!= 7) std::cout << "The variable number is not equal to 7\n";

129. If there are fewer initializers in an initializer list than the number of elements in the array, the remaining elements are initialized to the last value in the initializer list

o false

130. It is an error if an initializer list contains more initializers than there are elements in the array

o true

131. If a member initializer is not provided for a member object of a class, the object's __________ is called

o default constructor

132. Input/output in C++ occurs as ____________ of bytes

o streams

133. Input operations are supported by class __________.

o istream

134. Input with the stream extraction operator >> always skips leading white-space characters in the input stream, by default

o true

135. If a nonrecoverable error occurs during a stream operation, the bad member function will return TRue

o true

136. If the file-position pointer points to a location in a sequential file other than the beginning of the file, the file must be closed and reopened to read from the beginning of the file

false

137. The default case is required in the switch selection statement

o false

138. The break statement is required in the default case of a switch selection statement to exit the switch properly

o false

139. The expression (x > y && a < b) is true if either the expression x > y is true or the expression a < b is true

o false

140. The ________ statement in a called function passes the value of an expression back to the calling function

o return

141. The keyword ________ is used in a function header to indicate that a function does not return a value or to indicate that a function contains no parameters

o void

142. The ________ of an identifier is the portion of the program in which the identifier can be used

o scope

143. The three ways to return control from a called function to a caller are ________, ________ and ________.

o return, return expression or encounter the closing right brace of a function.

144. The storage-class specifiers are mutable, ________, ________, ________ and ________.

o auto, register, extern, static

145. The six possible scopes of an identifier are ________, ________, ________, ________, ________ and ________.

o function scope, file scope, block scope, function-prototype scope, class scope, namespace scope

146. The ________ enables access to a global variable with the same name as a variable in the current scope

o unary scope resolution operator (::)

147. The_________selection statement is used to execute one action when a condition is true or a different action when that condition is false.

o if…else

148. The types of arguments in a function call must match the types of the corresponding parameters in the function prototype's parameter list

o true

149. The source-code file and any other files that use a class can include the class's header file via an _________ preprocessor directive

o #include

150. The arithmetic operators *, /, %, + and all have the same level of precedence

o false

151. The modulus operator (%) can be used only with integer operands

o true

152. The escape sequence \n, when output with cout and the stream insertion operator, causes the cursor to position to the beginning of the next line on the screen

o true

153. The ________ qualifier is used to declare read-only variables

o const

154. The elements of an array are related by the fact that they have the same ________ and ___________.

o name, type

155. The number used to refer to a particular element of an array is called its ________.

o subscript (or index)

156. The process of placing the elements of an array in order is called ________ the array

o sorting

157. The process of determining if an array contains a particular key value is called _________ the array

o searching

158. the error in the following program segment and correct the error:
Assume that int a[ 2 ][ 2 ] = { { 1, 2 }, { 3, 4 } };
a[ 1, 1 ] = 5;

o a[ 1, 1 ] = 5;

159. The three values that can be used to initialize a pointer are_____________,__________ and___________.

o 0, NULL, an address

160. The only integer that can be assigned directly to a pointer is_____________.

o 0

161. The address operator & can be applied only to constants and to expressions

o false

162. The __________ operator dynamically allocates memory for an object of a specified type and returns a __________ to that type.

o new, pointer

163. The keyword __________ specifies that an object or variable is not modifiable after it is initialized

o const

164. The __________ operator reclaims memory previously allocated by new.

o delete

165. The stream manipulators that format justification are_________, _________ and _______.

o left, right and internal

166. The ostream member function ___________ is used to perform unformatted output

o write

167. The symbol for the stream insertion operator is ____________.

o <<

168. The four objects that correspond to the standard devices on the system include _________, _________, __________ and ___________.

o cin, cout, cerr and clog

169. The symbol for the stream extraction operator is __________

o >>

170. The stream manipulators ___________, __________ and ___________ specify that integers should be displayed in octal, hexadecimal and decimal formats, respectively

o oct, hex and dec

171. The stream member function flags with a long argument sets the flags state variable to its argument and returns its previous value.

o false

172. The stream extraction operator >> can be overloaded with an operator function that takes an istream reference and a reference to a user-defined type as arguments and returns an istream reference.

o true

173. The stream insertion operator << can be overloaded with an operator function that takes an istream reference and a reference to a user-defined type as arguments and returns an istream reference

o false

174. The stream member function rdstate returns the current state of the stream

o true

175. The cout stream normally is connected to the display screen

o true

176. The stream member function good returns TRUE if the bad, fail and eof member functions all return false

o true

177. The cin stream normally is connected to the display screen

o false

178. The ostream member function put outputs the specified number of characters

o false

179. The stream manipulators dec, oct and hex affect only the next integer output operation

o false

180. The programmer must create the cin, cout, cerr and clog objects explicitly

o false

181. The ostream member function write can write to standard-output stream cout

o true

182. The efficiency of merge sort is ______

o O(n log n).

183. Variables declared in a block or in the parameter list of a function are assumed to be of storage class ________ unless specified otherwise

o auto

184. Variables declared in the body of a particular member function are known as data members and can be used in all member functions of the class

o false

185. Find the error(s) in the following code segment:
x = 1;
while (x <= 10);
x++;
}

o x = 1;
while (x <= 10)
x++;
}

186. Find the error(s) in the following code segment:
for (y =.1; y!= 1.0; y +=.1) cout << y << endl;

o for (y = 1; y!= 10; y++) cout << (static_cast< double >(y) / 10) << endl;

187. Find the error(s) in the following code segment:
switch (n)
{
case 1:
cout << "The number is 1" << endl;
case 2:
cout << "The number is 2" << endl;
break;
default:
cout << "The number is not 1 or 2" << endl;
break;
}

o switch (n)
{
case 1:
cout << "The number is 1" << endl;
break;
case 2:
cout << "The number is 2" << endl;
break;
default:
cout << "The number is not 1 or 2" << endl;
break;
}

188. Find the error(s) in the following code segment. The following code should print the values 1 to 10:
n = 1;
while (n < 10) cout << n++ << endl;

o n = 1;
while (n < 11) cout << n++ << endl;

189. Function ________ is used to produce random numbers

o rand()

190. Function ________ is used to set the random number seed to randomize a program

o srand()

191. For a local variable in a function to retain its value between calls to the function, it must be declared with the ________ storage-class specifier

o static

192. Find the error in the following program segment:
int g(void)
{
cout << "Inside function g" << endl;
int h(void)
{
cout << "Inside function h" << endl;
}
}

o int g(void)
{
cout << "Inside function g" << endl;
}
int h(void)
{
cout << "Inside function h" << endl;
}

193. Find the error in the following program segment:
int sum(int x, int y)
{
int result;
result = x + y;
}

o int sum(int x, int y)
{
return x + y;
}

194. Find the error in the following program segment:
int sum(int n)
{
if (n == 0)
return 0;
else
n + sum(n - 1);
}

o int sum(int n)
{
if (n == 0)
return 0;
else
return n + sum(n - 1);
}

195. Find the error in the following program segment
void f (double a);
{
float a;
cout << a << endl;
}

o void f (double a)
{
cout << a << endl;
}

196. Find the error in the following program segment:
void product(void)
{
int a;
int b;
int c;
int result;
cout << "Enter three integers: ";
cin >> a >> b >> c;
result = a * b * c;
cout << "Result is " << result;
return result;
}

o void product(void)
{
int a;
int b;
int c;
int result;
cout << "Enter three integers: ";
cin >> a >> b >> c;
result = a * b * c;
cout << "Result is " << result;
}

197. Find the error in the following program segment and correct the error:
#include;

o #include

198. Find the error in the following program segment and correct the error:
arraySize = 10; // arraySize was declared const

o const int arraySize=10;

199. Find the error in the following program segment and correct the error:
Assume that int b[ 10 ] = { 0 };
for (int i = 0; <= 10; i++)
b[ i ] = 1;

o for (int i = 0; <= 9; i++)
b[ i ] = 1;

200. Find the error in the following program segment. Assume the following declarations and statements:
int *zPtr; // zPtr will reference array z
int *aPtr = 0;
void *sPtr = 0;
int number;
int z[ 5 ] = { 1, 2, 3, 4, 5 };
++zPtr;
zPtr = z;

o ++zPtr;

201. Find the error in the following program segment. Assume the following declarations and statements:
int *zPtr; // zPtr will reference array z
int *aPtr = 0;
void *sPtr = 0;
int number;
int z[ 5 ] = { 1, 2, 3, 4, 5 };
// use pointer to get first value of array
number = zPtr;

o number = *zPtr;

202. Find the error in the following program segment. Assume the following declarations and statements:
int *zPtr; // zPtr will reference array z
int *aPtr = 0;
void *sPtr = 0;
int number;
int z[ 5 ] = { 1, 2, 3, 4, 5 };
// assign array element 2 (the value 3) to number
number = *zPtr[ 2 ];

o number = zPtr[ 2 ];

203. Find the error in the following program segment. Assume the following declarations and statements:
int *zPtr; // zPtr will reference array z
int *aPtr = 0;
void *sPtr = 0;
int number;
int z[ 5 ] = { 1, 2, 3, 4, 5 };
// print entire array z
for (int i = 0; i <= 5; i++) cout << zPtr[ i ] << endl;

o for (int i = 0; i < 5; i++) cout << zPtr[ i ] << endl;

204. Find the error in the following program segment. Assume the following declarations and statements:
int *zPtr; // zPtr will reference array z
int *aPtr = 0;
void *sPtr = 0;
int number;
int z[ 5 ] = { 1, 2, 3, 4, 5 };
// assign the value pointed to by sPtr to number
number = *sPtr;

o number = *static_cast< int * >(sPtr);

205. Find the error in the following program segment. Assume the following declarations and statements:
int *zPtr; // zPtr will reference array z
int *aPtr = 0;
void *sPtr = 0;
int number;
int z[ 5 ] = { 1, 2, 3, 4, 5 };
++z;

o ++z[4];

206. Find the error in the following program segment. Assume the following declarations and statements:
int *zPtr; // zPtr will reference array z
int *aPtr = 0;
void *sPtr = 0;
int number;
int z[ 5 ] = { 1, 2, 3, 4, 5 };
char s[ 10 ];
cout << strncpy(s, "hello", 5) << endl;

o cout << strncpy(s, "hello", 6) << endl;

207. Find the error in the following program segment. Assume the following declarations and statements:
int *zPtr; // zPtr will reference array z
int *aPtr = 0;
void *sPtr = 0;
int number;
int z[ 5 ] = { 1, 2, 3, 4, 5 };
char s[ 12 ];
strcpy(s, "Welcome Home");

o char s[ 13 ];
strcpy(s, "Welcome Home");

208. Find the error in the following program segment. Assume the following declarations and statements:
int *zPtr; // zPtr will reference array z
int *aPtr = 0;
void *sPtr = 0;
int number;
int z[ 5 ] = { 1, 2, 3, 4, 5 };
if (strcmp(string1, string2))
cout << "The strings are equal" << endl;

o if (strcmp(string1, string2) == 0)
cout << "The strings are equal" << endl;

209. Find the error(s) in the following and correct it (them).
Assume the following prototype is declared in class Time:
void ~Time(int);

o ~Time();

210. Find the error(s) in the following and correct it (them).
The following is a partial definition of class Time:
class Time
{
public:
// function prototypes
private:
int hour = 0;
int minute = 0;
int second = 0;
}; // end class Time

o class Time
{
public:
// function prototypes
Time (int my_hour, int my_minute, int my_second)
{
hour=my_hour;
minute=my_minute;
second=my_second;
}
private:
int hour;
int minute;
int second;
}; // end class Time

211. Find the error(s) in the following and correct it (them).
Assume the following prototype is declared in class Employee:
int Employee(const char *, const char *);

o Employee(const char *, const char *);

212. Find the errors in the following class and explain how to correct them:
class Example
{
public:
Example(int y = 10)
: data(y)
{
// empty body
} // end Example constructor
int getIncrementedData() const
{
return data++;
} // end function getIncrementedData
static int getCount()
{
cout << "Data is " << data << endl;
return count;
} // end function getCount
private:
int data;
static int count;
}; // end class Example

Error: The class definition for Example has two errors. The first occurs in function getIncrementedData. The function is declared const, but it modifies the object.
Correction: To correct the first error, remove the const keyword from the definition of getIncrementedData.
Error: The second error occurs in function getCount. This function is declared static, so it is not allowed to access any non-static member of the class.
Correction: To correct the second error, remove the output line from the getCount definition.

213. Explain the purpose of a function parameter. What is the difference between a parameter and an argument?

o A parameter represents additional information that a function requires to perform its task. Each parameter required by a function is specified in the function header. An argument is the value supplied in the function call. When the function is called, the argument value is passed into the function parameter so that the function can perform its task

214. Every function's body is delimited by left and right braces ({ and }).

o true

215. Empty parentheses following a function name in a function prototype indicate that the function does not require any parameters to perform its task

o true

216. Each parameter in a function header should specify both a(n) _________ and a(n) _________.

o type, name

217. Every class definition contains keyword _________ followed immediately by the class's name

o class

218. Every C++ statement ends with a(n):

o semicolon

219. Every C++ program begins execution at the function

o main

220. Keyword public is a(n) _________.

o access specifier

221. Give the function header for the following function. Function hypotenuse that takes two double-precision, floating-point arguments, side1 and side2, and returns a double-precision, floating-point result.

o double hypotenuse(double side1, double side2)

222. Give the function header for the following function. Function smallest that takes three integers, x, y and z, and returns an integer.

o int smallest(int x, int y, int z)

223. Give the function header for the following function. Function instructions that does not receive any arguments and does not return a value. [Note: Such functions are commonly used to display instructions to a user.]

o void instructions(void)

224. Give the function header for the following function. Function intToDouble that takes an integer argument, number, and returns a double-precision, floating-point result.

o double intToDouble(int number)

225. Lists and tables of values can be stored in __________ or __________.

o arrays, vectors

226. Use a for statement to print the elements of array numbers using array subscript notation. Print each number with one position of precision to the right of the decimal point:

o cout << fixed << showpoint << setprecision(1);
for (int i = 0; i < SIZE; i++)
cout << numbers[ i ] <<' ';

227. Use a for statement to print the elements of array numbers using pointer/offset notation with pointer nPtr

o cout << fixed << showpoint << setprecision(1);
for (int j = 0; j < SIZE; j++)
cout << *(nPtr + j) << ' ';

228. Use a for statement to print the elements of array numbers using pointer/offset notation with the array name as the pointer

cout << fixed << showpoint << setprecision(1);
for (int k = 0; k < SIZE; k++)
cout << *(numbers + k) << ' '

229. Use a for statement to print the elements of array numbers using pointer/subscript notation with pointer nPtr

o cout << fixed << showpoint << setprecision(1);
for (int m = 0; m < SIZE; m++)
cout << nPtr[ m ] << ' ';

230. Use a stream manipulator that causes the exponent in scientific notation and the letters in hexadecimal values to print in capital letters

o cout << uppercase;

231. Use a stream manipulator to ensure floating-point values print in scientific notation

o cout << scientific;

232. Use a stream manipulator such that, when integer values are output, the integer base for octal and hexadecimal values is displayed.

o cout << showbase;

233. Use a stream member function to set the fill character to '*' for printing in field widths larger than the values being output. Write a separate statement to do this with a stream manipulator

o cout.fill('*');
cout << setfill('*');

234. __________ must be used to initialize constant members of a class

o Member initializers

235. Member objects are constructed __________ their enclosing class object

o before

236. Member function _________ can be used to set and reset format state

o flags

237. Member function read cannot be used to read data from the input object cin

False

238. Member functions seekp and seekg must seek relative to the beginning of a file

o false

239. Outputs to the standard error stream are directed to either the ___________ or the ___________ stream object

o cerr or clog

240. Output operations are supported by class ___________.

o ostream

241. Output to cerr is unbuffered and output to clog is buffered

o true

242. Output the string "Enter your name: "

o cout << "Enter your name: ";

243. Output the address of the variable myString of type char *

o cout << static_cast< void * >(myString);

244. Output the address in variable integerPtr of type int *.

o cout << integerPtr;

245. Output the value pointed to by floatPtr of type float *.

o cout << *floatPtr;

246. Output the characters '0' and 'K' in one statement with ostream function put

o cout.put('0').put('K');


Понравилась статья? Добавь ее в закладку (CTRL+D) и не забудь поделиться с друзьями:  



double arrow
Сейчас читают про: