//: C12:IntegerTest.cpp // From Thinking in C++, 2nd Edition // Available at http://www.BruceEckel.com // (c) Bruce Eckel 2000 // Copyright notice in Copyright.txt //{L} Integer #include "Integer.h" #include using namespace std; ofstream out("IntegerTest.out"); void h(Integer& c1, Integer& c2) { // A complex expression: c1 += c1 * c2 + c2 % c1; #define TRY(OP) \ out << "c1 = "; c1.print(out); \ out << ", c2 = "; c2.print(out); \ out << "; c1 " #OP " c2 produces "; \ (c1 OP c2).print(out); \ out << endl; TRY(+) TRY(-) TRY(*) TRY(/) TRY(%) TRY(^) TRY(&) TRY(|) TRY(<<) TRY(>>) TRY(+=) TRY(-=) TRY(*=) TRY(/=) TRY(%=) TRY(^=) TRY(&=) TRY(|=) TRY(>>=) TRY(<<=) // Conditionals: #define TRYC(OP) \ out << "c1 = "; c1.print(out); \ out << ", c2 = "; c2.print(out); \ out << "; c1 " #OP " c2 produces "; \ out << (c1 OP c2); \ out << endl; TRYC(<) TRYC(>) TRYC(==) TRYC(!=) TRYC(<=) TRYC(>=) TRYC(&&) TRYC(||) } int main() { cout << "friend functions" << endl; Integer c1(47), c2(9); h(c1, c2); } ///:~