Fraction class?

fraction class
Last edited on
why not call your operator << and >>???

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
ostream& operator<<(std::ostream &output, const Fraction &F)
{
	output << F.toString();
	return output;
}
//*********************************************
//*******************Stream Insertion**************************
istream& operator>>(std::istream &input, Fraction&value)
{
	//Numerator = s.substr(0, i);
	//Denominator = s.substr(i, 1);
	//s.find('/');
	//find the delimniter and call on the substring 
	int Numerator, Denominator;

	input >> Numerator>>Denominator;
	value = Fraction(Numerator, Denominator);
	return input;
}


Anyways the other way you would have to move line 207 to line 213 then change the 5 to numerator and 7 to denominator also they should probably be integers.

1
2
3
4
5
6
7
	int Numerator, Denominator;

	cout << "Lets create a fraction! Please enter a value for the numerator." << endl;
	cin >> Numerator;
	cout << "Please enter a value for the denominator." << endl;
	cin >> Denominator;
        Fraction Fract(Numerator , Denominator); 


Though taking advantage of your operator overloads would be better.

1
2
3
Fraction Fract;
cout << "Enter a fraction (numerator [space] denominator): ";
cin >> Fract;

Topic archived. No new replies allowed.