b); bool operator lt;=(const fraction amp; a, const fraction amp; b); bool operator gt;=(const fraction amp; a, const fraction amp; b); bool operator lt; (const fraction amp; a, const fraction amp; b); bool operator gt; (const fraction amp; a, const fraction amp; b);
}; :: ostream amp; operator lt; lt; (std :: ostream amp; os, const fraction amp; f);
# include fraction. h
# include lt; iostream gt; :: fraction (): num (0), den (1)
{= 0; den=1;
} :: fraction (int a, unsigned b): num (a)
{(b gt; 0) den=b;
{= 1; :: cerr lt; lt; error: wrong denominator n raquo ;;
} ();
} :: fraction (const fraction amp; f)
{= f. num; den=f. den;
} :: ~ fraction ()
{
} fraction :: show (std :: ostream amp; os) const
{ lt; lt; num lt; lt; / lt; lt; den;
} fraction :: add (const fraction amp; f) const
{a=this- gt; num * f. den + this- gt; den * f. num; b=this- gt; den * f. den; fraction (a, b). simplify ();
} fraction :: operator + (const fraction amp; f) const
{a=this- gt; num * f. den + this- gt; den * f. num; b=this- gt; den * f. den; fraction (a, b). simplify ();
} fraction :: operator=(const fraction amp; f) const
{fraction (f);
} fraction :: operator/(const fraction amp; f) const
{a=this- gt; num * f. den; b=this- gt; den * f. num; fraction (a, b). simplify ();
} fraction :: operator- (const fraction amp; f) const
{a=this- gt; num * f. den - this- gt; den * f. num; b=this- gt; den * f. den; fraction (a, b). simplify ();
} fraction :: operator * (const fraction amp; f) const
{a=this- gt; num * f. num; b=this- gt; den * f. den; fraction (a, b). simplify ();
} amp; fraction :: simplify ()
{a=this- gt; num; b=this- gt; den; (a!=b)
{(a gt; b) a -=b; b -=a;
} (a gt; 1)
{/=a; /=a;
} * this;
} :: ostream amp; operator lt; lt; (std :: ostream amp; os, const fraction amp; f)
{. show (os); os;
} operator == (const fraction amp; a, const fraction amp; b)
{(a. num == b. num amp; amp; a. den == b. den) return true; return false;
} operator! =(Const fraction amp; a, const fraction amp; b)
{! (a == b);
} operator lt; (const fraction amp; a, const fraction amp; b)
{a1=float (a. num)/a. den, b1=float (b. num)/b. den; (a1 lt; b1);
} operator gt; (const fraction amp; a, const fraction amp; b)
{a1=float (a. num)/a. den, b1=float (b. num)/b. den; (a1 gt; b1);
} operator gt;=(const fraction amp; a, const fraction amp; b)
{! (a lt; b);
} operator lt;=(const fraction amp; a, const fraction amp; b)
{! (a gt; b);
}
# include fraction. h
# include lt; iostream gt; makeDefaultFraction ()
{fraction ();
} retCopyFraction (fraction amp; t)
{t;
} main ()
{b (8,24); c (1,2); d=c; :: cout lt; lt; b: lt; lt; b lt; lt; n raquo ;; :: cout lt; lt; d: lt; lt; d lt; lt; n raquo ;; :: cout lt; lt; d lt; b: lt; lt; (d lt; b) lt; lt; n raquo ;; :: cout lt; lt; d gt; b: lt; lt; (d gt; b) lt; lt; n raquo ;; :: cout lt; lt; d == b: lt; lt; (d == b) lt; lt; n raquo ;; :: cout lt; lt; d! =b: lt; lt; (d!=b) lt; lt; n raquo ;; :: cout lt; lt; d lt;=b: lt; lt; (d lt;=b) lt; lt; n raquo ;; :: cout lt; lt; d gt;=b: lt; lt; (d gt;=b) lt; lt; n raquo ;; :: cout lt; lt; d + b: lt; lt; (d + b) lt; lt; n raquo ;; :: cout lt; lt; db: lt; lt; (db) lt; lt; n raquo ;; :: cout lt; lt; d * b: lt; lt; (d * b) lt; lt; n raquo ;; :: cout lt; lt; d/b: lt; lt; (d/b) lt; lt; n raquo ;; :: cin. get (); :: cin. get (); 0;
...