• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Objective-C 程序设计(第六版)第十章习题答案

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

1.

 1 - (id) init
 2 {
 3     return [self initWithWidth: 0 andHeight: 0];
 4 }
 5 
 6 - (id) initWithWidth: (int) w andHeight: (int) h
 7 {
 8     self = [super init];
 9     if (self) {
10         [self setWidth: w andHeight: h];
11     }
12     return self;
13 }

2.

 1 - (id)init
 2 {
 3     return [self initWithSide:0];
 4 }
 5 
 6 - (id) initWithSide: (int) side
 7 {
 8     self = [super init];
 9     if (self) {
10         [self setSide:side];
11     }
12     return self;
13 }

3.

 1 //.m文件定义静态变量  增加类方法
 2 #import "Fraction.h"
 3 
 4 static int gCounter;
 5 
 6 @implementation Fraction
 7 @synthesize numerator, denominator;
 8 
 9 
10 - (Fraction *) add: (Fraction *) f
11 {
12     Fraction *result = [[Fraction alloc] init];
13     
14    result.numerator = numerator * f.denominator + denominator * f.numerator;
15    result.denominator = denominator * f.denominator;
16     
17     [result reduce];
18     gCounter++;
19     return result;
20 }
21 
22 + (int) count
23 {
24     return gCounter;
25 }

4.

 typedef enum {Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday} Day;

5. 枚举类型不知道怎么用

 1         typedef Fraction * FractionObj;
 2         
 3         FractionObj f1 = [[Fraction alloc] init],
 4                     f2 = [[Fraction alloc] init];
 5         
 6         [f1 setTo: 1 over: 2];
 7         [f2 setTo: 2 over: 3];
 8         
 9         [f1 print];
10         [f2 print];

6.略.


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Objective-C 程序设计(第六版)第六章习题答案发布时间:2022-07-12
下一篇:
Objective-C之类目发布时间:2022-07-12
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap