需要类似面向对象程序

1)Aquatic类
Aquatic类中继承了Animal的属性并定义了自己的属性有无脊椎
//Aquatic.h
#include
using namespace std;
#include"Animal.h"
#ifndef MENU
#define MENU
class Aquatic:virtual public Animal
{
public:
string Vertebra;
set1(string co,string sx,int ag,string Ve);

void show1();
void play()
{
    cout<<"水生动物喜欢游泳"<<endl;
};

};
#endif
//Aquatic.cpp
#include"Aquatic.h"
Aquatic::set1(string co,string sx,int ag,string Ve)
{
color=co;
sex=sx;
age=ag;
Vertebra=Ve;
}
void Aquatic::show1()
{
cout<<"水生动物的的颜色是:"< }
2)Frog类
Frog类继承了Aquatic类的属性,并定义了自己的属性生殖方式
//Frog.h
#include
using namespace std;
#include"Aquatic.h"
#ifndef WANG
#define WANG
class Frog:virtual public Aquatic
{
public:
string Reproductive;
void set2(string co,string sx,int ag,string Ve,string Re);
void show2();
void play()
{
cout<<"青蛙爱跳"< };
};
#endif
//Frog.cpp
#include"Frog.h"
void Frog::set2(string co,string sx,int ag,string Ve,string Re)
{
color=co;
sex=sx;
age=ag;
Vertebra=Ve;
Reproductive=Re;
}
void Frog::show2()
{
cout cout }
3)Fish类
Fish类继承了Aqutic类的属性,并定义了自己的属性上课,并在Fish类中设置静态成员,有游泳动物的成绩,游泳动物的个数,游泳动物所用的时间,,运用了静态函数,构造函数,析构函数
//Fish.h
#include
using namespace std;
#include"Aquatic.h"
class Fish:virtual public Aquatic
{
public:
string Reproductive;
string length;
void set3(string co,string sx,int ag,string Ve,string Re,int le);
void show3();
void show0();
void play()
{
};
int score1;
static int totaltime;
static int sum;
static getave();
Fish(int no,int sco);
Fish();
Fish::~Fish();
};
//Fish.cpp
#include"Fish.h"
void Fish::set3(string co,string sx,int ag,string Ve,string Re,int le)
{
color=co;
sex=sx;
age=ag;
Vertebra=Ve;
Reproductive=Re;
length=le;
}
void Fish::show3()
{
cout<<"水生动物的颜色是:"< cout }
void Fish::show0()
{
cout cout cout }
Fish::Fish(int Ve,int sco)
{
Vertebra=Ve;
score1=sco;
sum++;
totaltime+=sco;
}
Fish::Fish()
{
cout }
Fish::~Fish()
{
sum--;
totaltime-=score1;
}
int Fish::getave()
{
return totaltime/sum;
}
4)Terrestrial类
Terrestrial类继承了Animal的属性,并定义了自己的高度
//Terrestrial.h
#include
using namespace std;
#include"Animal.h"
class Terrestrial:virtual public Animal
{
public:
int Height;
void set4(string co,string sx,int ag,int he);
void play()
{
cout<<"陆生动物喜欢跑步"< }
void show4();
};
//Terrestrial.cpp
#include"Terrestrial.h"
void Terrestrial::set4(string co,string sx,int ag,int he)
{
color=co;
sex=sx;
age=ag;
Height=he;
}
void Terrestrial::show4()
{
cout cout }
5)Amphibian类
Amphibian类继承了Frog类和Terrestrial类的属性,并定义了自己的属性喜欢的事
//Amphibian.h
#include
using namespace std;
#include
#include"Frog.h"
#include"Terrestrial.h"
class Amphibian:public Frog,public Terrestrial
{
public:
string favorate;
void play();
void set5(string co,string sx,int ag,string Ve,string Re,int he,string favorate);
void show5();

};
//Amphibian.cpp
#include"Amphibian.h"
void Amphibian::set5(string co,string sx,int ag,string Ve,string Re,int he,string favorate)
{
color=co;
sex=sx;
age=ag;
Vertebra=Ve;
Reproductive=Re;
Height=he;
favorate=favorate;
}
void Amphibian::play()
{
cout<<"两栖动物喜欢睡觉"< }
void Amphibian::show5()
{
cout cout cout cout cout }
6)Data类
Data类用于重载输入输出流,输入输出青蛙的腿的个数
//Data.h
#include
using namespace std;
class Date
{
public:
int Fyear;
friend ostream& operator<<(ostream&,Date &);
friend istream& operator>>(istream&,Date &);
};
//Data.cpp
#include"Data.h"
ostream& operator<<(ostream& output,Date &t0)
{
output<<"青蛙腿的个数:"< return output;
}
istream& operator>>(istream& input,Date &t0)
{
cout<<"input Fyear of a date: ";
input>>t0.Fyear;
return input;
}
7)Animal类
在Animal类中定义了动物的颜色,性别,年龄,定义了纯虚函数
//Animal.h
#ifndef SADF
#define SADF
#include
using namespace std;
#include
class Animal
{
public:
string color;
string sex;
int age;
void set0(string co,string sx,int ag);
virtual void play()=0;
void show();
};
#endif
//Animal.cpp
#include"Animal.h"
void Animal::set0(string co,string sx,int ag)
{
color=co;
sex=sx;
age=ag;
}
void Animal::show()
{
cout< }
8)menu类
menu类用于做各个类的菜单,可以便捷查找各个类的信息
//menu.h
#include
class menu
{
public:
int menu_select();
void handle_menu();
h1();
h2();
h3();
h4();
h5();
h6();
};
//menu.cpp
#include
using namespace std;
#include
#include"menu.h"
#include"Amphibian.h"
#include"Fish.h"
#include"Data.h"
void menu::handle_menu()
{

for(int i=0;i<=6;i++)
{
switch (menu_select())
{

case 1:h1();break;
case 2:h2();break;
case 3:h3();break;
case 4:h4();break;
case 5:h5();break;
case 6:h6();break;
case 7: cout<<"\t再见!\n";
return;
}
}

}
int menu::menu_select()
{
char s[2];
int cn;
cout<<"\t1. 建立水生动物并显示 \n";
cout<<"\t2. 建立青蛙并显示 \n";
cout<<"\t3. 建立鱼并显示 \n";

cout<<"\t4. 建立陆生动物并显示 \n";
cout<<"\t5. 建立两栖动物并显示 \n";
cout<<"\t6. 输入腿的个数并显示\n";
cout<<"\t7.退出程序\n";
cout<<"\t选择1-7 \n";
for ( ; ;)
{
gets(s);
cn=atoi(s);
if (cn7) cout<<"\t输入错误,重选1-7\n";
else break;
}
return cn;
}
menu::h1()//水生动物类
{

Animal *an;
Aquatic aq;
an=&aq;
an->play();
Aquatic aquatic1;
aquatic1.set1("绿色","雌",3,"有");
aquatic1.show1();
}
menu::h2()//青蛙类
{
Animal *an;
Frog fr;
an=&fr;
an->play();
Frog b;
b.set2("绿色","雄",1,"有","卵生");
b.show2();
}
menu::h3()//鱼类
{
Fish f;
f.set3("金色","雌",1,"有","卵生",20);
f.show0();
Fish fi(10,20);
fi.show3();
}
menu::h4()//陆生动物类
{
Animal *an;
Terrestrial te;
an=&te;
an->play();
Terrestrial t;
t.set4("黄色","雄",1,40);
t.show4();
}
menu::h5()//两栖类
{
Amphibian a;
a.set5("橘黄色","雄",5,"有","卵生",30,"睡觉");
a.show5();
}
menu::h6()//
{
Date t01;
cin>>t01;
cout<<"青蛙腿的个数:"<<t01<<endl;
}

1个回答

啥意思啊,,把你的程序,给你换成面向对象的。。。??

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐