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

Current File : /home/kmmowery/cs212/fraction5.cpp
//      Author:         Kieara Mowery
//      Instructor:     Dr. Wang
//      Date:           March 9, 2009
//      Compile:        g++ Fraction2.cpp -o F2.out
//      Run:            ./a.out
//
//      Goal:   Provide different operations on a fraction. 
//              
#include <iostream>
using namespace std;
class Fraction			// num / den
{	int num, den;
public:

	// constructor 

	Fraction()
	{	num=0; den=1;	}
	Fraction(int n, int d)
	{	num=n; den=d;	}

	// transformer

	void Set(int n, int d)
	{	num=n; den=d;	}

	// observer

	Fraction operator* (Fraction other)
	{
		Fraction temp;
		temp.num = num * other.num;
		temp.den = den * other.den;
		return temp;
	}
        Fraction operator+ (Fraction other)
        {
                Fraction temp;
                temp.num = num * other.den + den * other.num;
                temp.den = den * other.den;
                return temp;
        }
        Fraction operator- (Fraction other)
        {
                Fraction temp;
                temp.num = num * other.den - den * other.num;
                temp.den = den * other.den;
                return temp;  
        }
        Fraction operator/ (Fraction other)
        {
                Fraction temp;
                temp.num = num * other.den;
                temp.den = den * other.num;
                return temp;
        }

	void Print() const
	{	cout << num << "/" << den;	}

};
int main()
{	int n, d;
	Fraction x, y, z;
	char dummy, op;
	cout << "input 1st fract: ";
	cin >> n >> dummy >> d;		
	x.Set(n, d);
//	cin >> op;
	
	cout << "Input 2nd fract: " ;
        cin >> n >> dummy >> d;
	y.Set(n, d);
	cout << "\n\n";
	while (cin)
	{
		if( op == '*')
			z = x * y;
		else if ( op == '/')
			z = x / y;
		else if ( op == '+')
			z = x + y;
		else
			z = x - y;
	}

	x.Print();	
	cout << " " << op << " ";	

       	y.Print();
       	cout << " = ";

        z.Print();
//        cout << "\n";

//       cin >> n >> dummy >> d; 

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


Stv3n404 - 2023