#include #include #include #include "Rational.h" using namespace std; // This program takes a maximum size digit to generate and a // number of trials to run. For each trial, it generates two Rational #s // and then runs all of the operations on them. Checking of the // results is currently not done, so you'll have to eyeball them // or write them yourself. int main(int argc, char* argv[]) { srand(time(0)); if (argc < 2) { cerr << "Usage: " << argv[0] << " max_int num_trials "; exit(1); } int max_digits = atoi(argv[1]); int num_trials = atoi(argv[2]); for (int i = 0; i < num_trials; i++) { int xnum = rand() % max_digits; int xden = rand() % max_digits; int ynum = rand() % max_digits; int yden = rand() % max_digits; Rational x(xnum, xden), y(ynum, yden), res; // Change the print functions to whatever your // rational printing functions are named. x.printRational(); cout << " + "; y.printRational(); res = x.addition( y ); cout << " = "; res.printRational(); cout << endl; res.printRational(); cout << " = "; res.printRationalAsFloating(); cout << endl; x.printRational(); cout << " - "; y.printRational(); x = x.subtraction( y ); cout << " = "; x.printRational(); cout << '\n'; x.printRational(); cout << " = "; x.printRationalAsFloating(); cout << "\n\n"; x.printRational(); cout << " x "; y.printRational(); x = x.multiplication( y ); cout << " = "; x.printRational(); cout << '\n'; x.printRational(); cout << " = "; x.printRationalAsFloating(); cout << "\n\n"; x.printRational(); cout << " / "; y.printRational(); x = x.division( y ); cout << " = "; x.printRational(); cout << '\n'; x.printRational(); cout << " = "; x.printRationalAsFloating(); cout << endl; } return 0; }