the result came incorrectly |
Please don't make us wade through the whole thing, especially when you haven't shown the program that generates this output. Which result(s) are incorrect? What result do you expect?
A few comments on the code.
Most importantly of all, this could be done far easier if you stored the total number of ounces rather than the pounds and ounces. Convert to/from pounds/ounces on input and output. There's a very important lesson to learn here: store the data in a format that's convenient for the
computer, not in the format that's convenient for the
user. These are often not the same.
Why are none of these functions/operators members of the class? While there are sometimes good reasons to do this, in a beginner's class your prof probably wants to see methods.
EnglishWeight::EnglishWeight(istream& str)
isn't necessary. Just have the
>>
operator read into the object.
You've made some of these methods too complicated. For example:
1 2 3 4 5 6 7 8
|
//Define operator * for number * EnglishWeight
EnglishWeight operator * (int num, EnglishWeight rhs)
{
rhs.m_pounds *= num;
rhs.m_ounces *= num;
return convertOunces(rhs);
return rhs;
}
|
convertOunces()
isn't quite right. When I add this main program:
int main()
{
EnglishWeight w(12,4);
EnglishWeight w1 = w * 5;
cout << w1 << '\n';
}
I get this output: