I am working with post & pre incrementing. I am having a bit of difficulty getting the numbers to increment correctly where I need them. Could someone tell me what I am doing wrong? Here is what I have.
Main()
{
Fraction P=(5,2);//preincrementing
cout<<"The number is:<<++P<<"after incrementing is"<<P<<endl;
cout<<"The number is:<<--P<<"after incrementing is"<<--P<<endl;
************This section above should be outputed
The number is: 7/2 after incrementing is 7/2
The number is: 5/2 after incrementing is 5/2
***************Post Incrementing********************
Fraction Q=(2,3);
cout << ", Q++ is: " << Q++ << ", now Z is: " << Q << endl;
cout << "\tQ is: " << Q;
cout << ", Q-- is: " << Q-- << ", now Q is: " << Q << endl;
The number is: 2/3 after incrementing is 4/3
The number is: 4/3 after incrementing is 2/3
****************************Here is the code for function***
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 problem is that the numbers are not coming out right. I have looked at several books could someone give me some insite on what I am or am not doing so I could learn?
Main()
{
Fraction P=(5,2);//preincrementing
cout<<"The number is:<<++P<<"after incrementing is"<<P<<endl;
cout<<"The number is:<<--P<<"after incrementing is"<<--P<<endl;
************This section above should be outputed
The number is: 7/2 after incrementing is 7/2
The number is: 5/2 after incrementing is 5/2
***************Post Incrementing********************
Fraction Q=(2,3);
cout << ", Q++ is: " << Q++ << ", now Z is: " << Q << endl;
cout << "\tQ is: " << Q;
cout << ", Q-- is: " << Q-- << ", now Q is: " << Q << endl;
The number is: 2/3 after incrementing is 4/3
The number is: 4/3 after incrementing is 2/3
****************************Here is the code for function***
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 problem is that the numbers are not coming out right. I have looked at several books could someone give me some insite on what I am or am not doing so I could learn?