Skip to content

Instantly share code, notes, and snippets.

@arnaudoff
Created April 19, 2018 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arnaudoff/56bd798a2facc115b6f51c5dbb1431c3 to your computer and use it in GitHub Desktop.
Save arnaudoff/56bd798a2facc115b6f51c5dbb1431c3 to your computer and use it in GitHub Desktop.
//Implement the class Box
//l,b,h are integers representing the dimensions of the box
// The class should have the following functions :
// Constructors:
// Box();
// Box(int,int,int);
// Box(Box);
// int getLength(); // Return box's length
// int getBreadth (); // Return box's breadth
// int getHeight (); //Return box's height
// long long CalculateVolume(); // Return the volume of the box
//Overload operator < as specified
//bool operator<(Box& b)
//Overload operator << as specified
//ostream& operator<<(ostream& out, Box& B)
class Box{
private:
long long l;
long long b;
long long h;
public:
Box() : l(0), b(0), h(0) {};
Box(int length, int breadth, int height) : l(length), b(breadth), h(height) {};
Box(const Box & A)
{
this->l = A.l;
this->h = A.h;
this->b = A.b;
}
int getLength() {return l;}
int getBreadth() {return b;}
int getHeight() {return h;}
long long CalculateVolume() { return l*b*h;}
bool operator < (const Box & A)
{
if (this->l < A.l)
{
return true;
}
else if (this->l == A.l)
{
if (this->b < A.b)
{
return true;
}
else if (this->b == A.b)
{
if (this->h < A.h)
{
return true;
}
return false;
}
return false;
}
return false;
}
};
ostream & operator<<(ostream& out, Box& B)
{
return out<<B.getLength()<<" "<<B.getBreadth()<<" "<<B.getHeight();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment