Skip to content

Instantly share code, notes, and snippets.

@tannerkrewson
Last active December 12, 2017 02:52
Show Gist options
  • Save tannerkrewson/2784deab60961878ca420e37f397ec85 to your computer and use it in GitHub Desktop.
Save tannerkrewson/2784deab60961878ca420e37f397ec85 to your computer and use it in GitHub Desktop.
rational class runner/tester
#include <iostream>
#include "rational.h"
using namespace std;
int main() {
Rational a( -1, 2 ), b( 250, 500 ), c(-123, -456), d(456,123), e(28, 7), f(369,123);
Rational out1 = b+a+c*d+f*e+b/a-c;
cout << "1783/152 should be printed => " << out1 << endl;
Rational out2 = ( ( Rational(12) ^ 3 ) - ( Rational(1, 116) ^ -1 ) ) * Rational(1, -1);
cout << "-1612/1 should be printed => " << out2 << "\n\n";
Rational test, test2(100);
cout << "Default constructor => " << test << endl;
cout << "test(100) => " << test2 << "\n\n";
cout << "Enter 2 fractions and imma do all the operations on 'em: " << endl;
cin >> a >> b;
cout << "You entered " << a << " and " << b << "\n\n";
cout << a << " + " << b << " = " << a + b << endl;
cout << a << " - " << b << " = " << a - b << endl;
cout << a << " * " << b << " = " << a * b << endl;
cout << a << " / " << b << " = " << a / b << endl;
cout << a << " ^ -3" << " = " << (a ^ -3) << endl;
cout << a << " ^ -1" << " = " << (a ^ -1) << endl;
cout << a << " ^ 0" << " = " << (a ^ 0) << endl;
cout << a << " ^ 3" << " = " << (a ^ 3) << endl;
Rational zero(0);
cout << "NOW FAIL GRACEFULLY." << endl;
// Uncomment the one you want to try
// Zero Denominator
//Rational wow(-123, 0);
// Divide by Zero
//(Rational(-4) / zero).output();
// Zero to the Zero
//(zero ^ 0).output();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment