音乐家演奏乐器
2015-07-29 19:50
351 查看
Main.m
Actor.h
Actor.m
Instrument.h
Instrument.m
Piano.m
#import <Foundation/Foundation.h> #import "Piano.h" #import "Violin.h" #import "Actor.h" /* 乐器(Instrument)分为:钢琴(Piano)、小提琴(Violin)。 各种乐器的弹奏( play )方法各不同样。演奏家能够使用各种乐器。 */ int main(int argc, const char * argv[]) { //创建演奏者和乐器 Actor *actor = [[Actor alloc] init]; Piano *piano = [[Piano alloc] init]; Violin *violin = [[Violin alloc] init]; int cmd; NSLog(@"请输入须要使用的乐器:"); scanf("%d",&cmd); if (cmd == 1) { [actor playWithInstrument:piano]; }else if (cmd == 2) { [actor playWithInstrument:violin]; }else { NSLog(@"输入有误"); } return 0;
Actor.h
//使用乐器演奏的方法 - (void)playWithInstrument:(Instrument *)instrument;
Actor.m
//使用乐器演奏的方法 - (void)playWithInstrument:(Instrument *)instrument { [instrument play]; }
Instrument.h
@interface Instrument : NSObject //演奏 - (void)play;
Instrument.m
//演奏 - (void)play { NSLog(@"乐器演奏"); }
Piano.m
//演奏 - (void)play { NSLog(@"钢琴演奏"); }Violin.m
//演奏 - (void)play { NSLog(@"小提琴演奏"); }
相关文章推荐
- 对应用程序域的浅显理解
- LBS根据经纬查看附近商家的实现
- uvalive 4992(半平面交+二分)
- 41 - 找出数组中和为sum的 2个数字 | 找出和为sum的连续正整数序列
- IOS的后台的持续定位
- HDOJ 2642 Stars
- 【POJ】1364 King
- POJ 2965 The Pilots Brothers' refrigerator (想法题)
- vs2015安装使用体验
- CFrameWnd的两个函数
- HDOJ 3966 Aragorn's Story
- 快速排序 c++
- hdu 5325 Crazy Bobo (树形dp)
- 关于cassandra vnode的理解-marsyoung.
- 排序算法的稳定性讨论
- 【CodeForces】E. Xenia and Tree(分块 + LCA)
- Trim(),TrimStart(),TrimEnd()用于去除字符串中的特定字符
- 多校第三场 1010 hdu 5325 Crazy Bobo(拓扑排序+树形dp)
- linux防火墙基础和管理设置iptables规则
- java中的并发:线程通信