------Java培训、Android培训、iOS培训、.Net培训、期待与您交流! -------
类名:苹果手机(iPhone)
属性:颜色(_color),大小(_size),_cpu
行为:查看本机信息(aboutMyPhone),打电话(call),发短信(sendMessage)
实现该类,并:
1)查看本机信息
2)打电话给10086
3)给10086发短信
#import <Foundation/Foundation.h>
//iPhone 类的声明
typedef enum color{kColorWhite,kColorBlack,kColorTHJ} iColor;
@interface iPhone:NSObject
{
@public
//类的属性(实例变量、成员变量)
//手机的颜色
iColor _color;
//手机的尺寸
float _size;
NSString *_cpu;
}
//类的行为(方法)的声明
//查看手机的信息 实质:把手机的实例变量值打印出来
-(void)aboutMyPhone;
//打电话,需要一个参数,参数就是电话号码(字符串)
-(void)callPhone:(NSString *) telNum;
//发短信,给指定号码发送短信,短信内容可以指定,两个参数
-(void)sendMassage:(NSString *)telNum and:(NSString *) content;
@end
//iPone 类的实现
@implementation iPhone
-(void)aboutMyPhone{
NSLog(@"颜色:%d,尺寸:%.2f,cup:%@",_color,_size,_cpu);
}
-(void)callPhone:(NSString *) telNum{
NSLog(@"给 %@ 打电话",telNum);
}
-(void)sendMassage:(NSString *)telNum and:(NSString *) content{
NSLog(@"给 %@ 发送短信,短信内容:%@ 。",telNum,content);
}
@end
int main(int argc, const char * argv[]) {
@autoreleasepool {
//创建对象
iPhone *iphone6Plus = [iPhone new];
//设定手机的信息
iphone6Plus->_color = kColorTHJ;
iphone6Plus->_cpu = @"A10";
iphone6Plus->_size = 5.5f;
//调用方法
[iphone6Plus aboutMyPhone];
//给10086打电话
[iphone6Plus callPhone:@"10086"];
//给10086发短信
[iphone6Plus sendMassage:@"10086" and:@"当前话费余额"];
}
return 0;
}