Created
April 19, 2018 10:06
-
-
Save arnaudoff/56bd798a2facc115b6f51c5dbb1431c3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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