{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

rational.cc

# rational.cc - return*this Rational Rational:add(const...

This preview shows pages 1–2. Sign up to view the full content.

//#include <iostream> #include "rational.h" //using namespace std; //default constr Rational::Rational() { cout << "default constr" << endl; num = 0; dem = 1; // int b[5]; Rational* r = new Rational(5, 3); (*r).num; r->num; int* a = new int[5]; a[0] = 1; *a = 1; a[1] = 2; *(a + 1) = 2; //*(a + 10) = 2; //a[10] = 2; delete r; delete [] a; } // Destructor Rational::~Rational() { delete r; delete []a; } // Parm constr Rational::Rational(int n, int d) { cout << "parm constr" << endl; (*this).num = n; this->dem = d; } // copy constr Rational::Rational(const Rational& rhs) { cout << "copy constr" << endl; num = rhs.num; dem = rhs.dem; } // Overloaded Assignment Rational& Rational::operator=(const Rational& rhs) { cout << "assignment" << endl; num = rhs.num;

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
dem = rhs.dem;
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: return *this; } Rational Rational::add(const Rational& r) { int n = (num * r.dem) + (r.num * dem); int d = (dem * r.dem); Rational result(n, d); return result; } Rational Rational::operator+(const Rational& r) { int n = (num * r.dem) + (r.num * dem); int d = (dem * r.dem); Rational result(n, d); return result; } /* Rational operator+(const Rational& lhs, const Rational& rhs) { int n = (lhs.num * rhs.dem) + (rhs.num * lhs.dem); int d = (lhs.dem * rhs.dem); Rational result(n, d); return result; } */ ostream& operator<<(ostream& os, const Rational& r) { r.display(os); return os; } void Rational::display(ostream& os) const { os << num << "/" << dem << endl; }...
View Full Document

{[ snackBarMessage ]}