Operations on Fractions
Let’s continue to work with the Fraction class. First, you write a method that enables you to add one fraction to another. You name the method add:, and you have it take a fraction as an argument. Here’s the declaration for the new method:
-(void) add: (Fraction *) f;
Note the declaration for the argument f:
(Fraction *) f
This says that the argument to the add: method is a reference to an object from the Fraction class. The asterisk is necessary, so the following declaration is not correct:
(Fraction) f
You will be passing one fraction as an argument to your add: method, and you’ll have the method add it to the receiver of the message; the following message expression adds the Fraction bFraction to the Fraction aFraction ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access