Question: #include #include usingnamespacestd; constintNT =10; constintNC =2; classChocolate { chartype[NT +1]; public: Chocolate(constchar* t =nullptr) { if(t) { strncpy(type, t, NT); type[NT] ='0'; } else{

#include

#include

usingnamespacestd;

constintNT =10;

constintNC =2;

classChocolate {

chartype[NT +1];

public:

Chocolate(constchar* t =nullptr) {

if(t) {

strncpy(type, t, NT);

type[NT] ='\0';

}

else{

type[0] ='\0';

}

cout <<"C";

}

~Chocolate() {

cout <<"~"<< type << endl;

}

voiddisplay()const{

cout << type << endl;

}

};

classBox {

Chocolate ch[NC];

intnc;

public:

Box() {

nc =0;

cout <<"B";

}

Box&operator+=(constChocolate& c) {

if(nc < NC) {

ch[nc] = c;

cout <<"+";

ch[nc++].display();

}

return*this;

}

Box(constBox& b) {

nc = b.nc;

for(inti =0; i < nc; i++)

ch[i] = b.ch[i];

cout <<"E"<< endl;

}

~Box() {

cout <<"~B"<< endl;

}

voiddisplay()const{

for(inti =0; i < nc; i++)

ch[i].display();

cout << endl;

}

};

voidshow(constBox b) {

b.display();

}

intmain() {

cout <<"=Chocolate="<< endl;

Chocolate cherry("cherry");

Chocolate orange("orange");

cout <<" =Box="<< endl;

Box b;

cout <<" =++="<< endl;

b += orange;

b += cherry;

cout <<" =show="<< endl;

show(b);

cout <<" =done="<< endl;

return0;

}

1- Explain what the operatorBox& operator+=(const Chocolate& c) does.

2- How can you improve the performance the show() function in this program.

Explain the effect of your upgrade in one or two sentences.

3- Explain in one or two sentences the meaning of the keyword const in the display( )

function.

4- Describe in one or two sentences the effect of removing the default parameter

value in the definition of the Chocolate( ) constructor.

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 Programming Questions!