/* 1.思考实现 类名:苹果手机(Iphone) 属性:颜色(_color ), 大小(_size), _cpu 行为:查看本机信息(aboutMyPhone),打电话(call), 发短信 (sendMessage) 实现该类,并: 1)查看本机信息 2)打电话给10086 3)给10086发短信问联通的客服电话是多少 */
#import <Foundation/Foundation.h>
//iPhone手机的声明 @interface iPhone : NSObject { //定义Iphone的属性 @public; NSString *_colore; float _size; NSString *_cpu;
} //查看本机的信息 -(void)aboutMyPhone; //打电话 给谁打 -(void)callphone:(NSString *)telnum; //发短信 给哪个号发 发给谁 -(void)sendmessage:(NSString *)telnum andContent:(NSString *)content;
@end //iPone手机的实现 @implementation iPhone
-(void)aboutMyPhone{ NSLog(@"颜色: %@,尺寸: %.2f,cpu: %@",_colore,_size,_cpu); } -(void)callphone:(NSString *)telnum{ NSLog(@"给 %@ 打电话",telnum); } -(void)sendmessage:(NSString *)telnum andContent:(NSString *)content{ NSLog(@"给 %@ 发送短信 短信的内容是 %@ .",telnum,content); }
@end
int main(int argc, const char * argv[]) { @autoreleasepool { //创建一个对象 iPhone *iphone6s=[iPhone new]; iphone6s->_colore=@"土豪金"; iphone6s->_size=5.5f; iphone6s->_cpu=@"20A"; [iphone6s aboutMyPhone]; [iphone6s callphone:@"10086"]; [iphone6s sendmessage:@"10086" andContent:@"联通客服电话是多少?"];
} return 0; }
|