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:
- 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')
- 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.)
- Define a destructor to deallocate the memory pointed by the labelName, and prints object of type GiftBox just destroyed
- Implement a function called display that takes ostream (std::ostream& display()const;) to display the information as shown in the sample output.
- 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)
- 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started