reset password
Author Message
harry_520
Posts: 76
Posted 13:16 Jan 23, 2015 |

For the operator overloading, do me need to make the +/- operators support all the possible conditions - pounds +/-pounds, ounces +/- ounces, pounds ounces +/- pounds ounces, pounds+/- ounces?

And for the == operator, should we compare pounds and pounds, ounces and ounces, pounds ounces and pounds ounces, or pounds and ounces, or all of them?

Last edited by harry_520 at 13:21 Jan 23, 2015.
kscasado
Posts: 19
Posted 14:02 Jan 23, 2015 |

This should be much more of a one size fits all if you are adding a negative number you are still performing addition on that number regardless of the numbers sign linked.  .

Unless you are talking about having a negative value of ounces and a positive value of pounds. Logically this should never occur since the two are linked.  I.E if you have negative pounds and positive ounces perhaps some conversion needs to take place. The weight as a whole should be only positive or negative, not a mixture. At least that's my understanding.

 

 

For the == Operator this should work just like you would want a string == to work. As he said try to keep the same functionality that the primitives use for these operators.

raywu64
Posts: 44
Posted 16:00 Jan 23, 2015 |
harry_520 wrote:

For the operator overloading, do me need to make the +/- operators support all the possible conditions - pounds +/-pounds, ounces +/- ounces, pounds ounces +/- pounds ounces, pounds+/- ounces?

And for the == operator, should we compare pounds and pounds, ounces and ounces, pounds ounces and pounds ounces, or pounds and ounces, or all of them?

 

My take on it was that it didn't matter. As long as it had the same meaning it would be fine. So 3 pounds -4 ounces is essentially the same thing as 2 pounds and 12 ounces. 

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

For the == think about the data you have.  For a weight object to be equal to another the corresponding data should be equal.  Pounds must be equal to pounds and ounces must be equal to ounces.  Also consider how you are storing your objects.... I could have w1 which is 1 pound and w2 which is 16 ounces and they should be equal to one another.  Think if it like a fraction that you always have to keep reduced to its lowest terms.