Here is the implementation for our person class. Examine the following code:
1 @implementation Person
2 -(void) setAge: (int) a{
3 age = a;
4 }
5 -(void) setWeight: (int) w{
6 weight = w;
7 }
8 -(void) eat{
9 weight++;
10 }
11 @end
Line 1 lets the compiler know that this is where the code for the Person implementation begins.
Line 2 is a repeat of the declaration we saw in the interface section.
Line 3 is the operation that takes place in setAge. The age of the person is set to be the age you pass into the function.
Lines 5-7 are exactly the same as the setAge code, except instead of age, the variable is weight.
Line 9 is the operation for our eat function. weight++ means that the value of weight will be increased by 1. When you eat, you gain weight!
Line 11 signifies the end of the Person implementation.
In the next tutorial, we'll get to use our Person class definition to create a new person object!
I think you lost me :D
ReplyDeleteWhere can I find a good manual on this?
ReplyDeletecool stuff
ReplyDeleteLike the idea!
ReplyDeleteAs a student who is now taking a computer science class for the first time, this was very interesting. Following
ReplyDeleteuhh awesome, idk if I missed any lessions but could you explain like rly basic stuff. I have tryed to get in to coding but i get bored easy ;D
ReplyDeletedo something fun with the codes! :D
sweet
ReplyDeleteNeat code
ReplyDeleteI think is is beyond my skills :(
ReplyDeletethank you.
ReplyDeleteHaha, nice
ReplyDeletenoob here
ReplyDelete