oc加强day01作业答案
2016-02-16 21:34
211 查看
题目
/**1. 说说类
* 文字内容
* 图片
* 发表时间
* 作者
* 转发的说说
* 评论数
* 转发数
* 点赞数
作者
名称
生日
账号
账号
账号名称
账号密码
账号注册时间
模拟场景:
张三在2007-9-8 17:56:34的时候, 注册了一个账号(名称:itcast, 密码:123456)
张三的生日是1998-7-4 18:46:24
张三在2010-8-8 9:23:44的时候, 发布一条说说
文字内容 @“今天心情不错”
图片 @“test.png”
发表时间
作者
转发的说说
评论数 100
转发数 290
点赞数 2000
李四在2006-9-8 19:26:54的时候, 注册了一个账号(名称:lisiitcast, 密码:654321)
李四的生日是1999-9-6 14:16:28
李四在2011-8-8 20:47:09的时候, 转发了张三之前发布的说说, 并且还附带了一句话:@“今天心情确实不错”
*/
blog.h
#ifndef blog_h #define blog_h #import <Foundation/Foundation.h> //账号类 @interface CzxxAcc: NSObject { @private NSString * _accName; NSString * _accPassword; NSString * _accRegTime; } @property (nonatomic,copy) NSString * accName; @property (nonatomic,copy) NSString * accPassword; @property (nonatomic,copy) NSString * accRegTime; -(id)initWithAccName:(NSString *) pAccname andPass:(NSString *) accPass andRegTime:(NSString *) Time; @end //作者类 @interface CzxxAuthor: NSObject { @private NSString * _name; NSString * _birth; CzxxAcc * _account; } @property (nonatomic,copy) NSString * name; @property (nonatomic,copy) NSString * birth; @property (nonatomic,strong) CzxxAcc * account; @end //说说类 @interface CzxxQzone: NSObject { @private NSString * _blogContents; NSString * _blogPics; NSString * _blogSendTime; CzxxAuthor * _blogAuthor; CzxxQzone * _blogCopy; int _commentsNums; int _copyNums; int _likeNums; } @property (nonatomic,copy) NSString * blogContents; @property (nonatomic,copy) NSString * blogPics; @property (nonatomic,copy) NSString * blogSendTime; @property (nonatomic,strong) CzxxAuthor * blogAuthor; @property (nonatomic,strong) CzxxQzone * blogCopy; @property (nonatomic,assign) int commentsNums; @property (nonatomic,assign) int copyNums; @property (nonatomic,assign) int likeNums; -(NSString *)description; @end #endif /* blog_h */
blog.m
#import <Foundation/Foundation.h> #import "blog.h" @implementation CzxxAcc -(id)initWithAccName:(NSString *) pAccname andPass:(NSString *) accPass andRegTime:(NSString *) Time { if(self = [super init]) { self.accName = pAccname; self.accPassword = accPass; self.accRegTime = Time; } return self; } @end @implementation CzxxAuthor @end @implementation CzxxQzone @synthesize blogContents = _blogContents; @synthesize blogPics = _blogPics; @synthesize blogSendTime = _blogSendTime; @synthesize blogAuthor = _blogAuthor; @synthesize blogCopy = _blogCopy; @synthesize commentsNums = _commentsNums; @synthesize copyNums = _copyNums; -(NSString *)description { NSString * str = [NSString stringWithFormat:@"blogContents is %@\n andPic is%@ \n and sendTime is %@\n and andAuthName is %@\n and AuthBirth is %@\n AccName is %@\n and AccPass is %@ and accRegTime is%@ andblogCopy conTent is%@ and Copy from %@\n",_blogContents,_blogPics,_blogSendTime,_blogAuthor.name,_blogAuthor.birth,_blogAuthor.account.accName,_blogAuthor.account.accPassword,_blogAuthor.account.accRegTime,_blogCopy.blogContents,_blogCopy.blogAuthor.name]; return str; } @end
main.m
#import <Foundation/Foundation.h> #import "blog.h" int main(int argc, const char * argv[]) { @autoreleasepool { // insert code here... CzxxAcc * acc_zhangsan = [[CzxxAcc alloc] initWithAccName:@"itcast" andPass:@"123456" andRegTime:@"2007-9-8 17£∫56£∫34" ]; CzxxAuthor * auth_zhangsan = [[CzxxAuthor alloc] init]; auth_zhangsan.name = @"张三˝"; auth_zhangsan.birth = @"11998-7-4 18:46:24"; auth_zhangsan.account = acc_zhangsan; CzxxQzone * blog_zhangsan = [[CzxxQzone alloc] init]; blog_zhangsan.blogContents = @"今天心情不错"; blog_zhangsan.blogPics = @"test.png"; blog_zhangsan.blogSendTime = @"2010-8-8 9:23:44"; blog_zhangsan.blogAuthor = auth_zhangsan; blog_zhangsan.blogCopy = nil; blog_zhangsan.commentsNums = 100; blog_zhangsan.copyNums = 290; blog_zhangsan.likeNums = 2000; NSLog(@"%@",blog_zhangsan); CzxxAcc * acc_lishi = [[CzxxAcc alloc] initWithAccName:@"lisiitcast" andPass:@"654321" andRegTime:@"2006-9-8 19£∫26£∫54" ]; CzxxAuthor *author_lishi = [[CzxxAuthor alloc] init]; author_lishi.name = @"李四"; author_lishi.birth = @"1999-9-6 14:16:28"; author_lishi.account = acc_lishi; CzxxQzone * blog_lishi = [[CzxxQzone alloc] init]; blog_lishi.blogContents = @"今天确实心情不错"; blog_lishi.blogPics = nil; blog_lishi.blogSendTime = @"2011-8-8 20:47:09"; blog_lishi.blogAuthor = author_lishi; blog_lishi.blogCopy = blog_zhangsan;//ƒø«∞√ª”–◊™∑¢ blog_lishi.commentsNums = 0; blog_lishi.copyNums = 0; blog_lishi.likeNums = 0; NSLog(@"%@",blog_lishi); } return 0; }
相关文章推荐
- OC - 9.基于Quartz2D绘制下载进度条(demo)
- oc 的一些概念
- [代码例程] iPhone开发入门(7)--- 从C/C++语言到Objective-C语
- IOS 面试习题 Object-C
- objective-c block 讲解
- IOS求职之OC面试题
- iOS OC和Swift混编
- OC_继承,初始化
- OC 省市区划分
- iOS开发 — Quartz 2D知识点应用 (制作了一个Demo,源代码)
- OC 自定义 get/set 方法注意点
- OC 书签管理系统
- 编写 Objective-C 代码/掌握基本的编程技能 之 读后笔记
- Swift 和 OC 混编
- 利用UIScrollView实现展示图片的无限滚动及自动滚动
- Objective-C 类,对象,属性,方法
- Objective - C 字符串 数组 字典 集合的基本使用
- 图形上下文解释CGContextSaveGState/CGContextRestoreGState
- Objective-C更改placeholder字体颜色
- Objective-C关键字self和super详解