Involve more properties and methods of the class topic, very simple topic originally do not want to send, if a classmate learned this topic feel too long reluctant to knock code, copy walk my can ~ but still suggest to play a dozen

Source: Internet
Author: User

/*
3. Design a "student" category
1> Property
* Name
* Birthday
* Age
* Height (unit is m)
* Weight (unit is kg)
* Gender
* C language Score
* OC Results
* iOS Score

2> behavior
* Running: Every run, height increased by 1cm, weight loss 0.5kg, output after running the weight
* Eat: Every time, height increases 1cm, weight gain 0.5kg, output after eating the weight
* Study: Each study once, 3 can score each plus 1 points, output after the study of 3 subjects results
* Sleep: Output all the properties
* Compare C language scores: Compare C language scores with another student, return to poor grades (own score-other people's scores)
* Compare OC Scores: Compare OC language scores with another student, return to poor grades (own score-other people's scores)
* Compare iOS scores: Compare iOS with another student, return to poor grades (your score-other people's scores)
* Calculate total Score: Figure out the total score of 3 subjects
* Calculate average score: Calculate the average score of 3 subjects
*/

/*
#import <Foundation/Foundation.h>

@interface Student:nsobject
{
Each time a class property declaration is to mention a few words: To add @public, to be declared as a string type of the property declaration as a string pointer variable type
@public
NSString *_name;
NSString *_birthday;
int _year;
float _height;
float _weight;
NSString *_sex;
int _scorec;
int _SCOREOC;
int _scoreios;
}

-(void) run;
-(void) eat;
-(void) study;
-(void) sleep;
-(int) Gradec: (int) score1 ANDGRADEC: (int) score2;
-(int) GRADEOC: (int) score2;
-(int) Gradeios: (int) score2;
-(int) Sumscore;
-(int) Averscore: (int) sum;

@end

@implementation Student

-(void) run
{
_weight-=0.5;
NSLog (@ "Running, thin 0.5kg, weight changed to%.2f", _weight);
}
-(void) Eat
{
_weight+=0.5;
NSLog (@ "eat, fat 0.5kg, weight into%.2f", _weight);
}
-(void) study
{
_scorec+=1;
_scoreoc+=1;
_scoreios+=1;
NSLog (@ "c:%d,oc:%d,ios:%d", _scorec,_scoreoc,_scoreios);
}
-(void) sleep
{
NSLog (@ "name:%@\nbirthday:%@\nyear:%d\nheight:%.2f\nweight:%.2f\nsex:%@\ncscore:%d\nocscore:%d\niosscore:%d", _ Name,_birthday,_year,_height,_weight,_sex,_scorec,_scoreoc,_scoreios);
}
-(int) Gradec: (int) score1 ANDGRADEC: (int) Score2//This method is to pass in the data of two people, and then calculate, I think this method is insufficient, we obviously use the first person to call this method, Then only need to pass the second person's achievement not to have, we obviously can in the method directly refers to call this method the person's result. The improved method is the following two methods for OC and iOS
{
int score3=score1-score2;
return score3;
}
-(int) GRADEOC: (int) Score2//This method and the following iOS method only need to pass in a value, and then in the method directly refer to the object that calls this method of the related properties (members) and the value of the passed in the comparison can be, relatively simple
{
int score3=_scoreoc-score2;
return score3;
}
-(int) Gradeios: (int) Score2
{
int score3=_scoreios-score2;
return score3;
}
-(int) Sumscore
{
int sum;
Sum=_scorec+_scoreoc+_scoreios;
return sum;
}
-(int) Averscore: (int) sum
{
int AVERAGE=SUM/3;
return average;
}


@end

int main ()
{
@autoreleasepool {
Student *ss1=[student New];
Student *ss2=[student New];
Ss1->[email protected] "Wang";
Ss2->[email protected] "Lao";
ss1->_weight=55.5;
ss2->_weight=65.5;
[Ss1 Run]; The first instantiation of the object SS1 to call the Run method
[SS2 eat]; The second instantiation of the object SS2 to call the Eat method
Arithmetic, so the assignment is a must, very troublesome, the habit is good
ss1->_scorec=85;
ss2->_scorec=90;
ss1->_scoreoc=90;
ss2->_scoreoc=75;
ss1->_scoreios=80;
ss2->_scoreios=100;
Ss1->[email protected] "1993.12.31";
ss1->_year=22;
ss1->_height=1.81;
Ss1->[email protected] "man";
[SS1 Study]; Because this method will make all the scores plus 1, so the subsequent operations are in the results plus 1 of the case of the operation.
[SS1 Sleep];
int Scoreccha=[ss1 Gradec:ss1->_scorec andgradec:ss2->_scorec];
NSLog (@ "%@ C language score minus%@ C language score difference is:%d", Ss1->_name,ss2->_name,scoreccha);
int Scoreoccha=[ss1 gradeoc:ss2->_scoreoc];
NSLog (@ "%@ 's OC language score minus%@ 's OC language score is:%d", Ss1->_name,ss2->_name,scoreoccha);
int Scoreioscha=[ss1 gradeios:ss2->_scoreios];
NSLog (@ "%@ 's iOS score minus%@ 's iOS score difference is:%d", Ss1->_name,ss2->_name,scoreioscha);
int Sum=[ss1 Sumscore];
NSLog (@ "%@ 's total is:%d", ss1->_name,sum);
int Average=[ss1 Averscore:[ss1 Sumscore]]; Here is a direct call to the previous method's return value, type consistency can be
NSLog (@ "%@ 's average score is:%d", ss1->_name,average);
}
return 0;
}
*/

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Involve more properties and methods of the class topic, very simple topic originally do not want to send, if a classmate learned this topic feel too long reluctant to knock code, copy walk my can ~ but still suggest to play a dozen

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.