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, 23.06.2019 20:30
If chris has a car liability insurance, what damage would he be covered for
Answers: 1
question
Computers and Technology, 24.06.2019 00:40
To maintain clarity and focus lighting might be needed
Answers: 2
question
Computers and Technology, 24.06.2019 20:00
Write c++programs for the following problem: let the user enter two numbers and display which is greater. !
Answers: 1
question
Computers and Technology, 25.06.2019 04:30
Which relativos possible when two tables share the same primary key? a.) one-to-one b.) one-to-many c.) many-to-one d.) many-to-many
Answers: 2
You know the right answer?
Consider the class as partially defined here: //class PizzaOrder
class PizzaOrder
{
Questions
question
Business, 23.02.2021 21:10
question
English, 23.02.2021 21:10
question
Mathematics, 23.02.2021 21:10
question
Mathematics, 23.02.2021 21:10
Questions on the website: 13722363