码迷,mamicode.com
首页 > 其他好文 > 详细

实验五

时间:2019-05-31 23:43:43      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:cpp   mes   总结   ios   event   int   show   clu   ret   

技术图片
#ifndef MACHINEPETS_H
#define MACHINEPETS_H
#include <iostream>
#include <string>
using namespace std;
class MachinePets
{
      public:
          MachinePets(const string s);
          string getNickname();
          virtual string talk()=0;
      private:
           string Nickname;
};
#endif
MachinePets.h
技术图片
#include "MachinePets.h"
#include <iostream>
#include <string>
using namespace std;
MachinePets::MachinePets(const string s):Nickname(s){
}
string MachinePets::getNickname(){
    return Nickname;}
MachinePets.cpp
技术图片
#ifndef PETCATS_H
#define PETCATS_H
#include "MachinePets.h"
class PetCats:public MachinePets
{
public:
    PetCats(const string s);
    string talk();

private:
    string catname;
};
#endif
PetCats.h
技术图片
#include <iostream>
#include "MachinePets.h"
#include "PetCats.h"
using namespace std;
PetCats::PetCats(const string s):MachinePets(s){
}
string PetCats::talk(){
    return "miao wu~";}
PetCats.cpp
技术图片
#ifndef PETDOGS_H
#define PETDOGS_H
#include "MachinePets.h"
class PetDogs:public MachinePets
{
public:
    PetDogs(const string s);
    string talk();

private:
    string Nickname;
};
#endif
PetDogs.h
技术图片
#include <iostream>
#include "MachinePets.h"
#include "PetDogs.h"
using namespace std;
PetDogs::PetDogs(const string s):MachinePets(s){
}
string PetDogs::talk(){
    return "wang wang~";}
PetDogs.cpp
技术图片
#include <iostream>
#include <string>
#include "MachinePets.h"
#include "PetCats.h"
#include "PetDogs.h"
using namespace std;
void play(MachinePets *p)
{
    cout << p->getNickname() << " says " << p->talk() << endl;
}
int main()
{
    PetCats cat("miku");
    PetDogs dog("da huang");
    play(&cat);
    play(&dog);
    system ("pause");
    return 0;
}
main.cpp

总结:程序都是在课上完成的,回来运行时出现找不到play标识符,然后百度之后换了void和int main的顺序就对了

实验五

标签:cpp   mes   总结   ios   event   int   show   clu   ret   

原文地址:https://www.cnblogs.com/wmy0621/p/10957745.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!