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

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

View Full Document Right Arrow Icon
//#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 cout << "copy constr" << endl; num = rhs.num; dem = rhs.dem; } // Overloaded Assignment cout << "assignment" << endl; num = rhs.num;
Background image of page 1

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

View Full DocumentRight Arrow Icon
dem = rhs.dem;
Background image of page 2
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&amp; 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&amp; r) { int n = (num * r.dem) + (r.num * dem); int d = (dem * r.dem); Rational result(n, d); return result; } /* Rational operator+(const Rational&amp; lhs, const Rational&amp; rhs) { int n = (lhs.num * rhs.dem) + (rhs.num * lhs.dem); int d = (lhs.dem * rhs.dem); Rational result(n, d); return result; } */ ostream&amp; operator&lt;&lt;(ostream&amp; os, const Rational&amp; r) { r.display(os); return os; } void Rational::display(ostream&amp; os) const { os &lt;&lt; num &lt;&lt; &quot;/&quot; &lt;&lt; dem &lt;&lt; endl; }...
View Full Document

This note was uploaded on 04/19/2008 for the course CS 265 taught by Professor Daniele.stevenson during the Spring '08 term at Wisc Eau Claire.

Page1 / 2

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

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online