This library supports the calculation of a fraction
NOTE: Fraction supports from C++20
to latest
The fraction class is overloaded with the following operators
- Move/Copy-assignment operator
- Input/Output operators
- Comparison operators (
==
,!=
,>
,<
,>=
,<=
) - Binary arithmetic operators (
+
,-
,*
,/
,+=
,-=
,*=
,/=
)
It can perform calculations with other Fractions/Integers
Open terminal with Visual Studio Code and run the command line below
mingw32-make run
#include "fraction.hpp"
int main() {
Fraction result, first(12, 9), second(2, 7), third(3, 4);
result = first + second + 2;
result *= 3;
result -= 4 / third;
std::cout << result;
return 0;
}
#include "fraction.hpp"
int main() {
Fraction first(42, 9), second(2, 23);
std::cout << (first == second ? "equal" : "not equal") << std::endl;
std::cout << (second < 1 ? "less than" : "not less than") << std::endl;
std::cout << (5 > first ? "greater than" : "not greater than") << std::endl;
return 0;
}
#include "fraction.hpp"
int main() {
Fraction first(5, 2);
double number = 3.6;
number += static_cast<double>(first);
// Or: number += first.to_double();
std::cout << number;
return 0;
}