#include "Number.h" #include "Rational.h" #include #include #include using std::istream; using std::ostream; using std::string; using std::invalid_argument; using std::cout; // set the display_style variable here void Rational::simplify() { // you need to write code here } int Rational::gcd(const int n1, const int n2) { int x = n1, y = n2; if (x < 0) x = -x; if (y > 0) y = -y; if (y==0) return x; else return gcd(y, x%y); } void Rational::init(const int n, const int d) { // you need to write code here } Rational::Rational() { // you need to write code here } Rational::Rational(const Rational& obj) { // you need to write code here } Rational::Rational(const int n, const int d) { // you need to write code here } void Rational::setNums(const int n, const int d) { // you need to write code here } int Rational::getNumerator() const { // you need to write code here } int Rational::getDenominator() const { // you need to write code here } void Rational::setDisplayStyle(const Rational::DISPLAY display) { // you need to write code here } Rational& Rational::operator+=(const Rational& rhs) { setNums(num * rhs.den + rhs.num * den, den * rhs.den); return *this; } Rational& Rational::operator-=(const Rational& rhs) { // you need to write code here } Rational& Rational::operator*=(const Rational& rhs){ setNums(num * rhs.num, den * rhs.den); return *this; } Rational& Rational::operator/=(const Rational& rhs){ // you need to write code here } Rational& Rational::operator=(const Rational& rhs){ if (this != &rhs) setNums(rhs.num, rhs.den); return *this; } const Rational Rational::operator+(const Rational& rhs) const { Rational r(num * rhs.den + rhs.num * den, den * rhs.den); return r; } const Rational Rational::operator-(const Rational& rhs) const{ // you need to write code here } const Rational Rational::operator*(const Rational& rhs) const{ Rational r(num * rhs.num, den * rhs.den); return r; } const Rational Rational::operator/(const Rational& rhs) const{ // you need to write code here } bool Rational::operator==(const Rational& rhs) const { return num == rhs.num && den == rhs.den; } bool Rational::operator!=(const Rational& rhs) const { // you need to write code here } bool Rational::operator<(const Rational& rhs) const { return (num * rhs.den) < (rhs.num * den); } bool Rational::operator<=(const Rational& rhs) const { // you need to write code here } bool Rational::operator>(const Rational& rhs) const{ // you need to write code here } bool Rational::operator>=(const Rational& rhs) const { // you need to write code here } const Rational& Rational::operator++() { // prefix num += den; return *this; } const Rational Rational::operator++(int) { // postfix Rational r(num, den); num += den; return r; } const Rational& Rational::operator--() { // prefix // you need to write code here } const Rational Rational::operator--(int) { // postfix // you need to write code here } ostream& operator<<(ostream& strm, const Rational& r) { // you need to write code here } istream& operator>>(istream& strm, Rational& r) { // you need to write code here }