public:
void setFraction (const double& x, const double& y, const double& z, const double& r);
//Function to set the member variables x, y, z.
//Postcondition: a=x, b=y, c=z.
void getFraction (double& x, double& y, double& z, double& r) const;
//Function to return fraction.
//Postcondition: x=a, y=b, z=c.
bool operator==(const fractionType& otherFraction) const;
//overload the equality operator.
//Postcondition: Returns true if the fraction
//is equal to the ohter fraction, otherwise it returns false.
bool operator!= (const fractionType& otherFraction) const;
//Overload the not equal operator.
//Postcondition: REturns true if the fraction is not
// equal to the other fraction, otherwise it returns false.
fractionType operator+ (const fractionType& otherFraction) const;
//Overload the addition operator.
fractionType operator* (const fractionType& otherFraction) const;
//overloa the multiplication operator.
fractionType operator/ (const fractionType& otherFraction) const;
//Overload the division operator.
fractionType( double x = 0, double y = 0, double z = 0, double r = 0);
//Constructor to initialize the object with the values
//specified by the user. If no values are specified, the
//default values are assumed.
//Postcondition: a=x, b=y, c=z.
private:
double a; //variable to store x
double b; //variable to store y
double c; //variable to store z
double d; //Variable to store r
};
#endif
This is the Imp file:
# include <iostream>
# include <cmath>
# include <string>
#include "fractionType.h"
I can't have the >> operator to work. When it asks me for the first fraction, I input the data in the form (1,3), but It just stays still. The Enter button doesnt do anything. It just allows me to write whatever I want but it never takes me to the next fraction.
If I do
fraction1 (1,3);
fraction2 (1,3);
fraction3;
fraction3 = fraction1 + fraction2;
It works!!!
It works fine, but when I ask the user to input the data, it doesnt do anything.
Any ideas?? Or what am I missing???
Also, how do reduce the fractions?? and where do I write the code???
No I'm not going to read all that unformatted code not in [code] tags. Well, just a little bit.. Why in the world does your fraction have 4 doubles, when is should have 2 integers?
Reduction:
fraction F = {a, b};
int g = gcd(a, b) where gcd stands for greatest common divisor
reduced fraction F' = {a/g, b/g}
If you don't know how to write a gcd function, google it. There is pseudocode in wikipedia.
>>:
you want to read "12/13" into {12, 13}, so (you may first want to ignore any whitespaces with stream >> ws;) read a, ignore one char, read b.
But it just stays still. I'm ignoring the () and the comma, unless I'm doing it wrong. What drives me crazy is that I am following what the book says in order to get it right, but it doesnt work. It just stays still and it doesnt go to the next statement where I'm supposed to enter the next fraction.