ios8第1天答案2
来源:互联网 发布:js动态创建节点 编辑:程序博客网 时间:2024/06/08 07:42
编程题2
/*结合前面的“狗”类,设计一个“人”类
1> 属性
姓名
狗(养了一条狗)
2> 行为
喂狗:每喂一次,狗就会执行“吃”这个行为
遛狗:每溜一次,狗就会执行“跑”这个行为*/
person.h
#ifndef Person_h#define Person_h#import <Foundation/Foundation.h>#import "dog.h"@interface Person : NSObject{@public NSString *name; Dog *pet_dog;}- (void)FeedDog;- (void)WalkDog;@end#endif /* Person_h */
person.m
#import <Foundation/Foundation.h>#import "dog.h"#import "person.h"@implementation Person- (void)FeedDog{ NSLog(@"%@ 喂狗",name); [pet_dog Eat];}- (void)WalkDog{ NSLog(@"%@ 溜狗",name); [pet_dog Run];}@end
main.m
#import <Foundation/Foundation.h>#import "dog.h"#import "Person.h"int main(int argc, const char * argv[]) { @autoreleasepool { // insert code here... Dog *dog_st = [Dog new]; dog_st->color = @"红色"; dog_st->speed = 5.0f; dog_st->sex = @"雌性"; dog_st->weight = 20.0f; Dog *dog_nd = [Dog new]; dog_nd->color = @"红色"; dog_nd->speed = 6.0f; dog_nd->sex = @"雌性"; dog_nd->weight = 21.0f; [dog_st Eat]; [dog_st Bark]; [dog_st Run]; [dog_st CmpColor:dog_nd]; [dog_st CmpSpeed:dog_nd]; Person *person = [Person new]; person->name = @"希尔薇"; person->pet_dog = dog_st; [person FeedDog]; [person WalkDog]; } return 0;}
3
/*设计一个”学生“类
1> 属性
姓名
生日
年龄
身高(单位是m)
体重(单位是kg)
性别
C语言成绩
OC成绩
iOS成绩
2> 行为
跑步:每跑步一次,身高增加1cm,体重减小0.5kg,输出跑完后的体重
吃饭:每吃一次,身高增加1cm,体重增加0.5kg,输出吃完后的体重
学习:每学习一次,3可成绩各加1分,输出学习完后的3科成绩
睡觉:输出所有的属性
比较C语言成绩:跟另外一个学生比较C语言成绩,返回成绩差(自己的成绩 - 其他人的成绩)
比较OC成绩:跟另外一个学生比较OC语言成绩,返回成绩差(自己的成绩 - 其他人的成绩)
比较iOS成绩:跟另外一个学生比较iOS语言成绩,返回成绩差(自己的成绩 - 其他人的成绩)
计算总分:算出3科成绩的总分
计算平均分:算出3科成绩的平均分*/
student.h
#ifndef student_h#define student_h#import <Foundation/Foundation.h>typedef enum{ stu_male = 0, stu_female = 1, stu_ry = 2,}STU_SEX;@interface Student: NSObject{@public NSString *name; NSString *birthday; int age; float height; float weight; STU_SEX sex; float c_scores; float oc_scores; float ios_scores;}- (void)Run;-(void)Eat;-(void)Study;-(void)Sleep;-(double)CmpCscores:(Student*) pStu;-(double)CmpOCscores:(Student*) pStu;-(double)CmpIOSscores:(Student*) pStu;@end#endif /* student_h */
student.m
#import <Foundation/Foundation.h>#import "student.h"#import <Foundation/Foundation.h>@implementation Student- (void)Run{ height += 0.01; weight -= 0.5; NSLog(@"身高:%g m", height); NSLog(@"体重:%g kg",weight);}- (void)Eat{ height += 0.01; weight += 0.5; NSLog(@"after eat height :%g", height ); NSLog(@"after eat weight:%g",weight);}-(void)Study{ c_scores += 1; oc_scores += 1; ios_scores += 1; NSLog(@"after Study 各科成绩:%f,%f,%f,(顺序c,oc,ios)", c_scores , oc_scores , ios_scores );}-(void)Sleep{ NSLog(@"姓名:%@",name); NSLog(@"生日:%@",birthday); NSLog(@"年龄:%d",age); NSLog(@"身高:%f m",height); NSLog(@"体重:%f kg",weight); NSLog(@"性别:%d",sex); NSLog(@"C语言成绩:%f", c_scores); NSLog(@"OC语言成绩:%f", oc_scores); NSLog(@"IOS语言成绩:%f", ios_scores);}-(double)CmpCscores:(Student*) pStu;{ if(c_scores >= pStu-> c_scores ) { return c_scores - pStu-> c_scores; } else { return pStu-> c_scores -c_scores; }}-(double)CmpOCscores:(Student*) pStu;{ if(c_scores >= pStu-> oc_scores ) { return oc_scores - pStu-> oc_scores ; } else { return pStu-> oc_scores - oc_scores ; }}-(double)CmpIOSscores:(Student*) pStu{ if(ios_scores >= pStu-> ios_scores) { return ios_scores - pStu-> ios_scores; } else { return pStu-> ios_scores - ios_scores; }}-(double)CalculateTotal{ return c_scores+ oc_scores+ ios_scores;}-(double)CalculateAvg{ double totalscores = [self CalculateTotal]; return totalscores/3;}@end
main.m
#import <Foundation/Foundation.h>#import "student.h"int main(int argc, const char * argv[]) { @autoreleasepool { // insert code here... Student *stu = [Student new]; stu->name = @"zxx"; stu->birthday = @"1985-03-23"; stu->age = 30; stu->height = 1.75; stu->weight = 160; stu->sex = stu_male; stu->c_scores = 75.5; stu->oc_scores = 90.0; stu->ios_scores = 88.0; [stu Run]; [stu Eat]; [stu Study]; [stu Sleep]; Student *stu_cmp = [Student new]; stu_cmp->name = @"zxx1"; stu_cmp->birthday = @"1985-03-23"; stu_cmp->age = 22; stu_cmp->height = 1.75; stu_cmp->weight = 160; stu_cmp->sex = stu_male; stu_cmp->c_scores = 73.5; stu_cmp->oc_scores = 94.0; stu_cmp->ios_scores = 80.0; double cmp_cscores=[stu CmpCscores:stu_cmp]; NSLog(@"cmp_scores=%f",cmp_cscores); double cmp_ocscores=[stu CmpOCscores:stu_cmp]; NSLog(@"cmp_ocscores=%f",cmp_ocscores); double cmp_iosscores=[stu CmpIOSscores:stu_cmp]; NSLog(@"cmp_iosscores=%f",cmp_iosscores); } return 0;}
进入day02视频
0 0
- ios8第1天答案2
- ios8 第一天答案
- 第1章 绪论(答案)
- 永久勘误:微软等面试100题答案V0.2版[第1-20题答案]
- 永久勘误:微软等面试100题答案V0.2版[第1-20题答案]
- 微软等面试100题答案V0.2版[第1-20题答案]
- 第2章 线性表(答案)
- 《Python核心编程》第1章答案
- Xcode9.2 运行iOS8.1图片异常
- 程序设计教程第二版(钱能)1.9 练习1 第2题个人练习答案
- 新视野大学英语(第2版)答案
- 《统计建模与R软件》练习答案-第2章
- 算法竞赛入门经典 第2章 习题答案
- 编程珠玑第2章部分课后习题答案注解
- 线性表-第2章-《数据结构习题集》答案解析-严蔚敏吴伟民版
- 快学Scala练习题答案-第2章
- 编译原理/紫龙书(第2版) 答案 1.1
- 编译原理/紫龙书(第2版) 答案 1.3
- Js-Html 前端系列--点击非Div区域隐藏Div
- JPA hibernate spring repository pgsql java 工程(一)环境配置和工程部署
- 欢迎来到 Apache Hadoop®!
- 跨浏览器解决事件处理程序兼容问题
- Trapping Rain Water
- ios8第1天答案2
- 《深入理解计算机系统》Tiny Web服务器实验
- 关于Java泛型的小知识点
- VS内存断点
- AsyncTask的简单用法和实例
- Java:十进制转十六进制
- tddl diamond配置
- ubuntu 安装iconv 库
- stm32学习之环境搭建