标题:是哪一步错了?
只看楼主
益达999
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2016-10-11
 问题点数:0 回复次数:0 
是哪一步错了?
#include<iostream>
using namespace std;
class animal
{
public:
    animal(int);
    virtual ~animal(){cout<<"析构动物。。\n";}
    virtual int getage(){return itsage;}
    virtual void sleep()=0;
    virtual void propagate()=0;
    virtual void move()=0;
    virtual void body()=0;
    virtual void eat()=0;
    virtual void show()=0;
private:
    int itsage;
};
animal::animal(int age):itsage(age)
{
    cout<<"创建动物\n";
   
}
class mammalia:public animal
{
public:
    mammalia(int age):animal(age)
    {
        cout<<"创建哺乳类。。\n";
    }
    virtual ~mammalia()
    {
        cout<<"析构哺乳类。。\n";
    }
    virtual void propagate()
    {
        cout<<"哺乳类是胎生动物,通过拍泰来繁殖后代。\n";
    }

};
class pig:public mammalia
{
public:
    pig(int age):mammalia(age)
    {
        cout<<"创建猪类。。\n";
    }
    virtual ~pig()
    {
        cout<<"析构猪类,,\n";
    }
    virtual void sleep()
    {
        cout<<"猪喜欢在烂泥里睡觉。。\n";
    }
    virtual void eat()
    {
        cout<<"猪是杂食类动物。。\n";
    }
    virtual int show()
    {
        cout<<"因为猪长大要被人杀了吃,所以一般寿命是:"<<getage()<<endl;
    }
    virtual void propagate()
    {
        cout<<"猪也是通过胚胎繁殖后代,,\n";
    }
    virtual void move()
    {
        cout<<"猪朱是靠四条腿走路。。\n";
    }
    virtual void body()
    {
        cout<<"猪体表有毛。。\n";
    }

};
class human:public mammalia
{
public:
    human(int age):mammalia(age)
    {
        cout<<"创建人类。。\n";
    }
    virtual ~human()
    {
        cout<<"析构人类,,\n";
    }
    virtual void sleep()
    {
        cout<<"人喜欢在床上睡觉。。\n";
    }
    virtual void eat()
    {
        cout<<"大多数人不吃生食。。\n";
    }
    virtual int show()
    {
        cout<<"人类一般的寿命是:"<<getage()<<endl;
    }
    virtual void propagate()
    {
        cout<<"人也是通过胚胎繁殖后代,,\n";
    }
    virtual void move()
    {
        cout<<"人类是靠两条腿走路。。\n";
    }
    virtual void body()
    {
        cout<<"猪体表无毛。。\n";
    }

};
class bird:public animal
{
public:
    bird(int age):animal(age)
    {
        cout<<"创建鸟类。。\n";
    }
    virtual ~bird()
    {
        cout<<"析构鸟类。。\n";
    }
    virtual void propagate()
    {
        cout<<"鸟类是卵生动物,通过排卵来繁殖后代。\n";
    }
    virtual void sleep()
    {
        cout<<"鸟喜欢站着睡觉。。\n";
    }
    virtual void eat()
    {
        cout<<"大多数鸟类吃素。。\n";
    }
    virtual int show()
    {
        cout<<"鸟类一般的寿命是:"<<getage()<<endl;
    }
    virtual void move()
    {
        cout<<"鸟类可以飞。。\n";
    }
    virtual void body()
    {
        cout<<"鸟类体表被羽毛覆盖。。\n";
    }
};
int main()
{
    animal *p;
    int choice=0;
    while(1)
    {
        bool quit=false;
        cout<<"(1)猪类;(2)人类;(3)鸟类;(4)退出;\n 请选择类种:";
        cin>>choice;
        switch(choice)
        {
        case 1:p=new pig(1);
            break;
        case 2:p=new human(80);
            break;
        case 3:p=new bird(30);
            break;
        case 4:quit=true;
            cout<<"程序结束\n";
            break;
        default :quit=true;
            break;
        }
        if(quit)
        {
            break;
        }
        p->show();
        p->eat();
        p->propagate();
        p->move();
        p->sleep();
        p->body();
        cout<<"\n";
        delete p;

    }
     return 0;
}
搜索更多相关主题的帖子: private include public return animal 
2016-12-17 22:35



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-472538-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.676722 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved