class Distance
{
private:
int feet;
int inches;
public:
// Default constructor
Distance() {
feet = inches = 0;
}
// Parametrrized constructor
Distance(int f, int i) {
inches = i % 12;
feet = f + i / 12;
}
// Return data
int getFeet() {
return feet;
}
int getInches() {
return inches;
}
void show() {
std::cout << feet << " feet " << inches << " inches";
}
Distance& operator+=(Distance other) {
feet += other.feet;
inches += other.inches;
if (inches > 12) {
inches -= 12;
feet++;
}
return *this;
}
bool operator<(Distance other) {
if (feet< other.feet)
return true;
else if (feet == other.feet && inches < other.inches)
return true;
else
return false;
}
};
Comments
Leave a comment