Question: question 21. Here is an prototype for a working class OldCellPhone that has no errors (you may see this exact class several times in this

question 21.

Here is an prototype for a working class OldCellPhone that has no errors (you may see this exact class several times in this exam):

class OldCellPhone { public: static const int MIN_CAP = 10; static const int MAX_CAP = 1000; static const string DEFAULT_DSCR; private: string description; int memCapacity; bool camera; bool gps; public: OldCellPhone(string dscr = DEFAULT_DSCR, int mem = MIN_CAP, bool cam = false, bool gp = false); string toString(); bool setMemCapacity(int mem); void setCamera( bool hasCam ) { camera = hasCam; } void setGps( bool hasGps ) { gps = hasGps; } }; 

A programmer decides to make the static DEFAULT_DSCR mutable, removing its const status, as in:

 static string DEFAULT_DSCR; 

A mutator is added for this member. Any string whose length is at least 2 characters will be acceptable as a new DEFAULT_DSCR. Check the true statements (there may be more than one correct answer):

The mutator for this member will be an instance method.
The mutator for this member will be a static method.

If the mutator takes a string parameter, newDefault, a reasonable definition would be:

 if ( newDefault.length() > 0 ) return false; DEFAULT_DSCR = newDefault; return true; 

If the mutator takes a string parameter, newDefault, a reasonable definition would be:

 if ( newDefault.length() < 2 ) { this->newDefault = DEFAULT_DSCR; return false; } this->newDefault = newDefault; return true; 

If the mutator takes a string parameter, newDefault, a reasonable definition would be:

 if ( newDefault.length() < 2 ) return false; DEFAULT_DSCR = newDefault; return true; 

question 22.

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

2
3
4

none

question 23.

Consider a binary search algorithm as described in the modules. Assume that the array to be searched is pre-sorted, so that sort is not part of the search algorithm.

Searching an array using a binary search (check all choices that apply):

... is usually slower for each search than a simple linear search.
... requires a pre-sorted array in order to work.
... is usually faster for each search than a simple linear search.
... requires more code and logic than a simple linear search.
... does a sort as part of the search algorithm.

question 24.

A static class method might take one or more objects of its class as parameters -- or it might take none -- depending on the purpose of the method.

True
False

question 25.

Which are true about instance variables of a class (check all that apply):

They should usually be declared private.
Mutators should protect them by filtering bad parameter values before assigning those values to them.
Loop counters and other helper variables should be declared as instance variables so that such counters and helpers don't have to be re-declared local to every member method, individually.
Member instance methods of the same class must use mutator methods to modify their values.
Member instance methods of the same class must use this-> before their names in order to access them.

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!