#include <iostream>
#include <exception>
#include "Fraction.h"
int main() {
Fraction f1(1, 2);
Fraction f2(3, 5);
Fraction result1 = f1 * f2;
std::cout << f1 << " * " << f2 << " = " << result1 << std::endl;
int i1 = 7;
Fraction result2 = f1 * i1;
std::cout << f1 << " * " << i1 << " = " << result2 << std::endl;
int i2 = 2;
Fraction result3 = f2 / i2;
std::cout << f2 << " / " << i2 << " = " << result3 << std::endl;
try {
int i3 = 0;
Fraction result4 = f2 / i3;
std::cout << f2 << " / " << i3 << " = " << result4 << std::endl;
}
catch(exception& e) {
std::cout << e.what() << std::endl;
// Writes "Error: Division by zero [3/5 / 0/1]"
}
Fraction result5 = f1 + f2;
std::cout << f1 << " + " << f2 << " = " << result5 << std::endl;
int i4 = 7;
Fraction result6 = f1 + i4;
std::cout << f1 << " + " << i4 << " = " << result6 << std::endl;
Fraction result7 = f1 - f2;
std::cout << f1 << " - " << f2 << " = " << result7 << std::endl;
int i5 = 11;
Fraction result8 = f1 - i5;
std::cout << f1 << " - " << i4 << " = " << result8 << std::endl;
Fraction result9 = -f1;
std::cout << "-" << f1 << " = " << result9 << std::endl;
return 0;
}
- Fraction(float) constructor
- Multiplication by Fraction
- Multiplication by int
- Division by Fracton
- Division by int
- Sum by Fraction
- Sum by int
- Mod by Fraction
- Mod by int
- Subtraction by Fraction
- Subtraction by int
- Negative
- Simplify fraction
- == with Fraction
- == with Integer
- != with Fraction
- != with Integer
- > with Fraction
- > with Integer
- < with Fraction
- < with Integer
- >= with Fraction
- >= with Integer
- <= with Fraction
- <= with Integer
- Inverse of operators (integer + Fraction <=> Fraction + integer)
- PI constant (http://turner.faculty.swau.edu/mathematics/materialslibrary/pi/pirat.html)
- MAX_VALUE constant
- MIN_VALUE constant
- Constant ZERO
- Constant ONE
- Change names from dividend/divisor to numerator/denominator