Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 3.139.87.113
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/fraction1.txt
Script started on Sat 21 Mar 2009 05:28:35 PM EST
[cchansen@zeus cchansen]$ exit./frac2.out < inp2.txtcat fraction2.cpp.cpp1.cpp
// Author: 	Caitlin Hansen
// Instructor: 	Dr.Wang
// Due Date: 	March 3, 2009
// File Name: 	fraction1.cpp
//
//      Goal: 	The program defines Fraction class and tests the class with a driver
//              that reads the fractions and computes them using multiplication,
//		division, addition, and subtraction.

#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 << "Input the first fraction (n/d): ";
	cin >> n >> dummy >> d;

	while( n!= -1 && d != 1)
	{	x.Set(n, d);
		cout << "Input y (n/d): ";
		cin >> n >> dummy >> d;
		y.Set(n, d);

		cout << "Which operation( +, -, *, /)?";
		cin >> op;
		if( op == '*')
			z = x * y;
		else if (op == '+')
			z = x + y;
		else if (op == '-')
			z = x - y;
		else if (op == '/')
			z = x / y;
		else 
		{
			cout << "Please choose an operation:";
			cin >> op;
		}
		cout << endl;		
		cout << "x: ";
		x.Print();
		cout << "\ny:  ";
		y.Print();
		cout << "\nz:  ";
		z.Reduce();
		z.Print();
		cout << endl;

		cout << "Input x (n/d, -1/1 to quit): ";
		cin >> n >> dummy >> d;
	}
	cout <<"\n\n Done. \n\n";

	return 0;
}
[cchansen@zeus cchansen]$ cat fraction1.cppexit./frac2.out < inp2.txtcat fraction2.cppscript 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.cppexitcat fraction.cpp./frac2.outg++ fraction2.cpp -o frac2.outpico fraction2.cpp1.cppscript fraction1.txt./frac1.out
Input the first fraction (n/d): 4/5
Input y (n/d): 2/3
Which operation( +, -, *, /)?*

x: 4/5
y:  2/3
z:  8/15
Input x (n/d, -1/1 to quit): 7/9
Input y (n/d): 5/7
Which operation( +, -, *, /)?-

x: 7/9
y:  5/7
z:  4/63
Input x (n/d, -1/1 to quit): 5/8
Input y (n/d): 2/3
Which operation( +, -, *, /)?/

x: 5/8
y:  2/3
z:  15/16
Input x (n/d, -1/1 to quit): 4/5
Input y (n/d): 6/7
Which operation( +, -, *, /)?+

x: 4/5
y:  6/7
z:  58/35
Input x (n/d, -1/1 to quit): / 1/  -1/1


 Done. 

[cchansen@zeus cchansen]$ exit

Script done on Sat 21 Mar 2009 05:30:58 PM EST

Stv3n404 - 2023