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

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/acyurksaitis/fraction.cpp
#include <iostream>

using namespace std;

class Fraction
{	//private is default
	int numerator;
	int  denomenator;
	
public:
	Fraction()
	{	numerator = 0;
		denomenator = 1;
	}
	Fraction(int n, int d)
	{	numerator = n;
		denomenator = d;
	}
	void Set(int n, int d)	//transformer
	{	numerator = n;
		denomenator = d;
	}
	void Print()const	//observer 
	{	cout << numerator  << '/' << denomenator;
	}
	Fraction Mult(Fractioin f)
	{
		Fraction t;
		int n, d;
		n = numerator*f.numerator;
		d = denomenator*f.denomenator;
		t.Set(n/d);
		return t;
	}


};		

int main ()
{
	Fraction x;
	Fraction y;
	int d;
	int n;
	char dummy;

	// Q: Declare an object named y with initalization 0/1
	 Fraction y;
	// Q: Declare an obj z with initalization 1/2?
	Fraction z (1,2);
	//Q: Reset y to 1/3?
	y.Set (1,3);
	// Q: Output y and z?
	y.Print ();
	cout << "\n" ;
	z.Print ();
		
	cout <<"Input x (n/d) -1/1 to quit: ";
	cin >> n >> dummy >> d;
	while(n!=-1 && d!=1)
	{
		// Q: Set x = n/d?
		x.Set(n,d);
		cout << "x: ";
		// debug out?
		x.Print();
		cout <<"\n";
		cout << "y: ";
		y.Print();
		cout <<"\n";
	}
	
	cout <<"\n\nBye.\n\n";
	return 0;
}

Stv3n404 - 2023