반응형
https://www.hackerrank.com/challenges/box-it/problem
class Box{
// The class should have the following functions :
private:
int l;
int b;
int h;
public:
// Constructors:
Box()
{
l=0;
b=0;
h=0;
}
Box(int length,int breadth,int height)
{
l=length;
b=breadth;
h=height;
}
Box(const Box &ref)
{
l=ref.l;
b=ref.b;
h=ref.h;
}
int getLength()
{
return this->l;
} // Return box's length
int getBreadth ()
{
return b;
} // Return box's breadth
int getHeight ()
{
return h;
} //Return box's height
long long CalculateVolume()
{
return (long long)l*b*h;
}// Return the volume of the box
//Overload operator < as specified
bool operator<(const Box& b)
{
return((this->l<b.l)||
((this->b<b.b)&&(this->l==b.l))||
((this->h<b.h)&&(this->b==b.b)&&(this->l==b.l)));
}
//Overload operator << as specified
friend ostream& operator<<(ostream& out, Box& B)
{
out<<B.getLength()<<" "<<B.getBreadth()<<" "<<B.getHeight();
return out;
}
};
반응형
'C++' 카테고리의 다른 글
[HackerRank] Exceptional Server - Easy (0) | 2019.10.25 |
---|---|
[HackerRank] Inherited Code - Easy (0) | 2019.10.25 |
[HackerRank] Classes and Objects - Easy (0) | 2019.10.16 |
[HackerRank] Strings - Easy (0) | 2019.10.14 |
[HackerRank] StringStream - Easy (0) | 2019.10.14 |
댓글