This is a design for a class named Box whose dimensions are integers and private
ID: 3736619 • Letter: T
Question
This is a design for a class named Box whose dimensions are integers and private to the class. The dimensions are labeled: length I, breadth b, and height h The default constructor of the class should initialize I, b, and h to 0. The parameterized constructor Box(int length, int breadth, int height) should initialize Box's l,b and h to length, breadth and height The copy constructor Box(Box B) should set l.b and h to B's I.b and h, respectively Every constructor should increment the global variable BoxesCreated. The destructor should increment the global variable BoxesDestroyed. Apart from the constructor and destructor, the class should have 4 functions: int getLength)- Return box's length int getBreadth Return box's breadth int getHeight0 Return box's height long long CalculateVolume) Return the volume of the box Overload the operator 'for the class Box. "Box A Box B" if Overload operatorExplanation / Answer
box.h
Below is the header file with function prototypes for the box class as per the documentation.
#include <iostream>
using namespace std;
int boxesCreated; //global variable that is incremented in constructor
int boxesDestroyed; //global variable that is decremented in destructor
class Box
{
private:
int l; //variable to hold length of box
int b; //variable to hold breadth of box
int h; //variable to hold height of box
public:
Box(); //default constructor
Box(int length, int breadth, int height); //parameterized constructor
Box(const Box& anotherBox); //Copy constructor
~Box(); //destructor
int getLength(); //function to return the length of box
int getBreadth(); //function to return the breadth of box
int getHeight(); //function to return the height of box
long long calculateVolume(); // function to return the calculated volume of the box
friend std::ostream& operator<<(std::ostream& s, const Box& b); // operator "<<" overloaded function
bool operator < (const Box& anotherBox) const; // operator "<" overloaded function
};
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.