// --------------------------------- // fractest.cpp fractions // --------------------------------- #include "w.h" #include "frac.h" #include "frac.cpp" // global Max function for fractions frac Max(frac f, frac g) { return (f > g ? f : g); } // ----------------------------------------------------- void main() { nl(0); banner("fractest.cpp"); frac a,b(1),c(4,6); p("a = "); pl(a); p("b = "); pl(b); p("c = "); pl(c); p("num(c) = ", num(c)); pl(" dnum(c) = ", dnum(c)); p("eval(c) = ");pleval(c); a = c; // try it p("a = c, a = "); pl(a); p("b = "); r(b); nl(); p("r(b) = "); pl(b); frac d = a + b; p("a + b = "); p(a); p(" + "); p(b); p(" = "); pl(d); a = b = c = d; p("a = b = c = d = "); pl(a); frac g(22,99); p("g = 22/99 = "); pl(g); p("g*a = ");pl(g*a); p("g/a = ");pl(g/a); frac f1(4,5),f2(41,51); p("f1 = "); p(f1); p(" f2 = "); pl(f2); p("Max(f1,f2) = "); pl(Max(f1,f2)); } /* output -------------- fractest.cpp -------------- a = 0 b = 1 c = 2/3 num(c) = 2 dnum(c) = 3 eval(c) = 0.666667 a = c, a = 2/3 b = 21/28 r(b) = 3/4 a + b = 2/3 + 3/4 = 17/12 a = b = c = d = 17/12 g = 22/99 = 2/9 g*a = 17/54 g/a = 8/51 f1 = 4/5 f2 = 41/51 Max(f1,f2) = 41/51 */