objective吧 关注:379贴子:465
  • 7回复贴,共1

求大神帮我解决老师布置的作业

只看楼主收藏回复

关于objective c
创建一个person类,创建两个类钢琴家和小提琴家继承自person类,钢琴家用钢琴演奏音乐,小提琴家用小提琴演奏音乐,但是他们睡觉和吃饭的方式是一样的。
我表示题目我都看不懂


1楼2014-10-27 20:15回复
    。。建一个lifestyle父类,然后建两个子类:violin和piano二者继承lifestyle的方法:睡觉和吃饭。同时两个子类分别有自己的方法:钢琴奏音乐和小提琴奏音乐。


    来自iPhone客户端2楼2014-10-29 22:37
    回复
      基本构架就是这个,感觉这个吧大部分人都是凑热闹的,根本都不会。我问了三回问题了每一次别人给我解答


      来自iPhone客户端3楼2014-10-29 22:38
      收起回复
        //copyright by ads_zealot
        //written by ads use objc
        //2014 11 5-2014 11 6
        //main.m
        #include <Foundation/Foundation.h>
        int main(void) {
        typedef enum
        {
        Apiano,
        Aviolin,
        }Different_instruments;
        typedef enum
        {
        Aviolinist,
        Apianoist,
        }Different_musicions;
        //not used,you can delect it
        //or use it in the function"NSLog"
        typedef struct
        {
        Different_instruments instrument;
        Different_musicions musicion;
        }musicion;
        @interface Person:NSObject
        {
        Different_instruments instrument;
        Different_musicions musicion;
        }
        - (void) introMusicion:(Different_musicions) musicion;
        - (void) introInstrument:(Different_instruments) instrument;
        - (NSString) *Way_of_eat;
        - (NSString) *Way_of_sleep;
        - (NSString) *introLifestyle;
        - (void) intro;
        @implementation Person
        - (void)introMusicion:(Different_musicions)A
        {
        musicion = A;
        }
        - (void)introInstrument:(Different_instruments)D
        {
        instrument = D;
        }
        - (NSString) *Way_of_eat
        {
        return@"Eat three meals everyday.";
        }
        - (NSString) *Way_of_sleep
        {
        return@"Sleep at 10 o'clock everyday.";
        }
        - (NSString) *introLifestyle
        {
        return@"%@ %@",Way_of_eat,Way_of_sleep;
        }
        - (void) intro
        {}
        @interface Pianist:Person
        @end
        @implementation Pianist
        - (void) intro
        {
        NSLog(@"Pianist %@ and he play music by %@",
        introLifestyle,
        return_Name(S));
        }
        @end
        @interface Violinist:Person
        @end
        @implementation Violinist
        - (void) intro
        {
        NSLog(@"Violinist %@ and he play music by %@",
        introLifestyle,
        return_Name(S));
        }
        @end
        void Introduction_musicion(id musicion_types[],int count))
        {
        int i;
        for (i=0;i<count;i++)
        {
        id musicion_type=musicion_types[i];
        [musicion_type intro]
        }
        }
        NSString *return_Name(Different_instruments S)
        {
        switch (S)
        {
        case Apiano:return @"piano";break;
        case Aviolin:return @"violin";break;
        }
        return @"no cule";
        }
        int main(int argc,const char argv*[])
        {
        id Musicions[2];
        Musicions[0] = [Pinaoist new];
        [Musicions[0] introInstrument:Apinao];
        Musicions[1] = [Violinist new];
        [Musicions[1] introInstrument:Aviolin];
        Introduction_musicion(Musicion,2);
        return 0;
        }


        来自iPhone客户端4楼2014-11-06 11:46
        回复
          把import下面的int main去掉


          来自iPhone客户端5楼2014-11-08 10:25
          回复
            楼上不错


            来自iPhone客户端6楼2015-04-12 14:00
            回复