subject

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;
}

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 12:40
The most complicated four letter word
Answers: 1
question
Computers and Technology, 24.06.2019 18:20
The following if statement contains a logic error, not a syntax error. rewrite it so that it is correct. assume the variable age already exists and holds a valid number. if (age == 18 & & age == 19) {
Answers: 1
question
Computers and Technology, 24.06.2019 22:00
True or false technology is often discovered by accident
Answers: 2
question
Computers and Technology, 25.06.2019 04:40
Ineed ! i need a computer whiz to me complete my study guide on computers, it's 50 questions. if anyone can me i'll be greatly appreciated.
Answers: 1
You know the right answer?
Consider the class as partially defined here: //class PizzaOrder
class PizzaOrder
{
Questions
question
Social Studies, 20.11.2020 01:00
question
Mathematics, 20.11.2020 01:00
question
Mathematics, 20.11.2020 01:00
question
Mathematics, 20.11.2020 01:00
question
Mathematics, 20.11.2020 01:00