Question: Question 36 If a programmer wants to store a character string into a variable defined by char streetName[80]; then the length of the string data

Question 36

If a programmer wants to store a character string into a variable defined by

 char streetName[80]; 

then the length of the string data stored in that variable at any point in time is (only one correct choice):

streetName.length() 
strlen( streetName ) 
sizeof( streetName ) 
strlen( user ) 
sizeof( streetName ) / sizeof( streetName[0] ) 

Question 37

Consider the class as partially defined here:

//class PizzaOrder ------------------------------------ class PizzaOrder { public: static const int MAX_TOPPINGS = 20; private: // instance members string toppings[MAX_TOPPINGS]; int numToppings; // constructor public PizzaOrder(); // accessor tells # toppings on pizza, i.e., # toppings in array int getNumToppings() { return numToppings; } // etc. } PizzaOrder::PizzaOrder() { numToppings = 0; } 

We want to write an instance method, addTopping() that will take a string parameter, topping, and add it to the toppings[] array at the next available location as determined by the int member numToppings. Assume any string passed in is valid and no other method modifies the toppings[] array or numToppings. The client would call it like so:

 somePizzaOrder.addTopping( "onions" ); 

Which is a correct definition for addTopping() based on what you see, above?

void PizzaOrder::addTopping( string topping ) { toppings[numToppings] = topping; } 
void PizzaOrder::addTopping( string topping ) { toppings[numToppings++] = topping; } 
bool PizzaOrder::addTopping( string topping ) { numToppings++; if ( numToppings >= MAX_TOPPINGS ) return false; toppings[numToppings] = topping; return true; } 
bool PizzaOrder::addTopping( string topping ) { if ( numToppings >= MAX_TOPPINGS || numToppings < 0 ) return false; toppings[numToppings++] = topping; return true; } 
bool PizzaOrder::addTopping( string topping ) { if ( numToppings >= MAX_TOPPINGS ) return false; toppings[numToppings++] = topping; return true; } 
bool PizzaOrder::addTopping( string topping ) { if (numToppings > MAX_TOPPINGS) return false; toppings[numToppings++] = topping; return true; } 

Question 38

A stack data structure, when implemented by a programmer as done in the modules as a LIFO data structure, has the following property (only one correct choice):

[Assume there are several items remaining in the stack when considering these options.]

It allows the client to pop() the most recently push()ed item (the newest item in the stack).
It allows the client to pop() the earliest, i.e., first, push()ed item (the oldest item in the stack).
It allows the client to pop() any item off the stack, based on the parameter the client passes to pop().

Question 39

When an object is passed as a (i.e. non-reference or pointer) parameter to a method, modifying the members of that object from inside the method will result in a change to that object as seen from the client.

True
False

Question 40

Consider this method definition:

 int someRecMethod( int n ) { if ( n < 0 ) return -1; return someRecMethod( n + 1 ); } 

This method has the following problem -- or none (only one correct choice):

It will always produce a runaway recursive call to itself resulting in a run-time error.
It will always return the same number no matter what is passed in as an argument from the client.
Nothing is wrong; it has both an explicit case and a recursive case.
It will sometimes return a -1 without error, and other times produce a runaway recursive call to itself resulting in a run-time error.

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!