#宠物 #includeiostream #include string #include cstdlib using namespace std;#ifndef MACHINEPETS_H #define MACHINEPETS_H class MachinePets{ public : MachinePets( const string s); virtual string talk() const = 0 ; string getNickname(); virt
#宠物
#include<iostream> #include<string> #include<cstdlib> using namespace std; #ifndef MACHINEPETS_H #define MACHINEPETS_H class MachinePets { public: MachinePets(const string s); virtual string talk() const=0; string getNickname(); virtual ~MachinePets(); private: string nickname; }; #endif MachinePets::MachinePets(const string s):nickname(s) { } string MachinePets::getNickname() { return nickname; } MachinePets::~MachinePets() { } #ifndef PETCATS_H #define PETCATS_H class PetCats:public MachinePets { public: PetCats(const string s); string talk() const; ~PetCats(); }; #endif PetCats::PetCats(const string s):MachinePets(s) { } string PetCats::talk() const { cout<<"words:"; return "wu~"; } PetCats::~PetCats() { } #ifndef PETDOGS_H #define PETDOGS_H class PetDogs:public MachinePets { public: PetDogs(const string s); string talk() const; ~PetDogs(); }; #endif PetDogs::PetDogs(const string s):MachinePets(s) { } string PetDogs::talk() const { cout<<"words:"; return "wang wang~"; } PetDogs::~PetDogs() { } void play(MachinePets *pet) { cout<<pet->getNickname()<<"says"<<pet->talk()<<endl; } int main() { PetCats cat("miku"); PetDogs dog("dahuang"); play(&cat); play(&dog); return 0; }MACHINEPETS
[修改]
void play(MachinePets *pet) { cout<<pet->getNickname()<<" says "<<pet->talk()<<endl; }
这里说声抱歉,因为本来是插的项目,然后把音频的那段删了,所以,搬过来一言难尽。
[运行结果]
#游戏
//第一空 #ifndef _CONTAINER // Conditional compilation
bool container::useHeal() { //第二空 numOfHeal--; return 1; // use heal successfully }
//第三空,这里默认p为失败者,由于背包里面就定义了小蓝和小红,所以就这样趴~ bag.set(bag.nOfHeal()+p.bag.nOfHeal(),bag.nOfMW()+p.bag.nOfHeal()); p.bag.set(0,0); // set the character‘s bag, get opponent‘s items
// display character‘s job //第四空 void showinfo(player &p1, player &p2)
//第五空 class swordsman : public player // subclass swordsman publicly inherited from base player
//第六空,即将退出 cout<<endl<<setw(50)<<"You‘re about to quit"<<endl; // player is dead, program is getting to its end, what should we do here?
//第七空,通关 cout<<endl<<setw(50)<<"Clearance"<<endl; // You win, program is getting to its end, what should we do here?
【实验总结】
嗯,这次做的有点匆忙,有什么不太好的地方见谅~不过可以指出来鸭~
说一下这次实验吧,前面验证性的应该是比较基础的,比较容易理解,宠物那道题的音频因为没法插音频文件的原因,就没把那段代码发上来,参考网址我会在明天发上来,今天有点晚了~
最后那道游戏,emmm,个人感觉其实还是比较容易看得懂的。大概是英语太菜了?有些很长很长的注释全靠百度翻译活命~还有就是最后填的那几个空也是百度翻译过来的,所以看不懂什么意思很正常,我也不太清楚用词恰不恰当,与你无瓜鸭~还有就是插的诸多头文件就没放进来了。
[一个问题]
救救孩子吧,博客园怎么把文件放进来,或者大佬们的运行视频是怎么搞进来的,我录了一下,放不进来,找不到文件在哪插的(PS:我百度过了,被自己傻哭了~)