#include using namespace std; int gcd(int a, int b) { while (b != 0) { int t = a % b; a = b; b = t; } return a; } struct fraction { int top, bot; fraction(int t, int b) { top = t; bot = b; normalise(); } void normalise() { int g = gcd(top, bot); top /= g; bot /= g; } void print() { cout << top << "/" << bot; } }; fraction multiply(const fraction f, const fraction g) { return fraction(f.top * g.top, f.bot * g.bot); } fraction divide(const fraction f, const fraction g) { return fraction(f.top * g.bot, f.bot * g.top); } fraction add(const fraction f, const fraction g) { return fraction(f.top * g.bot + f.bot * g.top, f.bot * g.bot); } fraction subtract(const fraction f, const fraction g) { return fraction(f.top * g.bot - f.bot * g.top, f.bot * g.bot); } bool lessthan(const fraction f, const fraction g) { return f.top * g.bot < f.bot * g.top; } int main() { fraction half(1, 2); fraction quarter(1, 4); fraction seven_eighths(7, 8); fraction x = add(half, quarter); half.print(); cout << " + "; quarter.print(); cout << " = "; x.print(); cout << "\n"; x.print(); cout << " < "; seven_eighths.print(); cout << " = "; bool y = lessthan(x, seven_eighths); cout << (y ? "true" : "false") << "\n"; }