Could someone look at my code and see why it is not outputting what I would like for it to? I am having the same problem with post as I am with pre. I thought perhaps maybe someone could show me the light here on why I am having a problem. I have looked at several books any suggestions.
Main()
//pre
z = Fraction( 5, 2);
cout << "\tFraction Z is: " << z << endl;
//this should be 5/2
cout << "\t++Z is: " << ++z << ", now Z is: " <<z<< endl;
//this should be 7/2 and then 7/2
cout << "\t--Z is: " << --z << ", now Z is: " <<z<< endl;
//this should be 5/2 and then 5/2
Although it reads out as
//Fraction Z is: 5/2
// ++Z is: 7/2, now Z is: 5/2
// --Z is: 5/2, now Z is: 7/2
Here is the code for it:
Fraction Fraction:
perator ++ ()
{
numerator += denominator;
return *this;
}
Fraction Fraction:
perator --()
{
numerator -= denominator;
return *this;
}
Fraction Fraction:
perator ++ (int)
{
Fraction temp=*this;
numerator += denominator;
return temp;
}
Fraction Fraction:
perator --(int)
{
Fraction temp=*this;
numerator -= denominator;
return temp;
}
The header file:
under public
Fraction operator ++();
Fraction operator --();
Fraction operator ++(int);
Fraction operator --(int);
Main()
//pre
z = Fraction( 5, 2);
cout << "\tFraction Z is: " << z << endl;
//this should be 5/2
cout << "\t++Z is: " << ++z << ", now Z is: " <<z<< endl;
//this should be 7/2 and then 7/2
cout << "\t--Z is: " << --z << ", now Z is: " <<z<< endl;
//this should be 5/2 and then 5/2
Although it reads out as
//Fraction Z is: 5/2
// ++Z is: 7/2, now Z is: 5/2
// --Z is: 5/2, now Z is: 7/2
Here is the code for it:
Fraction Fraction:
{
numerator += denominator;
return *this;
}
Fraction Fraction:
{
numerator -= denominator;
return *this;
}
Fraction Fraction:
{
Fraction temp=*this;
numerator += denominator;
return temp;
}
Fraction Fraction:
{
Fraction temp=*this;
numerator -= denominator;
return temp;
}
The header file:
under public
Fraction operator ++();
Fraction operator --();
Fraction operator ++(int);
Fraction operator --(int);