// Interface file for FRACTION class -- fraction.h #ifndef FRACTION_H #define FRACTION_H #include using namespace std; class fraction { public: // constructors fraction(); // default constructor -- results in 0/1 fraction(int num); // one parameter -- results in num/1 // this is a conversion constructor fraction(int num, int den);// two parameters -- results in num/den // the above three could be replaced with the single constructor // fraction(int num = 0, den = 1); // which uses default values // input and output methods void read(istream& iStr); // input must be one of the following forms : // 1. integer // 2. integer/integer // Note: no spaces allowed in the fraction void print(ostream& oStr) const; void printMixed(ostream& oStr) const; // print as a mixed number if the // fraction is improper // accessor methods int num() const; // returns the numerator int den() const; // returns the denominator // arithmetic methods fraction add(const fraction& frac) const; // fraction + fraction fraction sub(const fraction& frac) const; // fraction - fraction fraction mult(const fraction& frac) const; // fraction * fraction fraction div(const fraction& frac) const; // fraction / fraction fraction reciprocal() const; // the reciprocal // comparison methods bool sameAs(const fraction& frac) const; // equality bool isLessThan(const fraction& frac) const;// less than private: // Data members int numer; int denom; // Function member void reduce(); // reduces to lowest terms with denom > 0 }; #endif