Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
personally designed "class format snippet"
//C++ class example
#include <iostream>
#include <string>
class Box {
private:
int l;
int b;
long long int h;
public:
Box() : l(0), b(0), h(0) {}
Box(int _l, int _b, int _h) {
l = _l; b = _b; h = _h;
}
Box(class Box& B) { l = B.l; b = B.b; h = B.h; }
int getLength() const { return this->l; }
int getBreadth() const { return this->b; }
int getHeight() const { return this->h; }
long long CalculateVolume() { return (this->l * this->b * this->h); }
bool operator<(const Box& B) {
if (this->l < B.l)
return true;
else if (this->b < B.b && this->l == B.l)
return true;
else if (this->h < B.h && this->b == B.b && this->l == B.l)
return true;
return false;
}
};
std::ostream& operator<<(std::ostream& cout, const Box& B) {
std::cout << B.getLength() << " " << B.getBreadth() << " " << B.getHeight();
return cout;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.