Server IP : 172.16.15.8 / Your IP : 3.145.161.194 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 (0755) : /home/kmmowery/cs212/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
#include <iostream> using namespace std; class Fraction // num/den { int num, den; public: // constructors Fraction() { num=0; den=1; } Fraction(int n, int d) { num=n; den=d; } // transf. void Set(int n, int d) { num=n; den=d; } // observer Fraction operator* (Fraction other) // overloading '*' { Fraction temp; temp.num = num * other.num; temp.den = den * other.den; return temp; } Fraction operator+ (Fraction o) { Fraction t; t.num = num*o.den + den*o.num; t.den = den * o.den; return t; } void Print() const { cout << num << "/" << den; } }; int main() { Fraction x, y, z, ans; // 0/1 ans = x + y * z; ans.Print(); cout << "\n\nDone.\n\n"; return 0; }