Question: Question 31 Here is a class prototype and some static members, followed by a static initializer: class Student { public: static const int SORT_BY_FIRST =

Question 31

Here is a class prototype and some static members, followed by a static initializer:

class Student { public: static const int SORT_BY_FIRST = 88; static const int SORT_BY_LAST = 98; static const int SORT_BY_POINTS = 108; private: static int sortKey; // ... etc. }; int Student::sortKey = 88; 

Check the true statements (there may be more than one):

The initial sortKey is SORT_BY_LAST
The initial sortKey is SORT_BY_POINTS
The initial sortKey is SORT_BY_FIRST
If a programmer changes the first three const initializations from 88, 98, 108 to 0, 1, 2, but makes no other change, the program will have a logic error.

If a programmer changes the first three const initializations from 88, 98, 108 to 0, 1, 2, but makes no other change, the program will have a compiler error.

Assuming everything else is correct, a program using the code above will run perfectly but is not making maximum use of the three symbolic constants defined.

The program will not run correctly because a literal is used to initialize sortKey.

Question 32

If two int pointers, pMyAge and pYourAge, both point to the same int, age, then the statement:

 age = 7; 

will have what impact if followed immediately by the following statements? (Only one correct choice). It will:

cause only

 cout << *pMyAge; 

to display 7, but not

 cout << *pYourAge; 

cause only

 cout << *pYourAge; 

to display 7, but not

 cout << *pMyAge; 

cause both

 cout << *pYourAge; 

and

 cout << *pMyAge; 

to display 7.

cause both

 cout << pYourAge; 

and

 cout << pMyAge; 

to display 7.

Question 33

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

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

Question 34

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

There are no "sub-classes" (a topic from CS 2B we have not covered in CS 2A) 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):

methodA() can access private data of aObj directly, as in aObj.somePrivateMember = something, without the need for a public mutator or accessor.
methodA() can access private data of its calling object (the this object) directly, as in somePrivateMember = something, without the need for a public mutator or accessor and without the need to dereference anything.
If methodA() modifies a private instance 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.
If methodA() modifies a private instance 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.

Question 35

Within an instance method, a programmer might utilize the special syntax this->someMember to reasonably assist with which of the following challenges? (Check all that apply):

To get at private data of the calling object, since without this-> before the member, that member's privacy prohibits direct access.
To get at private data of a parameter that is passed to the method.
To get at private data of the calling object (the this object), if there is a local variable that has the same name as the instance member in question.
To enhance readability, if the programmer wants to allow the reader to easily distinguish instance members in their methods from local variables of those methods. While not required, prependingthis-> to each member used in the method can only mean that those variables refer to the calling object's members.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!