Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 18.119.122.69
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/cchansen/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : //home/cchansen/fraction2.txt
Script started on Sat 21 Mar 2009 05:26:51 PM EST
[cchansen@zeus cchansen]$ script fraction2.txt./frac2.out < inp2.txtless fract0ut.txt^H^H^H^H^H^H^H^H^H^H^H./frac2.out < inp2.txt > frac2.txt

[cchansen@zeus cchansen]$ ./frac2.out < inp2.txt > frac2.txt

[cchansen@zeus cchansen]$ g++ inp2.txtpico inp2.txtexit./frac2.out < inp2.txtcat fraction2.cpp
//      Author: 	Caitlin Hansen
//      Instructor: 	Dr.Wang
//      Due Date: 	March 11, 2009
//      File Name: 	fraction2.cpp
//
//      Goal: 		define Fraction class and test the class with a driver
//              	reads the fractions from a file and computes them using 
//              	basic arithmetic. 
//

#include <iostream>

using namespace std;

class Fraction
{       int num, den;
public:
        // constructors
        Fraction()
        {       num=0; den=1;   }
        Fraction(int n, int d)
        {       num=n; den=d;   }

        // transformers
        void Set(int n, int d)
        {       num=n; den=d;   }
        void Fraction :: Reduce()
        {       int n = num;
                int d = den;
                while ( d != 0)
                {       int r = n % d;
                        n = d;
                        d = r;
                }
                if (n != 0)
                {       num /= n;
                        den /= n;
                }
                if ( den < 0)
                {       num *= (-1);
                        den *= (-1);
                }
        }
  
        // observers
        Fraction operator+ (Fraction other)
        {       Fraction add;
                add.num = (num * other.den) + (other.num * den);
                add.den = den * other.den;
                return add;
        }
        Fraction operator- (Fraction other)
        {       Fraction sub;
                sub.num = (num * other.den) - (other.num * den);
                sub.den = den * other.den;
                return sub;
        }
        Fraction operator* (Fraction other)
        {       Fraction temp;
                temp.num = num * other.num;
                temp.den = den * other.den;
                return temp;
        }
        Fraction operator/ (Fraction other)
        {       Fraction div;
                div.num = num * other.den;
                div.den = den * other.num;
                return div;
        }
        void Print() const
        {       cout << num << "/" << den;      }

};


int main()
{       Fraction x, y, z;       // 0/1
        int n, d;
        char dummy, op;

        cout << "Fraction Arithmetic";
        cout << endl;
        cin >> n >> dummy >> d;

        while(cin)
        {       x.Set(n, d);

                cin >> op;

                cin >> n >> dummy >> d;
                y.Set(n, d);

                if( op == '*')
                        z = x * y;
                else if (op == '+')
                        z = x + y;
                else if (op == '-')
                        z = x - y;
                else if (op == '/')
                        z = x / y; 


                x.Print();
                cout << " " << op << " ";
                y.Print();
                cout << " =  ";
                z.Reduce();
                z.Print();
                cout << endl;

                cin >> n >> dummy >> d;
        }

        cout <<"\n\n Done. \n\n";
        return 0;
}

[cchansen@zeus cchansen]$ cat fraction2.cppscript fraction2.txt./frac2.out < inp2.txt
Fraction Arithmetic
3/4 + 2/3 =  17/12
1/2 + 1/3 =  5/6
17/3 * 12/25 =  68/25
1/2 - 5/8 =  -1/8
19/12 / 38/24 =  1/1
1/5 * 6/48 =  1/40
3/7 - 2/13 =  25/91
22/15 + 13/2 =  239/30
15/6 * 33/2 =  165/4
45/7 - 13/100 =  4409/700
66/5 / 2/3 =  99/5
456/32 + 123/4 =  45/1
600/8 + 100/12 =  250/3
159/33 + 2/11 =  5/1
1/2 + 3/7 =  13/14
1/2 - 3/7 =  1/14
1/2 * 3/7 =  3/14
1/2 / 3/7 =  7/6
78/16 * 60/1 =  585/2
13/13 + 52/5132 =  1296/1283
14/141 - 8/8 =  -127/141
6/6 * 7/7717 =  7/7717
15/1445 / 9/1119 =  373/289


 Done. 

[cchansen@zeus cchansen]$ exit

Script done on Sat 21 Mar 2009 05:27:14 PM EST

Stv3n404 - 2023