Question: (Please use the template shown in green text in your answer) Given the following class class GiftBox { char* labelName; double cubeVolume; double weight; };

(Please use the template shown in green text in your answer)

Given the following class

class GiftBox {

char* labelName;

double cubeVolume;

double weight;

};

Answer the following questions:

  1. Create default no-argument constructor to set the cubeVolume and weight to 0's, and the labelName to empty string (start with null character '\0')
  2. Create three arguments constructor to set the cubeVolume and weight, and labelName to the given argument values. Validate first if the double values are positive and the label name is not nullptr and not empty string '\0' before using it, otherwise do nothing.)
  3. Define a destructor to deallocate the memory pointed by the labelName, and prints object of type GiftBox just destroyed
  4. Implement a function called display that takes ostream (std::ostream& display()const;) to display the information as shown in the sample output.
  5. Implement two member operators += double (adds the double value to the weight) and += object of same type (add the cubeSize and weight to the current one; no change for the label) (see sample outputs)
  6. Implement a helper operator << that uses display implemented in part 4.

class GiftBox {

char* labelName;

double cubeVolume;

double weight;

// add all declarations that can be added here

//(the fifth one is provided to you)

void display(std::ostream os);

};

// implement your functions here

int main(){

GiftBox g1, g2(4000.8,200.2,"Sweet Box"), g3(2000,100.2,"Box!"),;

cout << g1;

cout <

g2+=100;

cout <

g2+=g3;

cout <

}

Output:

No data is available in this object.

Sweet Box

----------

cubeVolume=4000.8Cm3 and weight=300.2Grm

Sweet Box

----------

cubeVolume=4000.8Cm3 and weight=400.2Grm

Sweet Box

----------

cubeVolume=6000.8Cm3 and weight=500.4Grm

object of type GiftBox just destroyed

object of type GiftBox just destroyed

object of type GiftBox just destroyed

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!