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

实验五

时间:2019-06-01 19:45:54      阅读:81      评论:0      收藏:0      [点我收藏+]

标签:string   ios   dbf   hide   int   play   void   amp   define   

技术图片
#include <iostream>
#include "MachinePets.h"
#include "PetCats.h"
#include "PetDogs.h"
#include <string>
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);
    
    return 0;
}
main.cpp
技术图片
#ifndef PETDOGS_H
#define PETDOGS_H
#include "MachinePets.h"
#include <string>
using namespace std;

class PetDogs:public MachinePets{
public:
    PetDogs(const string s);
    string talk();
};

#endif
PetDogs.h
技术图片
#include <iostream>
#include "PetDogs.h"
#include <string>
using namespace std;

PetDogs::PetDogs(const string s):MachinePets(s){
}
    
string PetDogs::talk(){
    cout<<"says wang wang~"<<endl;
}
PetDogs.cpp
技术图片
#include <iostream>
#include "PetDogs.h"
#include <string>
using namespace std;

PetDogs::PetDogs(const string s):MachinePets(s){
}
    
string PetDogs::talk(){
    cout<<"says wang wang~"<<endl;
}
PetCats.h
技术图片
#include "MachinePets.h"
#include "PetCats.h"
#include <string>
#include <iostream>
using namespace std;

PetCats::PetCats(const string s):MachinePets(s){
}

string PetCats::talk(){
    cout<<"says miao wu~"<<endl;
}
PetCats.cpp
技术图片
#ifndef MACHINEPETS_H
#define MACHINEPETS_H
#include <string>
#include <iostream>
using namespace std;

class MachinePets{
private:
    string nickname;
public:
    MachinePets(const string s);
    string getNickname();
    virtual string talk()=0;
};

#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

技术图片

 

实验五

标签:string   ios   dbf   hide   int   play   void   amp   define   

原文地址:https://www.cnblogs.com/sunny0202/p/10960561.html

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