/* * FeetInches.cpp * * Created on: Mar 28, 2019 * Author: johnsontimoj */ #include "FeetInches.h" FeetInches::FeetInches() { setFeetInches(0, 0); } FeetInches::FeetInches(int f, int i){ setFeetInches(f, i); fixFeetInches(); } void FeetInches::setFeet(int f){ feet = f; return; } void FeetInches::setInches(int i){ inches = i; fixFeetInches(); return; } int FeetInches::getFeet(void) const{ return feet; } int FeetInches::getInches(void) const{ return inches; } void FeetInches::setFeetInches(int f, int i){ setFeet(f); setInches(i); fixFeetInches(); return; } void FeetInches::setFeetInches(int f){ setFeet(f); return; } int FeetInches::calcInches(void) const{ return ((feet*12) + inches); } double FeetInches::calcFeet(void){ return (feet + inches/12.0); } FeetInches & FeetInches::operator=(const FeetInches & rhs){ if(&rhs != this){ this->setFeetInches(rhs.getFeet(), rhs.getInches()); } return *this; } FeetInches FeetInches::operator+(const FeetInches & rhs){ FeetInches tmp; tmp.setFeet((this->getFeet() + rhs.getFeet())); tmp.setInches((this->getInches() + rhs.getInches())); fixFeetInches(); return tmp; } FeetInches FeetInches::operator-(const FeetInches & rhs){ FeetInches tmp; tmp.setFeet((this->getFeet() - rhs.getFeet())); tmp.setInches((this->getInches() - rhs.getInches())); fixFeetInches(); return tmp; } bool FeetInches::operator==(const FeetInches & rhs){ if(this->calcInches() == rhs.calcInches()) return true; else return false; } bool FeetInches::operator!=(const FeetInches & rhs){ if(this->calcInches() == rhs.calcInches()) return false; else return true; } bool FeetInches::operator<(const FeetInches & rhs){ if(this->calcInches() < rhs.calcInches()) return true; else return false; } bool FeetInches::operator>(const FeetInches & rhs){ if(this->calcInches() > rhs.calcInches()) return true; else return false; } void FeetInches::fixFeetInches(void){ if(inches > 12){ feet += inches / 12; inches = inches % 12; } return; }