Server IP : 172.16.15.8 / Your IP : 18.219.15.112 Web Server : Apache System : Linux zeus.vwu.edu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 UTC 2024 x86_64 User : apache ( 48) PHP Version : 7.2.24 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0705) : /home/bafreeman/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
#include <iostream> using namespace std; class Fraction { int nume, deno; public: Fraction() { nume = 0; deno = 1; } Fraction(int n, int d) { nume = n; deno = d; } void Set(int n, int d) { nume = n; deno = d; } void Print() const { cout << nume << '/' << deno; } Fraction Mult(Fraction f) { Fraction t; int n, d; n = nume*f.nume; d = deno*f.deno; t.Set(n,d); return t; } }; int main() { Fraction x; Fraction y; Fraction z; int n; int d; char dummy, op; cout << "Input x (n/d or -1/1 to quit): "; while (n!=-1 && d!=1) { cin >> n >> dummy >> d; // Set x = n/d? x.Set(n,d); cout << "Input y (n/d): "; cin >> n >> dummy >> d; // Set y = n/d? y.Set(n,d); cout << "Operation? (+, -, /, *): "; cin >> op; if (op == '*') z = x.Mult(y); else cout << "I'm working on."; // Debug cout << "x= "; x.Print(); cout << "\n"; cout << "y= "; y.Print(); cout << "\n"; cout << "z= "; z.Print(); cout << "Input x (n/d or -1/1 to quit): "; cin >> n >> dummy >> d; } cout << "\nDone.\n\n"; return 0; }