#include <stdio.h>
#include <tchar.h>
#include <stdio.h>
#include <windows.h>
#include <string>
#include <iostream>
using namespace std;
class Pet
{
public:
Pet(void);
Pet(string,int,int,string);
~Pet(void);
string GetNickName();
int GetHealth();
int GetLove();
string GetSex();
void SetHeaht(int health);
void SetLove(int love);
virtual void Eat(string food);
virtual void Play(string toy);
void Info();
private:
string nickName;
int health;
int love;
string sex;
};
class Cat :
public Pet
{
public:
Cat(void);
Cat(string nickName,int health,int love,string sex);
~Cat(void);
void Eat(string food);
void Play(string toy);
};
class Dog :
public Pet
{
public:
Dog(void);
Dog(string nickName,int health,int love,string sex);
~Dog(void);
void Eat(string food);
void Play(string toy);
};
class Player
{
public:
Player(void);
Player(string name);
~Player(void);
string GetName();
void Feed(Pet* pet,string food);
void PlayWith(Pet* pet,string toy);
private:
string name;
};
Cat::Cat(void)
{
}
Cat::Cat(string nickName,int health,int love,string sex):Pet(nickName,health,love,sex)
{
}
Cat::~Cat(void)
{
}
void Cat::Eat(string food)
{
SetLove(GetLove()-5);
SetHeaht(GetHealth()+5);
cout<<"\t\t 猫"<<GetNickName()<<"正在吃"<<food<<endl;
}
void Cat::Play(string toy)
{
SetLove(GetLove()+10);
SetHeaht(GetHealth()-10);
cout<<"\t\t 猫"<<GetNickName()<<"正在玩"<<toy<<endl;
}
Dog::Dog(void)
{
}
Dog::Dog(string nickName,int health,int love,string sex):Pet(nickName,health,love,sex)
{
}
Dog::~Dog(void)
{
}
void Dog::Eat(string food)
{
SetLove(GetLove()-10);
SetHeaht(GetHealth()+10);
cout<<"\t\t 狗"<<GetNickName()<<"正在吃"<<food<<endl;
}
void Dog::Play(string toy)
{
SetLove(GetLove()+15);
SetHeaht(GetHealth()-15);
cout<<"\t\t 狗"<<GetNickName()<<"正在玩"<<endl;
}
Pet::Pet(void)
{
}
Pet::Pet(string nickName,int health,int love,string sex)
{
this->nickName = nickName;
this->health = health;
this->love =love;
this->sex = sex;
}
Pet::~Pet(void)
{
}
string Pet::GetNickName()
{
return nickName;
}
int Pet::GetHealth()
{
return health;
}
int Pet::GetLove()
{
return love;
}
string Pet::GetSex()
{
return sex;
}
void Pet::SetHeaht(int health)
{
this->health = health;
}
void Pet::SetLove(int love)
{
this->love = love;
}
void Pet::Eat(string food)
{
cout<<"\t\t 宠物"<<nickName<<"正在吃"<<food<<endl;
}
void Pet::Play(string toy)
{
cout<<"\t\t 宠物"<<nickName<<"正在玩"<<toy<<endl;
}
void Pet::Info()
{
cout<<"\t\t 宠物"<<nickName<<",性别:"<<sex<<",健康值:"<<health<<",亲密度:"<<love<<endl;
}
Player::Player(void)
{
}
Player::Player(string name)
{
this->name = name;
}
Player::~Player(void)
{
}
string Player::GetName()
{
return name;
}
void Player::Feed(Pet* pet,string food)
{
pet->Eat(food);
pet->Info();
}
void Player::PlayWith(Pet* pet,string toy)
{
pet->Play(toy);
pet->Info();
}
int _tmain(int argc, _TCHAR* argv[])
{
cout<<"\n\n\n\n\t\t==========欢迎来到机电学院宠物乐园=========="<<endl;
cout<<"\n\n\t\t\t 请输入您的名字:";
string name;
cin>>name;
system("cls");
Player* player =new Player(name);
cout<<"\n\n\n\n\n\n\t\t\t\t 欢迎您:"<<player->GetName()<<endl;
while(1==1){
cout<<"\n\t\t 请选择宠物类型:1.狗 2.猫 3.退出:";
int choosePet,chooseSex;
cin>>choosePet;
if(choosePet==3)
{
break;
}
string petName,sex;
cout<<"\n\t\t 请选择宠物的性别:1.公 2.母:";
cin>>chooseSex;
if(chooseSex==1)
{
sex="公";
}else
{
sex="母";
}
cout<<"\n\t\t 请给您的宠物取个名字吧:";
cin>>petName;
system("cls");
Pet* pet;
if (choosePet==1)
{
pet = new Dog(petName,50,50,sex);
}
else if(choosePet==2)
{
pet = new Cat(petName,50,50,sex);
}
while(1==1)
{
cout<<"\n\n\n\n\n\n\n\n\n\t\t 请选择操作:1.喂,2.玩,3,返回:";
int index;
cin>>index;
if (index==1)
{
string food ;
player->Feed(pet,food);
}else if(index==2)
{
string toy;
player->PlayWith(pet,toy);
}else
{
system("cls");
break;
}
}
}
cout<<"谢谢使用"<<endl;
system("pause");
return 0;
}
没有合适的资源?快使用搜索试试~ 我知道了~
宠物领养(c++) 控制台界面
共54个文件
tlog:34个
manifest:2个
pdb:2个
需积分: 1 10 下载量 134 浏览量
2017-08-14
14:24:14
上传
评论 2
收藏 13.85MB RAR 举报
温馨提示
自己做的简易宠物领养小程序
资源推荐
资源详情
资源评论
收起资源包目录
Pet.rar (54个子文件)
Pet
Pet.suo 11KB
Pet.sdf 27.83MB
Pet
Pet.vcxproj.user 143B
pet.cpp 4KB
Pet.vcxproj.filters 941B
Pet.vcxproj 4KB
Debug
link.7392.write.1.tlog 2B
vc100.idb 531KB
Pet.lastbuildstate 108B
Pet.log 2KB
link.9908-cvtres.read.1.tlog 2B
link.10644.write.1.tlog 2B
link.10644-cvtres.read.1.tlog 2B
CL.write.1.tlog 596B
link.9908-cvtres.write.1.tlog 2B
CL.read.1.tlog 21KB
mt.read.1.tlog 478B
rc.write.1.tlog 458B
rc.read.1.tlog 450B
Pet.exe.embed.manifest 406B
link.9908.read.1.tlog 2B
link.7392-cvtres.read.1.tlog 2B
link.4252.read.1.tlog 2B
link.9908.write.1.tlog 2B
mt.command.1.tlog 448B
cl.command.1.tlog 822B
link-cvtres.read.1.tlog 2B
link.7392.read.1.tlog 2B
link.write.1.tlog 1KB
link.4252-cvtres.write.1.tlog 2B
Pet_manifest.rc 196B
link.10488-cvtres.write.1.tlog 2B
link-cvtres.write.1.tlog 2B
pet.obj 198KB
link.command.1.tlog 2KB
rc.command.1.tlog 664B
link.read.1.tlog 3KB
link.7392-cvtres.write.1.tlog 2B
Pet.exe.embed.manifest.res 472B
link.10488.read.1.tlog 2B
link.10644.read.1.tlog 2B
link.4252.write.1.tlog 2B
mt.write.1.tlog 478B
link.10488.write.1.tlog 2B
link.10644-cvtres.write.1.tlog 2B
link.4252-cvtres.read.1.tlog 2B
link.10488-cvtres.read.1.tlog 2B
Pet.exe.intermediate.manifest 381B
vc100.pdb 292KB
Pet.sln 876B
ipch
pet-a0df2b88
pet-9e911655.ipch 43.81MB
Debug
Pet.pdb 915KB
Pet.exe 78KB
Pet.ilk 568KB
共 54 条
- 1
资源评论
王小川啦啦啦
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功