Computers and Technology

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?
A. bool PizzaOrder::addTopping( string topping )
{
numToppings++;
if ( numToppings >= MAX_TOPPINGS )
return false;
toppings[numToppings] = topping;
return true;
}
B. void PizzaOrder::addTopping( string topping )
{
toppings[numToppings] = topping;
}
C. bool PizzaOrder::addTopping( string topping )
{
if ( numToppings >= MAX_TOPPINGS || numToppings < 0 )
return false;
toppings[numToppings++] = topping;
return true;
}
D. void PizzaOrder::addTopping( string topping )
{
toppings[numToppings++] = topping;
}
E. bool PizzaOrder::addTopping( string topping )
{
if ( numToppings >= MAX_TOPPINGS )
return false;
toppings[numToppings++] = topping;
return true;
}
F. bool PizzaOrder::addTopping( string topping )
{
if (numToppings > MAX_TOPPINGS)
return false;
toppings[numToppings++] = topping;
return true;
}

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 09:00, jgrable5175
Designing a mobile web page is a little different from designing a regular web page. name at least three features that should be considered when designing a website that is mobile phone-friendly, and briefly explain why they are important.
Answers: 1
image
Computers and Technology, 23.06.2019 19:00, jaymc1932
Whose task it is to ensure that the product flows logically from one step to another?
Answers: 3
image
Computers and Technology, 23.06.2019 20:50, terryhgivens5349
3.11.3 quiz: comparing and analyzing function typesquestion 4 of 102 pointswhat can you say about the y-values of the two functions f(x) = 3x2-3 andg(x)=2* - 3?
Answers: 2
image
Computers and Technology, 24.06.2019 09:00, lisacarter0804
Why might you chose to crest a function resume
Answers: 1