#include using namespace std; void multiply(int atop, int abot, int btop, int bbot, int & rtop, int & rbot) { rtop = atop * btop; rbot = abot * bbot; } void divide(int atop, int abot, int btop, int bbot, int & rtop, int & rbot) { rtop = atop * bbot; rbot = abot * btop; } void add(int atop, int abot, int btop, int bbot, int & rtop, int & rbot) { rtop = atop * bbot + btop * abot; rbot = abot * bbot; } void subtract(int atop, int abot, int btop, int bbot, int & rtop, int & rbot) { rtop = atop * bbot - btop * abot; rbot = abot * bbot; } void test(int atop, int abot, int btop, int bbot) { int ctop, cbot; add(atop, abot, btop, bbot, ctop, cbot); cout << atop << "/" << abot << " + " << btop << "/" << bbot << " = " << ctop << "/" << cbot << "\n"; subtract(atop, abot, btop, bbot, ctop, cbot); cout << atop << "/" << abot << " - " << btop << "/" << bbot << " = " << ctop << "/" << cbot << "\n"; multiply(atop, abot, btop, bbot, ctop, cbot); cout << atop << "/" << abot << " * " << btop << "/" << bbot << " = " << ctop << "/" << cbot << "\n"; divide(atop, abot, btop, bbot, ctop, cbot); cout << atop << "/" << abot << " / " << btop << "/" << bbot << " = " << ctop << "/" << cbot << "\n"; } void ask(string prompt, int & top, int & bot) { cout << prompt << ", top then bottom: "; cin >> top >> bot; } int main() { while (true) { int xtop, xbot, ytop, ybot; ask("X", xtop, xbot); ask("Y", ytop, ybot); test(xtop, xbot, ytop, ybot); } }