class FullFraction
{
int numerator;
int denominator;
int gcd(int x, int y);
public:
FullFraction();
FullFraction(int n, int d);
FullFraction add(FullFraction rop);
FullFraction subtract(FullFraction rop);
FullFraction multiply(FullFraction rop);
FullFraction divide(FullFraction rop);
int getNumerator() const;
void setFullFraction(int num, int denom);
int getDenominator() const;
float getDecimal() const;
std::string toString();
};
FullFraction::FullFraction()
{
/*********************************
Incase nothing is set like:
FullFraction f0;
sets the fraction to 0/0
*********************************/
numerator = 0;
denominator = 0;
}
//sends in the value of a numerator and denominator
FullFraction::FullFraction(int n, int d)
{
int numerator, denominator;
FullFraction::setFullFraction(numerator,denominator);
}
//gets value of numerator
int FullFraction::getNumerator() const
{
return numerator;
}
//sets value of the fraction
void FullFraction::setFullFraction(int num, int den)
{
numerator = num;
denominator = den;
}
//gets the value of the denominator
int FullFraction::getDenominator() const
{
return denominator;
}
staticint assign_FullFraction()
{
FullFraction f0; //if nothing is initilized it would be null
FullFraction f1(2, 2);
FullFraction f2(2, 7);
FullFraction f3(1, -3);
cout << f1.toString() << " + " << f0.toString() << " = " << f1.add(f0).toString() << endl;
cout << f0.toString() << " + " << f1.toString() << " = " << f0.add(f1).toString() << endl;
return 0;
}
Line 36 : You are passing uninitialized variables to setFullFraction function because these variables are uninitialized so they contain undefined values.
int numerator, denominator;
I think this is what you mean :
1 2 3 4 5 6
// Sends in the value of a numerator and denominator
FullFraction::FullFraction(int n, int d)
{
int numerator, denominator;
FullFraction::setFullFraction(n, d);
}