本帖最后由 从┧靇┟开始 于 2014-5-22 19:09 编辑
刚看到类 自己练习了一段小程序,求一个能打印出Apple电脑的方法,或者告诉我枚举占位符到底是什么? 小弟谢啦!
- #import <Foundation/Foundation.h>
- typedef enum{
- AppleComputer,
- DellComputer,
- LenovoComputer
- } ComputerBand;
- typedef struct{
- int year;
- int month;
- int day;
- } ExpireDate;
- @interface Computer : NSObject
- {
- @public
- ComputerBand band;
- ExpireDate expireDate;
- }
- - (void)open;
- - (void)close;
- @end
- @implementation Computer
- - (void)open
- {
- NSLog(@"选择打开电脑的品牌是%d", band); // 能不能不要输出0,1,2 直接输出电脑名称
- }
- - (void)close
- {
- NSLog(@"关闭显示日期为 %d年 %d月 %d日 的电脑", expireDate.year, expireDate.month, expireDate.day);
- }
- @end
- int main()
- {
- Computer *c1 = [Computer new];
-
- c1->band = AppleComputer;
-
- Computer *c2 = [Computer new];
-
- c2->expireDate.year = 1900;
- c2->expireDate.month = 9;
- c2->expireDate.day = 9;
-
-
- [c1 open];
-
- [c2 close];
-
- return 0;
- }
复制代码 |