reset password
Author Message
jpascua
Posts: 197
Posted 13:51 Jan 23, 2015 |

Overload the operator – for Weight objects. Overload the operator as a member function. NOTE: For
this program you can have negative weight and this should be handled correctly.

 

What exactly is meant by "handled correctly"?

If weight 1 = 1 pound and 1 ounce and weight 2 = 2 pounds and 16 ounces

after subtraction, pounds = -1 and ounces = -15 which is

-1.9375 pounds is correct?

kscasado
Posts: 19
Posted 14:21 Jan 23, 2015 |

I think he is trying to make sure you understand the difference between subtraction and negation.

For instance if you have a negative weight then presumably both values should be negative and not just the pounds or ounces. 

I.E if you want to use weight2=-weight1 this should give you the proper result.

jpascua
Posts: 197
Posted 14:25 Jan 23, 2015 |

Sorry, I still don't quite understand.

jpascua
Posts: 197
Posted 14:31 Jan 23, 2015 |

My function is basically doing w1.pounds - w2.pounds and w1.ounces - w2.ounces.

Depending on the inputted pounds, say w1.pounds = 30 and w2.pounds = 3. This would give a positive number. But if it was the other way around; that is to say, w1.pounds = 3 and w2.pounds = 30, the result of the subtraction would be negative. The pounds can be either positive or negative whereas the ounces can be either positive or negative.

What I'm trying to say is that pounds and ounces are both separate values so depending on the input, they can either be both negative, both positive, or one can be negative while the other stays positive.

Would it not make sense to have a negative pounds while the ounces are positive?

As long as the decimal output is negative, it makes sense; at least to me.

Last edited by jpascua at 14:33 Jan 23, 2015.
kscasado
Posts: 19
Posted 15:08 Jan 23, 2015 |

I guess we could take a look at say 5 pounds and 5 ounces subtract 3 pounds and 7 ounces. How would you treat this, would your result be  2 pounds and -2 ounces?     

How would that output look? 

jpascua
Posts: 197
Posted 15:59 Jan 23, 2015 |

output():

2 pounds and -2 ounces

output_d():

1.875 pounds

kscasado
Posts: 19
Posted 16:04 Jan 23, 2015 |

I'm not sure if that's the type of output he is looking for.  Also I think the other main concern would be if you use weight 1 = -weight 2 now it's -2 pounds and 2 ounces? Using  that same logic it's still right but the output is a little more confusing .

jpascua
Posts: 197
Posted 16:13 Jan 23, 2015 |

So he meant negative numbers as input for pounds and ounces?

So I tried plugging those in:

Weight 1: -5 pounds and -5 ounces

Weight 2: -3 pounds and -7 ounces

After subtraction:

-2 ounces and 2 ounces

which is -1.875 pounds

kknaur
Posts: 540
Posted 16:18 Jan 23, 2015 |

It just means that your subtraction operator should be able to result in a negative value.