Computer science

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

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

Suppose sum, num, and j are int variables, and the input is 4 7 12 9 -1. What is the output of the following code? cin >> sum; cin >> num; for (j = 1; j <= 3; j++) { cin >> num; sum = sum + num; } cout << sum << endl; a. 24 b. 25 c. 41 d. 42

a. 24

Consider the following statements: string str = "ABCDEFD"; string::size_type position; After the statement position = str.find('D'); executes, the value of position is ____. a. 3 b. 4 c. 6 d. 7

a. 3

What is the next Fibonacci number in the following sequence? 1, 1, 2, 3, 5, 8, 13, 21, ... a. 34 b. 43 c. 56 d. 273

a. 34

Suppose that x = 55.68, y = 476.859, and z = 23.8216. What is the output of the following statements? cout << fixed << showpoint; cout << setprecision(3); cout << x << ' ' << y << ' ' << setprecision(2) << z << endl; a. 55.680 476.859 23.82 b. 55.690 476.860 23.82 c. 55.680 476.860 23.82 d. 55.680 476.859 23.821

a. 55.680 476.859 23.82

The expression static_cast<int>(9.9) evaluates to ____. a. 9 b. 10 c. 9.9 d. 9.0

a. 9

To use the predefined function tolower, the program must include the header file ____. a. <cctype> b. <iostream> c. <cmath> d. <cstdlib>

a. <cctype>

The standard header file for the abs(x)function is ____. a. <cmath> b. <ioinput> c. <cctype> d. <cstdlib>

a. <cmath>

____ programs perform a specific task. a. Application b. System c. Operating d. Service

a. Application

Suppose that sum is an int variable. The statement sum += 7; is equivalent to the statement sum = sum + 7; a. True b. False

a. True

The basic commands that a computer performs are input (get data), output (display result), storage, and performance of arithmetic and logical operations. a. True b. False

a. True

The constructors of a derived class can (directly) initialize only the (public data) members inherited from the base class of the derived class. 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

The maximum number of significant digits in float values is up to 6 or 7. a. True b. False

a. True

The maximum number of significant digits in values of the double type is 15. a. True b. False

a. True

The number of input data extracted by cin and >> depends on the number of variables appearing in the cin statement. 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

To develop a program to solve a problem, you start by analyzing the problem. a. True b. False

a. True

When reading data into a char variable, after skipping any leading whitespace characters, the extraction operator >> finds and stores only the next character; reading stops after a single character. 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

You can use the function getline to read a string containing blanks. a. True b. False

a. True

Suppose that ch1 and ch2 are char variables and the input is: WXYZ What is the value of ch2 after the following statements execute? cin.get(ch1); cin.putback(ch1); cin >> ch2; a. W b. X c. Y d. Z

a. W

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

A step-by-step problem-solving process in which a solution is arrived at in a finite amount of time is called a(n) ____. a. algorithm b. linker c. analysis d. design

a. algorithm

Suppose that alpha and beta are int variables. The statement alpha = ++beta; is equivalent to the statement(s) ____. a. beta = beta + 1; alpha = beta; b. alpha = beta; beta = beta + 1; c. alpha = alpha + beta; d. alpha = beta + 1;

a. beta = beta + 1; alpha = beta;

The digit 0 or 1 is called a binary digit, or ____. a. bit b. bytecode c. Unicode d. hexcode

a. bit

Suppose cType is a class template, which can take int as a parameter. The statement: ____ declares x to be an object of type cType, and the type passed to the class cType is int. a. cType<int> x; b. cType int x; c. cType int = x; d. cType int :: x;

a. cType<int>

In a sequence of try/catch blocks, the last catch block of that sequence should be ____. a. catch(...){ } b. catch(int x){ } c. catch(str){ } d. catch(exception){}

a. catch(...){ }

Suppose that x is an int variable, ch is a char variable, and the input is: 276. Choose the values after the following statement executes: cin >> ch >> x; a. ch = '2', x = 76 b. ch = '276', x = '.' c. ch = ' ', x = 276 d. ch = 'b', x = 76

a. ch = '2', x = 76

Suppose that ch1 and ch2 are char variables, alpha is an int variable, and the input is: A 18 What are the values after the following statement executes? cin.get(ch1); cin.get(ch2); cin >> alpha; a. ch1 = 'A', ch2 = ' ', alpha = 18 b. ch1 = 'A', ch2 = '1', alpha = 8 c. ch1 = 'A', ch2 = ' ', alpha = 1 d. ch1 = 'A', ch2 = '\n', alpha = 1

a. ch1 = 'A', ch2 = ' ', alpha = 18

Which of the following is a reserved word in C++? a. char b. Char c. CHAR d. character

a. char

Which of the following statements creates a new exception class? a. class myClass {}; b. class myClass {} implements exception; c. class myExceptionClass {} extends exception; d. class myExceptionClass {} throws exception;

a. class myClass {};

To deal with logical errors in a program, such as a string subscript out of range or an invalid argument to a function call, several classes are derived from the class ____. a. logic_error b. logic_exception c. runtime_error d. exception

a. logic_error

What executes immediately after a continue statement in a while and do-while loop? a. loop-continue test b. update statement c. loop condition d. the body of the loop

a. loop-continue test

In ____ structures, the computer repeats particular statements a certain number of times depending on some condition(s). a. looping b. branching c. selection d. sequence

a. looping

To overload the pre-increment (++) operator for a class, if the operator function is a member of that class, it must have ____ parameter(s). a. no b. one c. two d. three

a. no

A data type wherein you directly specify values in the variable declaration with no type name is called a(n) ____________________type.

anonymous

The ____________________ of relational and logical operators is said to be from left to right.

associativity

For a program to use the assert function, it must include which of the following? a. #include <assert> b. #include <cassert> c. #include <assertc> d. #include NDEBUG

b. #include <cassert>

To use the assert function in your program, you should include the statement ____. a. #include <assert> b. #include <cassert> c. #include <iostream> d. #include <exception>

b. #include <cassert>

____ is a valid char value. a. "-129" b. 'A' c. "A" d. 129

b. 'A'

Suppose that ch1, ch2, and ch3 are variables of the type char and the input is: A B C What is the value of ch3 after the following statements execute? cin.get(ch1); cin.get(ch2); cin.get(ch3); a. 'A' b. 'B' c. 'C' d. '\n'

b. 'B'

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? enum courses {ALGEBRA, BASIC, PASCAL, PHILOSOPHY, ANALYSIS}; courses registered; registered = ALGEBRA; cout << registered << endl; a. ALGEBRA b. 0 c. 1 d. "ALGEBRA"

b. 0

Considering the statement string str = "Gone with the wind";, the output of the statement cout << str.find("the") << endl; is ____. a. 9 b. 10 c. 11 d. 12

b. 10

The statement: return 8, 10; returns the value ____. a. 8 b. 10 c. 18 d. 80

b. 10

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

The array index can be any integer less than the array size. a. True b. False

False

The declaration of a friend function cannot be placed within the private part of the class. a. True b. False

False

The execution of a return statement in a user-defined function terminates the program. a. True b. False

False

The expression (x >= 0 && x <= 100) evaluates to false if either x < 0 or x >= 100. a. True b. False

False

The following is a valid C++ enumeration type: enum places {1ST, 2ND, 3RD, 4TH};. a. True b. False

False

The following return statement returns the value 10. return 10, 16; a. True b. False

False

The following statement creates an anonymous type: enum {1ST, 2ND, 3RD, 4TH} places; a. True b. False

False

The function main is always compiled first, regardless of where in the program the function main is placed. a. True b. False

False

The general syntax for accessing a namespace member is: namespace_name->identifier. a. True b. False

False

The heading of a try block can contain ellipses in place of a parameter. a. True b. False

False

The order of the catch blocks does not affect the program. a. True b. False

False

The result of a logical expression cannot be assigned to an int variable, but it can be assigned to a bool variable. a. True b. False

False

The statement in the body of a while loop acts as a decision maker. a. True b. False

False

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

The value of the expression 6 < 5 || 'g' > 'a' && 7 < 4 is ____________________.

False

When writing the definition of a friend function, the name of the class and the scope resolution operator precede the name of the friend function in the function heading. a. True b. False

False

____________________ languages include FORTRAN, COBOL, Pascal, C, C++, and Java.

High-level

Once you write and properly debug a function, you can use it in the program (or different programs) again and again without having to rewrite the same code repeatedly. a. True b. False

True

One of the typical ways of dealing with exceptions is to use an if statement. a. True b. False

True

Operators can be overloaded either for objects of the user-defined types, or for a combination of objects of the user- defined type and objects of the built-in type. a. True b. False

True

Suppose P and Q are logical expressions. The logical expression P && Q is true if both P and Q are true. a. True b. False

True

The associativity of the operator = is from right to left. a. True b. False

True

The control statements in the for loop include the initial statement, loop condition, and update statement.

True

The control variable in a flag-controlled while loop is a bool variable.

True

The data type of a variable in a return statement must match the function type. a. True b. False

True

The following function heading in a C++ program is valid: int funcExp(int u, char v, float g) a. True b. False

True

The following is a legal C++ enumeration type: enum colorType {BLUE, GREEN, PINK, YELLOW, RED}; a. True b. False

True

The number of iterations of a counter-controlled loop is known in advance. 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

The operators != and == have the same order of precedence. a. True b. False

True

The value of the expression 7 + 8 <= 15 is ____________________.

True

Using functions greatly enhances a program's readability because it reduces the complexity of the function main. 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

What is the output of the following C++ code? int x = 55; int y = 5; switch (x % 7) { case 0: case 1: y++; case 2: case 3: y = y + 2; case 4: break; case 5: case 6: y = y - 3; } cout << y << endl; a. 2 b. 5 c. 8 d. 10

a. 2

What is the output of the following statements? cout << setfill('*'); cout << "12345678901234567890" << endl cout << setw(5) << "18" << setw(7) << "Happy" << setw(8) << "Sleepy" << endl; a. 12345678901234567890 ***18 Happy Sleepy b. 12345678901234567890 ***18**Happy**Sleepy c. 12345678901234567890 ***18**Happy Sleepy d. 12345678901234567890 ***18**Happy Sleepy**

b. 12345678901234567890 ***18**Happy**Sleepy

Suppose j, sum, and num are int variables, and the input is 26 34 61 4 -1. What is the output of the code? sum = 0; cin >> num; for (int j = 1; j <= 4; j++) { sum = sum + num; cin >> num; } cout << sum << endl; a. 124 b. 125 c. 126 d. 127

b. 125

Suppose that count is an int variable and count = 1. After the statement count++; executes, the value of count is ____. a. 1 b. 2 c. 3 d. 4

b. 2

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 inheritance is private, all members of the base class, including private members, become private members of the derived class. a. True b. False

b. False

If input failure occurs in a C++ program, the program terminates immediately and displays an error message. 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++, reserved words are the same as predefined identifiers. 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 an output statement, each occurrence of endl advances the cursor to the end of the current line on an output device. 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

In the statement cin >> x;, x can be a variable or an expression. a. True b. False

b. False

It is a good idea to redefine cin and cout in your programs. a. True b. False

b. False

Relational operations can be used on struct variables. a. True b. False

b. False

The class io is the base class of the C++ stream classes istream and ostream. a. True b. False

b. False

The command that does the linking on Visual C++ 2012 Express and Visual Studio 2012 is Make or Remake. a. True b. False

b. False

The device that stores information permanently (unless the device becomes unusable or you change the information by rewriting it) is called primary storage. a. True b. False

b. False

The devices that feed data and programs into computers are called output devices. a. True b. False

b. False

The escape sequence \r moves the insertion point to the beginning of the next line. a. True b. False

b. False

The extraction operator >> skips only all leading blanks when searching for the next data in the input stream. a. True b. False

b. False

The following statements will result in input failure if the input values are not on a separate line. (Assume that x and y are int variables.) cin >> x; cin >> y; a. True b. False

b. False

The private members of a base class can be directly accessed by a derived class. 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

When the computer is turned off, everything in secondary memory is lost. a. True b. False

b. False

When you compile your program, the compiler identifies the logic errors and suggests how to correct them. a. True b. False

b. False

You can use arithmetic operators to perform arithmetic operations on class objects. a. True b. False

b. False

Suppose that you have the following declaration. enum cars {FORD, GM, TOYOTA, HONDA}; cars domesticCars = FORD; The statement: domesticCars = static_cast<cars>(domesticCars + 1); sets the value of domesticCars to ____. a. FORD b. GM c. TOYOTA d. HONDA

b. GM

Suppose that bClass is a class. Which of the following statements correctly derives the class dClass from bClass? a. class dClass:: public bClass { //classMembersList }; b. class dClass: private bClass { //classMembersList }; c. class dClass:: protected bClass { //classMembersList }; d. class bClass: public dClass { //classMembersList };

b. class dClass: private bClass { //classMembersList };

If the derived class classD overrides a public member function functionName of the base class classB, then to specify a call to that public member function of the base class you use the statement ____. a. classD::functionName(); b. classB::functionName(); c. classD.functionName(); d. classB.functionName();

b. classB::functionName();

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

The general form of the functions to overload the binary operators as member functions of a class is returnType operator#(____ className&) const;. a. class b. const c. * d. &

b. const

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

A catch block can have, at most, ____ catch block parameter(s). a. zero b. one c. two d. three

b. one

How many destructors can a class have? a. no explicit destructors b. one c. two d. any number

b. one

If you overload the binary arithmetic operator + as a member function, how many objects must be passed as parameters? a. none b. one c. two d. three

b. one

In a C++ program, one and two are double variables and input values are 10.5 and 30.6. After the statement cin >> one >> two; executes, ____. a. one = 10.5, two = 10.5 b. one = 10.5, two = 30.6 c. one = 30.6, two = 30.6 d. one = 11, two = 31

b. one = 10.5, two = 30.6

The ____ monitors the overall activity of the computer and provides services. a. central processing unit b. operating system c. arithmetic logic unit d. control unit

b. operating system

Suppose that outFile is an ofstream variable and output is to be stored in the file outputData.out. Which of the following statements opens the file outputData.out and associates outFile to the output file? a. outFile("outputData.out"); b. outFile.open("outputData.out"); c. open(outFile,"outputData.out"); d. open.outFile("outputData.out");

b. outFile.open("outputData.out");

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;

Consider the following class definition: class dClass: bClass { //class members list }; The class dClass is derived from the class bClass using the ____ type of inheritance. a. public b. private c. protected d. static

b. private

Which of the following is a legal identifier? a. program! b. program_1 c. 1program d. program 1

b. program_1

The ____ members of an object form its external state. a. private b. public c. protected d. static

b. public

Main memory is called ____. a. read only memory b. random access memory c. read and write memory d. random read only memory

b. random access memory

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

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

Which of the following statements throws a valid exception in C++? a. throw.function(); b. throw 2; c. throws str; d. 4 throw;

b. throw 2

The general syntax to rethrow an exception caught by a catch block is: ____ (in this case, the same exception is rethrown). a. rethrow; b. throw; c. rethrow exception; d. throw exception;

b. throw;

Suppose x is 5 and y is 7. Choose the value of the following expression: (x != 7) && (x <= y) a. false b. true c. 0 d. null

b. true

In C++, ____ is a reserved word. a. deftype b. typedef c. typecc d. alias

b. typedef

The function ____ returns a string containing an appropriate message. a. where b. what c. when d. log

b. what

Consider the following statements: string str1 = "Gone with the wind"; string str2; After the statement str2 = str1.substr(5,4); executes, the value of str2 is "____". a. Gone b. with c. the d. wind

b. with

The ____________________ statement is typically used for two purposes: • To exit early from a loop. • To skip the remainder of a switch structure.

break

To output results correctly, the switch structure must include a(n) ____________________ statement after each cout statement, except the last cout statement.

break

Which of the following is the "not equal to" relational operator? a. ! b. | c. != d. &

c. !=

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. #

Suppose that ch1, ch2, and ch3 are variables of the type char and the input is: A B C Choose the value of ch3 after the following statement executes: cin >> ch1 >> ch2 >> ch3; a. 'A' b. 'B' c. 'C' d. '\n'

c. 'C'

The function that overloads the ____ operator for a class must be declared as a member of the class. a. :: b. * c. -> d. +

c. ->

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

What is the output of the following C++ code? int j; for (j = 10; j <= 10; j++) cout << j << " "; cout << j << endl; a. 10 b. 10 10 c. 10 11 d. 11 11

c. 10 11

Which of the following expressions correctly determines that x is greater than 10 and less than 20? a. 10 < x < 20 b. (10 < x < 20) c. 10 < x && x < 20 d. 10 < x || x < 20

c. 10 < x && x < 20

Suppose sum and num are int variables, and the input is 18 25 61 6 -1. What is the output of the following code? sum = 0; cin >> num; while (num != -1) { sum = sum + num; cin >> num; } cout << sum << endl; a. 92 b. 109 c. 110 d. 119

c. 110

The length of the string "Hello There. " is ____. a. 11 b. 12 c. 13 d. 14

c. 13

Suppose that x = 1565.683, y = 85.78, and z = 123.982. What is the output of the following statements? cout << fixed << showpoint; cout << setprecision(3) << x << ' '; cout << setprecision(4) << y << ' ' << setprecision(2) << z << endl; a. 1565.683 85.8000 123.98 b. 1565.680 85.8000 123.98 c. 1565.683 85.7800 123.98 d. 1565.683 85.780 123.980

c. 1565.683 85.7800 123.98

The length of the string "computer science" is ____. a. 14 b. 15 c. 16 d. 18

c. 16

Suppose that x = 25.67, y = 356.876, and z = 7623.9674. What is the output of the following statements? cout << fixed << showpoint; cout << setprecision(2); cout << x << ' ' << y << ' ' << z << endl; a. 25.67 356.87 7623.96 b. 25.67 356.87 7623.97 c. 25.67 356.88 7623.97 d. 25.67 356.876 7623.967

c. 25.67 356.88 7623.97

The value of the expression 17 % 7 is ____. a. 1 b. 2 c. 3 d. 4

c. 3

Suppose that alpha, beta, and gamma are int variables and the input is: 100 110 120 200 210 220 300 310 320 What is the value of gamma after the following statements execute? cin >> alpha; cin.ignore(100, '\n'); cin >> beta; cin.ignore(100,'\n'); cin >> gamma; a. 100 b. 200 c. 300 d. 320

c. 300

What is the value of x after the following statements execute? int x; x = (5 <= 3 && 'A' < 'F') ? 3 : 4 a. 2 b. 3 c. 4 d. 5

c. 4

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

The statement: return 2 * 3 + 1, 1 + 5; returns the value ____. a. 2 b. 3 c. 6 d. 7

c. 6

What value is returned by the following return statement? int x = 5; return x + 1; a. 0 b. 5 c. 6 d. 7

c. 6

Given the following function: int next(int x) { return (x + 1); } what is the output of the following statement? cout << next(next(5)) << endl; a. 5 b. 6 c. 7 d. 8

c. 7

The output of the statement: cout << pow(2.0, pow(3.0, 1.0)) << endl; is ____. a. 6.0 b. 7.0 c. 8.0 d. 9.0

c. 8.0

Suppose str = "ABCDEFGHI". The output of the statement cout << str.length() << endl; is ____. a. 7 b. 8 c. 9 d. 10

c. 9

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.

Which of the following options should you choose when an exception occurs in the program that analyzes an airline's ticketing transactions? a. Terminate the program. b. Include code in the program to recover from the exception. c. Log the error and continue. d. Include code in the header file.

c. Log the error and continue.

____ is the ability to use the same expression to denote different operations. a. Inheritance b. Encapsulation c. Polymorphism d. Composition

c. Polymorphism

Choose the output of the following C++ statement: cout << "Sunny " << '\n' << "Day " << endl; a. Sunny \nDay b. Sunny \nDay endl c. Sunny Day d. Sunny \n Day

c. Sunny Day

Which of the following statements about inheritance is true if memberAccessSpecifier is protected? a. The private members of the base class become protected members of the derived class. b. The derived class can directly access any member of the base class. c. The public members of the base class become protected members of the derived class. d. The protected members of the base class become private members of the derived class.

c. The public members of the base class become protected members of the derived class.

Which of the following is the syntax to declare the operator function operator[] as a member function of a class for nonconstant arrays? a. Type& []operator(int index); b. Type operator[](int index); c. Type& operator[](int index); d. Type [](int index);

c. Type& operator[](int index);

____ consists of 65,536 characters. a. ASCII-8 b. ASCII c. Unicode d. EBCDIC

c. Unicode

A function prototype is ____. a. a definition, but not a declaration b. a declaration and a definition c. a declaration, but not a definition d. a comment line

c. a declaration, but not a definition

Suppose that str1, str2, and str3 are string variables. After the following statements execute, the value of str3 is "____". str1 = "abc"; str2 = "xyz"; str3 = str1 + '-' + str2; a. abc b. xyz c. abc-xyz d. xyz-abc

c. abc-xyz

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

Suppose that alpha is an int variable and ch is a char variable and the input is: 17 A What are the values after the following statements execute? cin >> alpha; cin >> ch; a. alpha = 17, ch = ' ' b. alpha = 1, ch = 7 c. alpha = 17, ch = 'A' d. alpha = 17, ch = 'a'

c. alpha = 17, ch = 'A'

Suppose that alpha and beta are int variables and alpha = 5 and beta = 10. After the statement alpha *= beta; executes, ____. a. alpha = 5 b. alpha = 10 c. alpha = 50 d. alpha = 50.0

c. alpha = 50

Suppose that alpha and beta are int variables. The statement alpha = beta++; is equivalent to the statement(s) ____. a. alpha = 1 + beta; b. alpha = alpha + beta; c. alpha = beta; beta = beta + 1; d. beta = beta + 1; alpha = beta;

c. alpha = beta; beta = beta + 1;

The function ____ can check whether an expression meets the required conditions; if the conditions are not met, it terminates the program. a. check b. look c. assert d. what

c. assert

Suppose that alpha and beta are int variables. The statement alpha = --beta; is equivalent to the statement(s) ____. a. alpha = 1 - beta; b. alpha = beta - 1; c. beta = beta - 1; alpha = beta; d. alpha = beta; beta = beta - 1;

c. beta = beta - 1; alpha = beta;

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();

The ____ statement can be used to eliminate the use of certain (flag) variables. a. while b. switch c. break d. if

c. break

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

Which of the following is the general syntax of the function prototype to overload the post-increment operator as a member function? a. className operator++(); b. friend className operator++(); c. className operator++(int); d. friend className operator++(int);

c. className operator++(int);

A program called a(n) ____ translates instructions written in high-level languages into machine code. a. assembler b. decoder c. compiler d. linker

c. compiler

To guarantee that the member variables of a class are initialized, you use ____. a. accessors b. mutators c. constructors d. destructor

c. constructors

The expression in an if statement is sometimes called a(n) ____. a. selection statement b. action statement c. decision maker d. action maker

c. decision maker

The new classes that we create from existing classes are called ____ classes. a. sibling b. base c. derived d. parent

c. derived

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'

Which of the following loops does not have an entry condition? a. EOF-controlled while loop b. sentinel-controlled while loop c. do...while loop d. for loop

c. do...while loop

Which of the following loops is guaranteed to execute at least once? a. counter-controlled while loop b. for loop c. do...while loop d. sentinel-controlled while loop

c. do...while loop

An example of a floating point data type is ____. a. int b. char c. double d. short

c. double

Run-time binding is also known as ____ binding. a. static b. shallow c. dynamic d. deep

c. dynamic

A(n) ____-controlled while loop uses a bool variable to control the loop. a. counter b. sentinel c. flag d. EOF

c. flag

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;

The programming language C++ evolved from ____. a. BASIC b. assembly c. C d. C+

c. C

____ is a "hasa" relationship. a. Inheritance b. Encapsulation c. Composition d. Polymorphism

c. Composition

____ represent information with a sequence of 0s and 1s. a. Analog signals b. Application programs c. Digital signals d. System programs

c. Digital signals

Consider the following code. (Assume that all variables are properly declared.) cin >> ch; while (cin) { cout << ch; cin >> ch; } This code is an example of a(n) ____ while loop. a. sentinel-controlled b. flag-controlled c. EOF-controlled d. counter-controlled

c. EOF-controlled

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] << " ";

A variable listed in a header is known as a(n) ____ parameter. a. actual b. local c. formal d. function

c. formal

A(n) ____ function is a nonmember function that has access to all members of the class. a. access b. protected c. friend d. void

c. friend

Given the following code namespace globalType { void printResult(); } which of the following statements is needed to access printResult? a. globalType.printResult(); b. globalType.printResult; c. globalType::printResult(); d. globalType:printResult();

c. globalType::printResult();

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 a member of a class is ____, you cannot access it outside the class. a. public b. automatic c. private d. static

c. private

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;

Suppose that x is an int variable and y is a double variable and the input is: 10 20.7 Choose the values after the following statement executes: cin >> x >> y;. a. x = 10, y = 20 b. x = 10, y = 20.0 c. x = 10, y = 20.7 d. x = 10, y = 21.0

c. x = 10, y = 20.7

Suppose that x is an int variable, y is a double variable, z is an int variable, and the input is: 15 76.3 14 Choose the values after the following statement executes: cin >> x >> y >> z; a. x = 15, y = 76, z = 14 b. x = 15, y = 76, z = 0 c. x = 15, y = 76.3, z = 14 d. x = 15.0, y = 76.3, z = 14.0

c. x = 15, y = 76.3, z = 14

Suppose str = "xyzw";. After the statement str[2] = 'Y'; The value of str is "____". a. xyzw b. xYzw c. xyYw d. xzYw

c. xyYw

When you want to process only partial data, you can use the stream function ____ to discard a portion of the input. a. clear b. skip c. delete d. ignore

d. ignore

Every object of a class maintains a (hidden) pointer to itself, and the name of this pointer is ____. a. self b. object c. it d. this

d. this

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

When an exception is thrown in a function, the function-call stack is ____ so that the exception can be caught in the next try/catch block. a. destroyed b. allocated c. unbound d. unwound

d. unwound

Which of the following statements is used to simplify the accessing of all globalType namespace members? a. using globalType; b. using namespace globalType:all; c. using namespace globalType::all; d. using namespace globalType;

d. using namespace globalType;

In ANSI/ISO Standard C++, the ____________________ mechanism was designed to solve the problem of overlapping global identifiers.

namespace

In ____________________ design, the final program is a collection of interacting objects.

object-oriented object oriented OO oo OOD ood

In OOD, a program is a collection of interacting ____________________; in structured programming, a program is a collection of interacting functions.

objects

In object-oriented design, the first step in the problem-solving process is to identify the components called ____________________, which form the basis of the solution, and to determine how they interact with one another.

objects

The ____________________ monitors the overall activity of the computer and provides services such as memory management, input/output activities, and storage management.

operating system

Consider the following statements. int score; string grade; if (score >= 65) grade = "pass"; else grade = "fail"; If score is equal to 75, the value of grade is "____________________".

pass

The function ____________________ returns the next character in the input stream; it does not remove the character from the input stream.

peek

Manipulators without parameters are part of the ____ header file. a. iostream b. iomanip c. ifstream d. pmanip

pmanip

Which of the following statements declares the studentGrade variable? a. enum studentGrade {A, B, C, D, F}; b. enum int {A, B, C, D, F} studentGrade; c. enum studentGrade {A, B, C, D, F} grades; d. enum grades {A, B, C, D, F} studentGrade;

d. enum grades {A, B, C, D, F} studentGrade;

Which of the following statements creates an anonymous type? a. enum grades {A, B, C, D, F}; b. enum grades {}; c. enum {}; d. enum {A, B, C, D, F} grades;

d. enum {A, B, C, D, F} grades;

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;

To include the operator function operator+ as a nonmember function of the class rectangleType, its prototype in the definition of rectangleType is: ____ rectangleType operator+(const rectangleType&, const rectangleType&); a. bool b. int c. double d. friend

d. friend

A(n) ____________________ is a statement specifying the condition(s) that must be true before the function is called.

precondition

C++ comes with a wealth of functions, called ____________________ functions, that are written by other programmers.

predefined

In a C++ program, statements that begin with the symbol # are called ____________________ directives.

preprocessor

In a while and for loop, the loop condition is evaluated before executing the body of the loop. Therefore, while and for loops are called ____________________ loops.

pretest

By default, all members of a class are ____________________.

private

The constructor of a derived class cannot directly access the ____________________ member variables of the base class.

private

If inheritance is public, all protected members of the base class are ____________________ members of the derived class.

protected

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

Stream variables (for example, ifstream and ofstream) should be passed by ____________________ to a function.

reference

When you attach & after the dataType in the formal parameter list of a function, the variable following that dataType becomes a(n) ____________________ parameter.

reference

____________________ parameters are useful in three situations: • When the value of the actual parameter needs to be changed • When you want to return more than one value from a function • When passing the address would save memory space and time relative to copying a large amount of data

reference

For a list of length n, the ____________________ sort makes exactly (n(n - 1))/2 key comparisons and 3(n-1) item assignments.

selection

A semicolon at the end of the for statement (just before the body of the loop) is a(n) ____________________ error.

semantic

Putting a semicolon after the parentheses following the expression in an if statement (that is, before the statement) is a(n) ____________________ error.

semantic

The term ____________________ describes a process in which the computer evaluates a logical expression from left to right and stops as soon as the value of the expression is known.

short-circuit evaluation

The ____________________ of a function consists of the function name and its formal parameter list.

signature

The string expression strVar.____________________ starts at index pos, replaces the next n characters of strVar with all the characters of str.

strVar.replace(pos, n, str);

A function ____________________ is a function that is not fully coded.

stub

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

A(n) ____________________ is a collection of statements, and when it is activated, or executed, it accomplishes something.

subprogram

If a global identifier in a program has the same name as one of the global identifiers in the header file, the compiler generates a(n) ____________________ error.

syntax

The smallest individual unit of a program written in any language is called a(n) ____________________.

token

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

A(n) ____________________ is a memory location whose contents can be changed.

variable

C++ provides ____________________ functions as a means to implement polymorphism in an inheritance hierarchy.

virtual

The ____________________ of a base class automatically makes the destructor of a derived class virtual.

virtual destructor

If a function needs to return more than one value, as a rule of good programming style, you should change it to a(n) ____________________ function and use the appropriate reference parameters to return the values.

void

Which of the following is the general syntax of the function prototype to overload the pre-increment operator as a nonmember function? a. className operator++(); b. friend className operator++(); c. className operator++(int); d. friend className operator++(className&);

d. friend className operator++(className&);

The general syntax to overload the stream extraction operator >> for a class is ____. a. istream& operator>>(istream&, className&); b. const istream& operator>>(istream&, className&); c. friend operator>>(istream&, className&); d. friend istream& operator>>(istream&, className&);

d. friend istream& operator>>(istream&, className&);

The heading of the function is also called the ____. a. title b. function signature c. function head d. function header

d. function header

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 value of x after the following statements execute? int x = 5; int y = 30; do x = x * 2; while (x < y); a. 5 b. 10 c. 20 d. 40

d. 40

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

The statement: return 37, y, 2 * 3; returns the value ____. a. 2 b. 3 c. y d. 6

d. 6

Assume the following. static_cast<int>('a') = 97 static_cast<int>('A') = 65 The output of the statement: cout << static_cast<int>(tolower('B')) << endl; is ____. a. 65 b. 67 c. 96 d. 98

d. 98

In C++, ____ is called the scope resolution operator. a. . b. ? c. : d. ::

d. ::

Which of the following operators has the lowest precedence?

d. =

The ____ is the brain of the computer and the single most expensive piece of hardware in your personal computer. a. MM b. ROM c. RAM d. CPU

d. CPU

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

Consider the declaration: enum sports {BASKETBALL, FOOTBALL, HOCKEY, BASEBALL, SOCCER}; which of the following statements is true? a. SOCCER-- = BASEBALL b. BASEBALL++ = SOCCER c. HOCKEY + FOOTBALL < SOCCER d. FOOTBALL <= SOCCER

d. FOOTBALL <= SOCCER

When division by zero occurs and the problem is not addressed, the program crashes with an error message that is ____ dependent. a. code b. computer c. platform d. IDE

d. IDE

OOP implements ____. a. UML b. IPE c. EIP d. OOD

d. OOD

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

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)

No arithmetic operations are allowed on the enumeration type. a. True b. False

True

Putting ____________________ in front of a logical expression reverses the value of that logical expression.

!

The preprocessor directive ____________________ is used to prevent multiple inclusions of a header file in a program.

#ifndef

The statement that declares board to be an array of six pointers wherein each pointer is of type int is: int ____________________;

*board[6]

The ASCII data set consists of ____________________ characters.

128

The string concatenation operator is represented by the ____________________ symbol.

ANSWER: + plus

The ____________________ operator causes a member-wise copy of the member variables of the class.

ANSWER: assignment

With the exception of the ____________________ operator and the member selection operator, operators must be overloaded to be used on class objects.

ANSWER: assignment

If the operator new cannot allocate memory space, this operator throws a(n) ____________________ exception.

ANSWER: bad_alloc

A(n) ____________________ block specifies the type of exception it can catch and contains an exception handler.

ANSWER: catch

A(n) ____________________ constructor converts its argument to an object of the constructor's class.

ANSWER: conversion

The ____________________ of the catch block parameter specifies the type of exception that the catch block can catch.

ANSWER: data type

The only built-in operations on classes are assignment (=) and ____________________.

ANSWER: member selection

Any function that overloads an operator is called a(n) ____________________ function.

ANSWER: operator

The class ____________________ deals with the string subscript out of range error.

ANSWER: out_of_range

In C++, throw is a(n) ____________________ word.

ANSWER: reserved

The operators that cannot be overloaded are ., .*, ::, ?:, and ____________________.

ANSWER: sizeof

Throwing an exception is typically done using the ____________________ statement.

ANSWER: throw

All derived classes of the class exception override the function ____________________ to issue their own error messages.

ANSWER: what

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 ____________________ of an array is the address (that is, the memory location) of the first array component.

Base address

Suppose a = 5. After the execution of the statement ++a; the value of a is 6. a. True b. False

a. True

____________________ can be used to identify the authors of the program, give the date when the program is written or modified, give a brief explanation of the program, and explain the meaning of key statements in a program.

Comments comments

____________________ signals represent information with a sequence of 0s and 1s.

Digital

Assume you have three int variables: x = 2, y = 6, and z. Choose the value of z in the following expression: z = (y / x > 0) ? x : y;.

a. 2

2. The following while loop terminates when j > 20. j = 0; while (j < 20) j++; a. True b. False

False

A catch block specifies the type of exception it can catch and immediately terminates the program. a. True b. False

False

A friend function does not have access to the private data members of the class. a. True b. False

False

A function cannot return the value of an enumeration type. a. True b. False

False

An anonymous type can be passed as a parameter to a function. a. True b. False

False

An enumeration type can be passed as a parameter to a function only by value. a. True b. False

False

An exception is an occurrence of an undesirable situation that can be detected during program compilation. a. True b. False

False

An object that is being thrown cannot be an anonymous object. a. True b. False

False

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

Assume that all variables are properly declared. The following for loop executes 20 times. for (i = 0; i <= 20; i++) cout << i;

False

C++ provides all the exception classes you will ever need. 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

If the catch block with an ellipses (in the heading) is needed, then it should be the first catch block in a sequence of try/catch blocks. a. True b. False

False

If the expression in an assert statement evaluates to true, the program terminates. a. True b. False

False

If the formal parameter list of a function is empty, the parentheses after the function name are not needed. a. True b. False

False

In C++, !, &&, and || are called relational operators. a. True b. False

False

In C++, both ! and != are relational operators. a. True b. False

False

In a sentinel-controlled while loop, the body of the loop continues to execute until the EOF symbol is read.

False

Operator functions typically return void. a. True b. False

False

Suppose found = true and num = 6. The value of the expression (!found) || (num > 6) is ____________________.

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

____________________ functions are those that have already been written and are provided as part of the system.

Predefined predefined Standard standard

____________________ is the process of planning and creating a program.

Programming programming

____________________ rules determine the meaning of instructions.

Semantic semantic

In a(n) ____________________ data type, each data item is a collection of other data items.

Structured

A compound statement functions as if it was a single statement. a. True b. False

True

A control structure alters the normal sequential flow of execution in a program. a. True b. False

True

All components of an array are of the same data type. a. True b. False

True

Assume all variables are properly declared. The output of the following C++ code is 2 3 4 5. n = 1; while (n < 5) { n++; cout << n << " "; }

True

Assume that all variables are properly declared. The following statement in a value-returning function is legal. if (x % 2 == 0) return x; else return x + 1; a. True b. False

True

Both parameters of the function to overload the operator << are reference parameters. a. True b. False

True

If no exception is thrown in a try block, all catch blocks associated with that try block are ignored. a. True b. False

True

In C++, && has a higher precedence than ||. a. True b. False

True

In C++, >> is used as a stream extraction operator and as a right shift operator. a. True b. False

True

In C++, [] is called the array subscript operator. a. True b. False

True

In C++, a function prototype is the function heading without the body of the function. a. True b. False

True

In C++, any class can be considered an exception class. a. True b. False

True

In C++, namespace is a reserved word. a. True b. False

True

In C++, operator is a reserved word. a. True b. False

True

In a counter-controlled while loop, the loop control variable must be initialized before the loop.

True

In a two-dimensional array, the elements are arranged in a table form. a. True b. False

True

In the case of the sentinel-controlled while loop, the first item is read before the while loop is entered.

True

Most operator functions can either be member functions or nonmember functions of a class. a. True b. False

True

Which of the following operators has the highest precedence? a. ! b. * c. % d. =

a. !

In C++, ____ is called the address of operator. a. & b. * c. # d. ->

a. &

The output of the statement: cout << tolower('$') << endl; is ____. a. '$' b. '0' c. '1' d. An error, because you cannot use tolower with '$'.

a. '$'

In C++, the null character is represented as ____. a. '\0' b. "\0" c. '0' d. "0"

a. '\0'

Suppose that x is an int variable. Which of the following expressions always evaluates to true? a. (x > 0) || ( x <= 0) b. (x >= 0) || (x == 0) c. (x > 0) && ( x <= 0) d. (x > 0) && (x == 0)

a. (x > 0) || ( x <= 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. +

Given the following function: int strange(int x, int y) { if (x > y) return x + y; else return x - y; } what is the output of the following statement? cout << strange(4, 5) << endl; a. -1 b. 1 c. 9 d. 20

a. -1

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

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

What is the output of the following statements? cout << "123456789012345678901234567890" << endl cout << setfill('#') << setw(10) << "Mickey" << setfill(' ') << setw(10) << "Donald" << setfill('*') << setw(10) << "Goofy" << endl; a. 123456789012345678901234567890 ####Mickey Donald*****Goofy b. 123456789012345678901234567890 ####Mickey####Donald*****Goofy c. 123456789012345678901234567890 ####Mickey####Donald#####Goofy d. 23456789012345678901234567890 ****Mickey####Donald#####Goofy

a. 123456789012345678901234567890 ####Mickey Donald*****Goofy

The expression static_cast<int>(6.9) + static_cast<int>(7.9) evaluates to ____. a. 13 b. 14 c. 14.8 d. 15

a. 13

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

Consider the following code. // Insertion Point 1 using namespace std; const float PI = 3.14; int main() { //Insertion Point 2 float r = 2.0; float area; area = PI * r * r; cout << "Area = " << area <<endl; return 0; } // Insertion Point 3 In this code, where does the include statement belong? a. Insertion Point 1 b. Insertion Point 2 c. Insertion Point 3 d. Anywhere in the program

a. Insertion Point 1

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.

Suppose you have written a program that inputs data from a file. If the input file does not exist when the program executes, then you should choose which option? a. Terminate the program. b. Include code in the program to recover from the exception. c. Log the error and continue. d. Include code in the header file.

a. Terminate the program.

A call to the base class's constructor is specified in the heading of the definition of a derived class constructor. a. True b. False

a. True

A class is an example of a structured data type. a. True b. False

a. True

A derived class can directly access the protected members of the base class. 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

Entering a char value into an int variable causes serious errors, called input failure. 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 a C++ arithmetic expression has no parentheses, operators are evaluated from left to right. 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

If the derived class does not override a public member function of the base class, you may specify a call to that public member function by using the name of the function and the appropriate parameter list. 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

In multiple inheritance, the derived class has more than one base class. a. True b. False

a. True

In protected inheritance, public and protected members of the base class become the protected members of the derived class. a. True b. False

a. True

Information stored in main memory must be transferred to some other device for permanent storage. a. True b. False

a. True

Main memory is directly connected to the CPU. a. True b. False

a. True

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

Which of the following is the general syntax of the function prototype to overload the pre-increment operator ++ as a member function? a. className operator++(); b. className operator++(int); c. friend className operator++(); d. friend className operator++(int);

a. className operator++();

Using a class template, you can write a single code segment for a set of related ____. a. classes b. functions c. operators d. constructors

a. classes

Given the function prototype: double testAlpha(int u, char v, double t); which of the following statements is legal? a. cout << testAlpha(5, 'A', 2); b. cout << testAlpha( int 5, char 'A', int 2); c. cout << testAlpha('5.0', 'A', '2.0'); d. cout << testAlpha(5.0, "65", 2.0);

a. cout << testAlpha(5, 'A', 2);

Classes can create new classes from existing classes. This important feature ____. a. encourages code reuse b. aids the separation of data and operations c. provides public access to the internal state of an object d. results in more software complexity

a. encourages code reuse

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

What is the initial statement in the following for loop? (Assume that all variables are properly declared.) int i; for (i = 1; i < 20; i++) cout << "Hello World"; cout << "!" << endl; a. i = 1; b. i < 20; c. i++; d. cout << "Hello World";

a. i = 1;

Consider the following program segment. ifstream inFile; //Line 1 int x, y; //Line 2 ... //Line 3 inFile >> x >> y; //Line 4 Which of the following statements at Line 3 can be used to open the file progdata.dat and input data from this file into x and y at Line 4? a. inFile.open("progdata.dat"); b. inFile(open,"progdata.dat"); c. open.inFile("progdata.dat"); d. open(inFile,"progdata.dat");

a. inFile.open("progdata.dat")

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

Which of the following function prototypes is valid? a. int funcExp(int x, float v); b. funcExp(int x, float v){}; c. funcExp(void); d. int funcExp(x);

a. int funcExp(int x, float v);

Inheritance is an example of a(n) ____ relationship. a. is-a b. has-a c. handshaking d. had-a

a. is-a

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.

The ____ members of an object form its internal state. a. private b. protected c. public d. static

a. private

To ____ a public member function of a base class in the derived class, the corresponding function in the derived class must have the same name, number, and types of parameters. a. redefine b. overload c. rename d. reuse

a. redefine

Which of the following statements generates a random number between 0 and 50? a. srand(time(0)); num = rand() % 50; b. srand(time(10)); num = rand()/50; c. srand(time(0)); num = rand()50; d. srand(time(10)); num = rand() % 50;

a. srand(time(0)); num = rand() % 50;

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

Which executes first in a do...while loop? a. the statement b. loop condition c. the expression d. update statement

a. the statement

In C++, you can create aliases to a previously defined data type by using the ____ statement. a. typedef b. using c. namespace d. alias

a. typedef

In C++, virtual functions are declared using the reserved word ____. a. virtual b. private c. public d. struct

a. virtual

Consider the following class definitions: class bClass { public: void setX(int a); //Postcondition: x = a; void print() const; private: int x; }; class dClass: public bClass { public: void setXY(int a, int b); //Postcondition: x = a; y = b; void print() const; private: int y; }; Which of the following correctly sets the values of x and y? a. void dClass::setXY(int a, int b) { bClass::setX(a); y = b; } b. void dClass::setXY(int a, int b) { x = a; y = b; } c. void dClass::setXY(int a, int b) { x = bClass::setX(a); y = bClass::setY(b); } d. void dClass::setXY(int a, int b) { x = bClass.setX(a); b = y; }

a. void dClass::setXY(int a, int b) { bClass::setX(a); y = b; }

Suppose that x is an int variable, y is a double variable and ch is a char variable and the input is: 15A 73.2 Choose the values after the following statement executes: cin >> x >> ch >> y; a. x = 15, ch = 'A', y = 73.2 b. x = 15, ch = 'A', y = 73.0 c. x = 15, ch = 'a', y = 73.0 d. This statement results in an error because there is no space between 15 and A.

a. x = 15, ch = 'A', y = 73.2

Suppose that x and y are int variables, z is a double variable, and the input is: 28 32.6 12 Choose the values of x, y, and z after the following statement executes: cin >> x >> y >> z; a. x = 28, y = 32, z = 0.6 b. x = 28, y = 32, z = 12.0 c. x = 28, y = 12, z = 32.6 d. x = 28, y = 12, z = 0.6

a. x = 28, y = 32, z = 0.6

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

What is the output of the following program? #include <iostream> using namespace std; class bClass { public: void print() const; bClass(int a = 0, int b = 0); //Postcondition: x = a; y = b; private: int x; int y; }; class dClass: public bClass { public: void print() const; dClass(int a = 0, int b = 0, int c = 0); //Postcondition: x = a; y = b; z = c; private: int z; }; int main() { bClass bObject(2, 3); dClass dObject(3, 5, 8); bObject.print(); cout << endl; dObject.print(); cout << endl; return 0 ; } void bClass::print() const { cout << x << " " << y << endl; } bClass::bClass(int a, int b) { x = a; y = b; } void dClass::print() const { bClass:print(); cout << " " << z << endl; } dClass::dClass(int a, int b, int c) : bClass(a, b) { z = c; } a. 2 3 2 3 b. 2 3 3 5 8 c. 3 5 8 3 5 8 d. 5 8 3 5 8

b. 2 3 3 5 8

The value of the expression 33/10, assuming both values are integral data types, is ____. a. 0.3 b. 3 c. 3.0 d. 3.3

b. 3

What is the output of the following C++ code? int x = 35; int y = 45; int z; if (x > y) z = x + y; else z = y - x; cout << x << " " << y << " " << z << endl; a. 35 45 80 b. 35 45 10 c. 35 45 -10 d. 35 45 0

b. 35 45 10

____ is a valid int value. a. 46,259 b. 46259 c. 462.59 d. -32.00

b. 46259

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 a relational operator? a. = b. == c. ! d. &&

b. ==

Which of the following is true about a derived class? a. A derived class can directly access any member variable of the base class. b. A derived class can redefine any public member function of the base class. c. A derived class can have at most one base class. d. A derived class can redefine any member function of the base class.

b. A derived class can redefine any public member function of the base class.

Which of the following is an allowable aggregate operation on a struct? a. Arithmetic b. Assignment c. Input/output d. Comparison

b. Assignment

Consider the following statements: string str1 = "ABCDEFGHIJKLM"; string str2; After the statement str2 = str1.substr(1,4); executes, the value of str2 is "____". a. ABCD b. BCDE c. BCD d. CDE

b. BCDE

____ is the ability to combine data, and operations on that data, in a single unit. a. Inheritance b. Encapsulation c. Polymorphism d. Composition

b. Encapsulation

A comma is also called a statement terminator. a. True b. False

b. False

A derived class cannot directly access public members of a base class. a. True b. False

b. False

A function can return a value of the type array. a. True b. False

b. False

A mixed arithmetic expression contains all operands of the same type. a. True b. False

b. False

Aggregate input/output operations are allowed on a struct variable. a. True b. False

b. False

An operator that has only one operand is called a unique operator. 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

C++ programs have always been portable from one compiler to another. 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

____ are executable statements that inform the user what to do. a. Variables b. Prompt lines c. Named constants d. Expressions

b. Prompt lines

Which statement below about prototypes and headers is true? a. Parameter names must be listed in the prototype, but not necessarily in the header. b. Prototypes end with a semicolon, but headers do not. c. Headers should come before prototypes. d. Headers end with a semicolon, but prototypes do not.

b. Prototypes end with a semicolon, but headers do not.

Suppose that ch1 and ch2 are char variables and the input is: WXYZ What is the value of ch2 after the following statements execute? cin >> ch1; ch2 = cin.peek(); cin >> ch2; a. W b. X c. Y d. Z

b. X

Which of the following is the newline character? a. \r b. \n c. \l d. \b

b. \n

A variable or expression listed in a call to a function is called the ____. a. formal parameter b. actual parameter c. data type d. type of the function

b. actual parameter

Which of the following is a valid C++ statement? a. assert(0 = divisor); b. assert(divisor != 0); c. assert(divisor 0); d. assert(divisor is 0);

b. assert(divisor != 0);

Which of the following is a built-in operation on classes? a. increment b. assignment c. decrement d. relational operators

b. assignment

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

Existing classes, from which you create new classes, are called ____ classes. a. child b. base c. sibling d. derived

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

Which of the following function prototypes overloads the != operator for the class rectangleType? a. bool operator!=(rectangle&) const; b. bool operator!=(const rectangleType&) const; c. int operator!=(const rectangleType) const; d. int operator!=(rectangle&) const;

b. bool operator!=(const rectangleType&) const;

A sequence of eight bits is called a ____. a. binary digit b. byte c. character d. double

b. byte

Which of the following blocks is designed to catch any type of exception? a. catch(){ } b. catch(...){ } c. catch(*){ } d. catch(exception){ }

b. catch(...){ }

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;

Suppose that x and y are int variables. Which of the following is a valid input statement? a. cin >> x >> cin >> y; b. cin >> x >> y; c. cin << x << y; d. cout << x << y;

b. cin >> x >> y;

Which of the following class definitions makes the public members of the class aClass become the public members of the class bClass? a. class aClass: public bClass { //... }; b. class bClass: public aClass { //... }; c. class bClass: aClass { //... }; d. class aClass: bClass { //... };

b. class bClass: public aClass { //... };

Which of the following is a valid definition of the derived class bClass? a. class aClass: public bClass { //... }; b. class bClass: public aClass { //... }; c. class aClass::bClass { //... }; d. class bClass::aClass { //... }

b. class bClass: public aClass { //... };

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

Which of the following is the syntax to declare the operator function operator[] as a member function of a class for constant arrays? a. const Type& []operator(int index) const; b. const Type& operator[](int index) const; c. const Type& operator[](int index); d. const Type [](int index) const;

b. const Type& operator[](int index) 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

15. Consider the following code. int limit; int reps = 0; cin >> limit; while (reps < limit) { cin >> entry; triple = entry * 3; cout << triple; reps++; } cout << endl; This code is an example of a(n) ____ while loop. a. flag-controlled b. counter-controlled c. EOF-controlled d. sentinel-controlled

b. counter-controlled

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;

Given the following function prototype: int myFunc(int, int);, which of the following statements is valid? Assume that all variables are properly declared. a. cin >> myFunc(y); b. cout << myFunc(myFunc(7, 8), 15); c. cin >> myFunc('2', '3'); d. cout << myFunc(myFunc(7), 15);

b. cout << myFunc(myFunc(7, 8), 15);

Given the following function prototype: double tryMe(double, double);, which of the following statements is valid? Assume that all variables are properly declared. a. cin >> tryMe(x); b. cout << tryMe(2.0, 3.0); c. cout << tryMe(tryMe(double, double), double); d. cout << tryMe(tryMe(float, float), float);

b. cout << tryMe(2.0, 3.0);

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

A(n) ____ is an occurrence of an undesirable situation that can be detected during program execution. a. crash b. exception c. misfire d. bug

b. exception

The class ____ is the base of the classes designed to handle exceptions. a. class b. exception c. logic_error d. runtime_error

b. exception

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;

When a continue statement is executed in a ____, the update statement always executes. a. while loop b. for loop c. switch structure d. do...while loop

b. for loop

The memory allocated for a float value is ____ bytes. a. two b. four c. eight d. sixteen

b. four

The term GB refers to ____. a. giant byte b. gigabyte c. group byte d. great byte

b. gigabyte

Which of the following will cause a logical error if you are attempting to compare x to 5? a. if (x == 5) b. if (x = 5) c. if (x <= 5) d. if (x >= 5)

b. if (x = 5)

The devices that feed data and programs into computers are called ____ devices. a. entry b. input c. output d. secondar

b. input

The declaration int a, b, c; is equivalent to which of the following? a. inta , b, c; b. int a,b,c; c. int abc; d. int a b c;

b. int a,b,c;

A program that loads an executable program into main memory is called a(n) ____. a. compiler b. loader c. linker d. assembler

b. loader

In C++, the dot is an operator called the ____ operator. a. dot access b. member access c. data access d. member

b. member access

The components of a class are called the ____ of the class. a. elements b. members c. objects d. properties

b. members

A loop that continues to execute endlessly is called a(n) ____ loop. a. end b. unhinged c. infinite d. definite

c. infinite

The basic commands that a computer performs are ____, and performance of arithmetic and logical operations. a. input, file, list b. output, folder, storage c. input, output, storage d. storage, directory, log

c. input, output, storage

Given the following function prototype: int test(float, char);, which of the following statements is valid? a. cout << test(12, &); b. cout << test("12.0", '&'); c. int u = test(5.0, '*'); d. cout << test('12', '&');

c. int u = test(5.0, '*');

What does <= mean? a. less than b. greater than c. less than or equal to d. greater than or equal to

c. less than or equal to

A program called a(n) ____ combines the object program with the programs from libraries. a. assembler b. decoder c. linker d. compiler

c. linker

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

In a bubble sort for list of length n, the first step is to compare elements ____. a. list[0] and list[n] b. list[0] and list[n-1] c. list[0] and list[1] d. list[n-1] and list[n+1]

c. list[0] and list[1]

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

Main memory is an ordered sequence of items, called ____. a. pixels b. registers c. memory cells d. addresses

c. memory cells

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

When one control statement is located within another, it is said to be ____. a. blocked b. compound c. nested d. closed

c. nested

The name of the function to overload the operator <= is ____. a. overload<= b. <=new c. operator<= d. <=operator

c. operator<=

The devices that the computer uses to display results are called ____ devices. a. exit b. entry c. output d. input

c. output

Which of the following classes is derived from the class runtime_error? a. bad_alloc b. out_of_range c. overflow_error d. length_error

c. overflow_error

If the corresponding functions in the base class and the derived class have the same name but different sets of parameters, then this function is ____ in the derived class. a. reused b. redefined c. overloaded d. overridden

c. overloaded

The code int *p; declares p to be a(n) ____ variable. a. new b. num c. pointer d. address

c. pointer

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)

The class ____ is designed to deal with errors that can be detected only during program execution. a. error b. exception c. runtime_error d. logic_error

c. runtime_error

In a ____ control structure, the computer executes particular statements depending on some condition(s). a. looping b. repetition c. selection d. sequence

c. selection

The identifiers in the system-provided header files such as iostream, cmath, and iomanip are defined in the namespace ____. a. cctype b. stdl c. std d. stdlib

c. std

The logic_error and runtime_error classes are defined in the header file ____. a. stdex b. stdlib c. stdexcept d. exception

c. stdexcept

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");

Before using the data type string, the program must include the header file ____. a. enum b. iostream c. string d. std

c. string

Dividing a problem into smaller subproblems is called ____ design. a. OOD b. top-down refinement c. structured d. analog

c. structured

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

The ____ function is used to interchange the contents of two string variables. a. iterator b. traverse c. swap d. change

c. swap

The ____ rules of a programming language tell you which statements are legal, or accepted by the programming language. a. semantic b. logical c. syntax d. grammatical

c. syntax

Suppose cType is a class template, and func is a member function of cType. The heading of the function definition of func is: ____. a. template <class Type> funcType cType<Type> == func(parameters) b. template <class Type> funcType cType<Type> c. template <class Type> funcType cType<Type>::func(parameters) d. template <class Type> funcType cType<Type>func(parameters;

c. template <class Type> funcType cType<Type>::func(parameters)

When an exception is thrown, if the program does not handle the exception, then the function ____ is called to terminate the program. a. log b. what c. terminate d. close

c. terminate

When an object invokes a member function, the member function references the pointer ____ of the object. a. object b. it c. this d. address

c. this

The statements that may generate an exception are placed in a ____ block. a. throw b. finally c. try d. catch

c. try

When the post-increment operator is overloaded as a nonmember function of the class, the operator function has ____ parameter(s). a. no b. one c. two d. three

c. two

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

Which of the following is a valid C++ statement? a. typedef integer; b. typedef int; c. typedef int integer; d. typedef integer int;

c. typedef int integer;

C++ provides ____ functions as a means to implement polymorphism in an inheritance hierarchy, which allows the run-time selection of appropriate member functions. a. redefined b. overridden c. virtual d. overloaded

c. virtual

Functions that do not have a return type are called ____ functions. a. zero b. null c. void d. empty

c. void

A(n) ____________________ function of a class changes the values of the member variable(s) of the class.

mutator

C++ has a special name for the data types istream and ostream. They are called ____________________.

classes

A program or software that uses and manipulates the objects of a class is called a(n) ____________________ of that class.

client

In ____________________ (aggregation), one or more members of a class are objects of another class type.

composition

The word ____________________ is used before the array declaration in a function heading to prevent the function from modifying the array.

const

To generate a random number, you can use the function rand of the header file ____________________.

cstdlib

You can disable assert statements by using which of the following? a. #include <cassert> b. #define <assert> c. #clear NDEBUG d. #define NDEBUG

d. #define NDEBUG

13. What is the output of the following C++ code? num = 10; while (num > 10) num = num - 2; cout << num << endl; a. 0 b. 6 c. 8 d. 10

d. 10

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

The output of the statement: cout << pow(3.0, 2.0) + 5 << endl; is ____. a. 11.0 b. 12.0 c. 13.0 d. 14.0

d. 14.0

What is the output of the following C++ code? count = 1; num = 25; while (count < 25) { num = num - 1; count++; } cout << count << " " << num << endl; a. 24 0 b. 24 1 c. 25 0 d. 25 1

d. 25 1

Which of the following is true about inheritance? a. All public member functions of the base class become the public member functions of the derived class. b. All public member variables of the base class become the public member variables of the derived class. c. All public members of the base class become the public members of the derived class. d. The public member variables of the base class become the public or private member variables of the derived class.

d. The public member variables of the base class become the public or private member variables of the derived class.

What is the output of the following loop? count = 5; cout << 'St'; do { cout << 'o'; count--; } while (count <= 5); a. St b. Sto c. Stop d. This is an infinite loop.

d. This is an infinite loop.

Suppose that x and y are int variables, ch is a char variable, and the input is: 4 2 A 12 Choose the values of x, y, and ch after the following statement executes: cin >> x >> ch >> y; a. x = 4, ch = 2, y = 12 b. x = 4, ch = A, y = 12 c. x = 4, ch = ' ', y = 2 d. This statement results in input failure

d. This statement results in input failure

Suppose that alpha and beta are int variables. The statement alpha = beta--; is equivalent to the statement(s) ____. a. alpha = 1 - beta; b. alpha = beta - 1; c. beta = beta - 1; alpha = beta; d. alpha = beta; beta = beta - 1;

d. alpha = beta; beta = beta - 1;

The try block is followed by one or more ____ blocks. a. throw b. finally c. do d. catch

d. catch

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

The general syntax for the function prototype to overload the assignment operator = for a class is ____. a. friend className& operator=(const className&); b. className& operator=(className&); c. string className& operator=(className&); d. const className& operator=(const className&);

d. const className& operator=(const className&);

Given the function prototype: float test(int, int, int); which of the following statements is legal? a. cout << test(7, test(14, 23)); b. cout << test(test(7, 14), 23); c. cout << test(14, 23); d. cout << test(7, 14, 23);

d. cout << test(7, 14, 23);

Consider the following class definitions: class bClass { public: void set(double a, double b); //Postcondition: x = a; y = b; void print() const; bClass(); //Postcondition: x = 0; y = 0; bClass(double a, double b); //Postcondition: x = a; y = b; private: double x; double y; }; class dClass: public bClass { public: void set(double a, double b, double c); //Postcondition: x = a; y = b; z = c; void print() const; dClass(); //Postcondition: x = 0; y = 0; z = 0 ; dClass(double a, double b, double c); //Postcondition: x = a; y = b; z = c; private: double z; }; Which of the following dClass constructor definitions is valid in C++? a. dClass::dClass(double a, double b, double c) : bClass() { x = a; y = b; z = c; } b. dClass::dClass(double a, double c) { x = a; z = c; } c. dClass::dClass(double a, double b) : bClass() { x = a; y = b; } d. dClass::dClass(double a, double b, double c) : bClass(a, b) { z = c; }

d. dClass::dClass(double a, double b, double c) : bClass(a, b) { z = c; }

Which of the following is a repetition structure in C++? a. if b. switch c. while...do d. do...while

d. do...while

____ loops are called posttest loops. a. break b. for c. while d. do...while

d. do...while

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

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 prototypes is valid? a. int funcTest(int x, int y, float z){} b. funcTest(int x, int y, float){}; c. int funcTest(int, int y, float z) d. int funcTest(int, int, float);

d. int funcTest(int, int, float);

The class ____ is designed to deal with illegal arguments used in a function call. a. illegal_argument b. bad_argument c. invalid_call d. invalid_argument

d. invalid_argument

The return type of the function to overload the operator >> must be a reference to a(n) ____ object. a. iostream b. ostream c. stream d. istream

d. istream

Several categories of computers exist, such as ____. a. microframe, midframe, and miniframe b. midsize, microframe, and mainframe c. mainsize, midsize, and microsize d. mainframe, midsize, and micro

d. mainframe, midsize, and micro

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

The scope of a namespace member is local to the ____. a. function b. block c. file d. namespace

d. namespace

A(n) ____ consists of data and the operations on those data. a. disk b. compiler c. interpreter d. object

d. object

Class templates are called ____ types. a. polymorphic b. structured c. member d. parameterized

d. parameterized

What is the output of the following code? char lastInitial = 'S'; switch (lastInitial) { case 'A': cout << "section 1" <<endl; break; case 'B': cout << "section 2" <<endl; break; case 'C': cout << "section 3" <<endl; break; case 'D': cout << "section 4" <<endl; break; default: cout << "section 5" <<endl; } a. section 2 b. section 3 c. section 4 d. section 5

d. section 5

____ is a parameterized stream manipulator. a. endl b. fixed c. scientific d. setfill

d. setfill

The data type string has a named constant, ____, associated with it. a. string::size b. string::size_type c. string::pos d. string::npos

d. string::npos

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

Suppose that sum and num are int variables and sum = 5 and num = 10. After the statement sum += num executes, ____. a. sum = 0 b. sum = 5 c. sum = 10 d. sum = 15

d. sum = 15

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 following class definitions: class bClass { public: void setX(int); void print() const; private: int x; }; class dClass: public bClass { public: void setXY(int, int); void print() const; private: int y; }; Which of the following statements correctly redefines the member function print of bClass? a. void dClass::print() const { dClass:print(); cout << " " << y << endl; } b. void dClass::print() const { cout << x << " " << y << endl; } c. void bClass::print() const { cout << x << " " << y << endl; } d. void dClass::print() const { bClass::print(); cout << "y = " << y << endl; }

d. void dClass::print() const { bClass::print(); cout << "y = " << y << endl; }

If you want to include members in your exception class, you typically include the function ____. a. that b. this c. log d. what

d. what

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 values in the domain of an enumeration type are called ____________________.

enumerators

The binding of virtual functions occurs at program ____________________ time.

execution

Once an input stream enters a(n) ____________________ state, all subsequent input statements associated with that input stream are ignored, and the computer continues to execute the program, which produces erroneous results.

fail

C++ provides a header file called ____________________, which is used for file I/O.

fstream

A(n) ____________________ contains the definitions of the functions to implement the operations of an object.

implementation file

The string expression strVar.____________________ inserts all the characters of str at index pos into strVar.

insert(pos, str);

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

A loop ____________________ is a set of statements that remains true each time the loop body is executed.

invariant

The function eof is a member of the data type ____________________.

istream

In C++, the mechanism that allows you to combine data and operations on the data into a single unit is called a(n) ____________________.

lass

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

In C++, the dot is an operator called the ____________________operator.

member access

Assembly language uses easy-to-remember instructions called ____________________.

mnemonics


Set pelajaran terkait

AP Euro Chapter 15 Test Review: Seventeenth-Century Crisis and Rebuilding

View Set

ATI TEAS English Practice, TEAS English Test Practice, ATI TEAS 6 study guide Math, TEAS 6 Science, TEAS

View Set

Datadog & DevOps Level 2 Technical Questions/terminology

View Set

Law 3220 Legal Environment of Business Exam 2 (Ch. 5-7, 9)

View Set

ICORE MARKETING FALL FINAL 2017 KITZ

View Set

Julius cease terms and definition test

View Set