OC-Simple design of classes with enum and struct

Source: Internet
Author: User

#import <Foundation/Foundation.h>

@interface car:nsobject{

@public

int _wheels;

int _speed;

}

-(void) run;

@end

@implementation Car

-(void) run{

NSLog (@ "%d wheels, with a speed of%d cars running up", _wheels, _speed);

}

@end

void Test1 (Car *newcar) {

Newcar->_wheels = 5;

}

void Test2 (Car *newcar);

int main (int argc, const char * argv[]) {

Car *C1 = [[Car alloc] init];

Car *C2 = [[Car alloc] init];

Test1 (C1);

Test2 (C2);

[C1 run];

[C2 Run];

return 0;

}

void Test2 (Car *newcar) {

Newcar->_wheels = 4;

Newcar->_speed = 300;

}

*/

/*

#import <Foundation/Foundation.h>

@interface persons:nsobject{

@public

NSString *_name;

int _age;

}

-(void) print;

@end

@implementation Persons

-(void) print{

NSLog (@ "name =%@, age =%d", _name, _age);

}

@end

void Sett (Persons *p);

int main (int argc, const char * argv[]) {

Persons *p = [[Persons alloc] init];

Sett (p);

[P print];

return 0;

}

void Sett (Persons *p) {

P->_name = @ "Jerry";

P->_age = 15;

}

*/

#import <Foundation/Foundation.h>

typedef enum{

Sexman,

Sexwoman

} Sex;

typedef enum{

Colorblue,

Colorwhite,

Colorblack,

Colorgreen,

Colorred,

Colororange

} Color;

typedef struct{

int year;

int month;

int day;

} Date;

@interface Person:nsobject

@property NSString *name;

@property int age;

@property sex sex;

@property Color Favcolor;

@property Date birthday;

-(void) print;

@end

@implementation person

-(void) print{

NSLog (@ "name =%@, age =%d, sex =%d, Favcolor =%d, birthday =%d-%d-%d", _name, _age, _sex, _favcolor, _birthday.year, _birthday.month, _birthday.day);

}

@end

int main (int argc, const char * argv[]) {

Person *p = [[Person alloc] init];

P.name = @ "Jerry";

P.age = 10;

P.sex = Sexman;

P.favcolor = Colorwhite;

Date D = {2015, 7, 21};

P.birthday = D;

[P print];

return 0;

}

OC-Simple design of classes with enum and struct

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.