Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions

Question

What steps are commonly used by unions to organize a workplace?

Answered: 1 week ago