Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Assume that we have defined an enum type Planet and an instance memberMethod() in class SolarSystem : class SolarSystem { public: enum Planet {

1.

Assume that we have defined an enum type Planet and an instance memberMethod() in classSolarSystem:

class SolarSystem { public: enum Planet { MERCURY, VENUS, EARTH, MARS, JUPITER, SATURN, URANUS, NEPTUNE }; void memberMethod(); // other class things omitted ... }; 

Which statement has an enum-related compiler error? Assume that these are isolated statements in otherwise sensible method definitions and that there are no variables with the names MERCURY,... NEPTUNE anywhere in our program other than the ones seen above.

A.
void SolarSystem::memberMethod() { Planet myHome = EARTH; } 
B.
void SolarSystem::memberMethod() { SolarSystem::Planet myHome = SolarSystem::EARTH; } 
C.
int main() { SolarSystem::Planet myHome; myHome = EARTH; } 
D.
int main() { SolarSystem::Planet myHome; myHome = SolarSystem::EARTH; if (myHome > SolarSystem::JUPITER) // ... } 
E.
int main() { cout << SolarSystem::EARTH; } 

2.

Which describe a design in which B is a derived class of base class A? (Check all that apply.)

A. Class A is Building that shelters people and equipment.

Class B is a HighRise, which has a minimum of five floors (stories) with stairs and elevators and utilized by government agencies, condo complexes and companies.

B. Class A is Building that shelters people and equipment.

Class B is a CityVisualizer which will render one or more Buildings in 3D on a computer or smart phone screen.

C. Class A is an AutoPart which goes into a car or truck. It has a part number, weight and price.

Class B is a Automobile -- either a Car or a Truck.

D. Class A is an AutoPart which goes into a car or truck. It has a part number, weight and price.

Class B is a FuelInjector, a special kind of part that goes into cars and trucks.

4.

Consider the following 2-D array allocation:

 double * myArray[3]; int k; for (k = 0; k < 3; k++) myArray[k] = new double[5]; 

Assume that we deallocate in a sensible manner using simple loop structures that would work no matter how large the array was. Check all the true statements:

A. It is a completely dynamic array having 5 rows and 3 columns.
B. It is a completely dynamic array having 3 rows and 5 columns.
C. It is a partially dynamic array having 5 rows and 3 columns.
D. It is a partially dynamic array having 3 rows and 5 columns.
E. Memory freeing will require one un-nested loop.
F. Memory freeing will require a double-nested loop.

5.

Which describe a design in which B is a derived class of base class A? (Check all that apply -- there may be one or more checked box.)

A. Class A is an Sleeve, something that goes into a shirt, jacket or sweater.

Class B is a Jacket.

B. Class A is an InventoryItem, something a business stocks and sells to a customer. It has an item number and price.

Class B is an MensApparelItem, which is stocked and sold by a department store like Macy's.

C. Class A is a Jacket something that is worn to keep a person warm.

Class B is an JacketSleeve (something that goes into a Jacket).

D. Class A is an MensApparelItem, which is stocked and sold by a department store like Macy's.

Class B is an InventoryItem, something a business stocks and sells to a customer. It has an item number and price.

6.

In which type of class methods is it typically necessary to filter bad arguments (either directly or indirectly with the help of validators) in order to protect private data of your class?

A. A set() method (non-constructor mutator).
B. A get() method (non-constructor accessor).
C. A Constructor that takes parameters.
D. A display() (or show()) method, which takes no parameters, intended to output the data of the class for the display.
E. A toString() method, which takes no parameters, intended to return some private data to the client in the form of a string.

7.

An array of 100 elements is to be sorted using the bubble sort in the modules (the one that tests the return value of floatLargestToTop() to see if it can return "early".) Check all the true statements about the sort algorithm, i.e., the sort method and its support methods. (Check all that apply.)

A. It will always return (completely sorted) after 99 data comparisons.
B. It will sometimes return (completely sorted) after only 99 data comparisons.
C. It will always require at least one swap.
D.

It will always require at least 99 comparisons

8.

Which of the following are good candidates for instance variables for a class that you would define?

A. Constants used by the class and the client.
B. Variables (like loop counters or temporary variables) used by most or all of your instance methods (in an attempt to avoid redeclaring these variables multiple times as locals for each instance method).
C. Variables whose values are shared by all class objects.
D. Private data whose values could be different for different objects of the class.

9.

If we operate bitwise on the following two decimal integers, as indicated, what are the two resulting decimal answers?

9 bitwise-or 7 9 bitwise-and 7

A. 15 2
B. 12 2
C. 15 1
D. 12 1
E. 16 1

10.

If an instance method calls another instance method of the same class, an object must be used for dereferencing the call.

True False

11.

Check the true statement(s) (There is at least one correct choice, possibly more.)

A. A static method can access an instance member (of the same class) inside its definition using only the member name, no object or class name prepended (i.e., without someObj. in front).
B. An instance method can access a static member (of the same class) inside its definition using only the member name, no object or class name prepended (i.e., without ClassName:: or someObj. in front).
C. An instance method can access a static member (of the same class) inside its definition using only the member name, no object or class name prepended (i.e., without ClassName:: or someObj. in front).
D. A static method can access a static member (of the same class) inside its definition using only the member name, no object or class name prepended (i.e., without ClassName:: or someObj. in front).

12.

ClassA has a method, void methodA( ClassA aObj ), which takes, as a parameter, an object of the same ClassA.

There are no "sub-classes" involved. ClassA is the only class in the discussion and is not derived from any other user-defined classes.)

Check all the true statements. (Check all that apply):

A. methodA() can access private data of aObj directly, as in aObj.somePrivateMember = something, without the need for a public mutator or accessor.
B. methodA() can access private data of its calling object (the this object) directly, as insomePrivateMember = something, without the need for a public mutator or accessor and without the need to dereference anything.
C. If methodA() modifies a private member of its calling object (the this object), it will result in a simultaneous change of the corresponding private member in the parameter object, aObj, even if aObj is a different object than the calling object.
D. If methodA() modifies a private member of the parameter object, aObj, it will result in a simultaneous change of the corresponding private member in the calling object (the this object), even if aObj is a different object than the calling object.

13.

The statements

 Card *card1, *card2, *card3, myCard; card1 = new Card; card2 = card1; 

will cause how many card objects to be instantiated? (only one correct choice):

A. 0
B. 1
C. 2
D. 3
E.

4

14.

A constructor is used to:

A. ... declare the member variables of a class.
B. ... initialize the instance members of a class.
C. ... initialize the static members of a class.
D. ... initialize both instance and static members of a class.

15.

If varA and varB are two instantiated object variables of some class, then varB = varA copies all the (shallow) data members from varA's object over to varB's object. Assume that = has not been overloaded (i.e., has its default meaning).

True False

16.

In the following numbers, we use (D) to denote ordinary decimal notation, and (H) to denote hexadecimal notation:

 FF (H) 11 (H) 5 (D) 11 (D) 

Which of the following are the correct binary representation of these four numbers?

A.
11111111 10001 101 1011 
B.
11001100 10001 101 1101 
C.
11001100 10001000 101 1101 
D.
11111111 10001 10000 1011 
E.
11111111 10001 101 11 

17.

A binary search of a pre-sorted array of 256 elements would take (at most) how many comparisons? (Assume the search key is the key on which the array is sorted).

[I allow for off-by-one errors in this problem, so if your prediction is within one of the posted choice below, choose it.]

A. 1
B. 4
C. 9
D. 255
E. 256

18. A binary search algorithm is written (as in the modules, for example) which searches a pre-sorted array for some user-defined value, clientData. If clientData is stored in the array, it returns its array position, and if not found, it returns -1 (again, just like in the modules). Assume the array to be searched has 100 data elements in it. (Check all that apply):

[NOTE: due to common off-by-one interpretations when counting such things, if your predicted answer is within one (+1 or -1) of a posted option below, you can assume your prediction and the choice you are looking at are equivalent and check that option.]

A. It might return to the client with an answer after only one comparison of data.
B. It may require as many as 99 comparisons of data before it returns.
C. It will always return with an answer in 7 or fewer comparisons of data.
D. It will always return with an answer in 3 or fewer comparisons of data.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Management Process

Authors: Lee Long

4th Edition

978-0201822939,0201822938

Students also viewed these Databases questions