We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
classBox{//for people who are learningprivate:intl;intb;inth;public://Getter functions for Box object attributesintgetLength()const{//const shows it does not modify objectreturnl;}intgetBreadth()const{returnb;}intgetHeight()const{returnh;}//volume calculationlonglongCalculateVolume()const{/*We use the static_cast method to prevent overflow,just in case the volume exceeds the interger range.Note we dont place l * b * h inside the static_cast parametersas that causes the multiplication to take place first.*/returnstatic_cast<longlong>(l)*b*h;}// Constructors - Topic overloading constructors with differerent parametersBox(intlength,intbreadth,intheight):l(length),b(breadth),h(height){}Box(Box&X):l(X.l),b(X.b),h(X.h){}Box():l(0),b(0),h(0){}// overloading the '<' operatorbooloperator<(constBox&other)const{//again const shows we are not modifying either objif(l<other.l)returntrue;if(l==other.l&&b<other.b)returntrue;if(l==other.l&&b==other.b&&h<other.h)returntrue;returnfalse;}//Declare friend function for opp<< that exists outside the class.friendostream&operator<<(ostream&out,constBox&B);};// The friend we refered to in the classostream&operator<<(ostream&out,constBox&B){//its our friend so it can see our privates :pout<<B.l<<' '<<B.b<<' '<<B.h;returnout;}
For those who is wondering why test case 3 is not getting passed. Just try to cast volume to long long
use the long datatype instead of int for lenght, breadth and height if some test case fails