Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Fraction {
- int uppernum;
- int lowernum;
- public:
- Fraction(int m_uppernum, int m_lowernum) {
- this->uppernum = uppernum;
- this->lowernum = lowernum;
- }
- void showdata() {
- cout << uppernum << "/" << lowernum << endl;
- }
- friend Fraction operator*(Fraction& f1, Fraction& f2);
- friend Fraction operator/(Fraction& f1, Fraction& f2);
- friend Fraction operator*(Fraction& f1, int a);
- friend Fraction operator*(int a,Fraction& f1);
- friend Fraction operator/(Fraction& f1, int a);
- friend Fraction operator/(int a, Fraction& f1);
- };
- Fraction operator*(Fraction& f1, Fraction& f2)
- {
- return Fraction(f1.uppernum * f2.uppernum, f1.lowernum * f2.lowernum);
- }
- Fraction operator/(Fraction& f1, Fraction& f2) {
- return Fraction(f1.uppernum * f2.lowernum, f1.lowernum * f2.uppernum);
- }
- Fraction operator*(Fraction& f1, int a)
- {
- return Fraction(f1.uppernum * a, f1.lowernum * 1);
- }
- Fraction operator*(int a, Fraction& f1) {
- return Fraction(f1.uppernum * a, f1.lowernum * 1);
- }
- Fraction operator/(Fraction& f1, int a) {
- return Fraction(f1.uppernum * 1, f1.lowernum * a);
- }
- Fraction operator/(int a, Fraction& f1) {
- return Fraction(f1.lowernum * 1, f1.uppernum * a);
- }
- int main()
- {
- setlocale(LC_ALL, "rus");
- Fraction f1(1, 2);
- Fraction f2(1, 4);
- Fraction f3 = f1 * 4;
- Fraction f4 = 4 * f1;
- Fraction f5 = f1 / f2;
- Fraction f6 = f1 / 2;
- Fraction f7 = 2 / f1;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement