警察与厨师2

来源:互联网 发布:mac ps4手柄设置 编辑:程序博客网 时间:2024/04/28 05:23
#include <iostream>  
  
using namespace std;  
class Person  
{  
public:  
    Person(int a,string nam);  
    void action();  
    string getname(){return name;}  
protected:  
    int age;  
    string name;  
};  
Person::Person(int a,string nam):age(a),name(nam){}  
void Person::action()  
{  
    cout<<"姓名:"<<name<<endl;  
    cout<<"年龄:"<<age<<endl;  
}  
class Police:public Person  
{  
public:  
    Police(int a,string nam,int l);  
    void arrest(Person);  
private:  
    int level;  
};  
Police::Police(int a,string nam,int l):Person(a,nam),level(l){}  
void Police::arrest(Person p)  
{  
    cout<<"Police"<<name<<" arrest "<<p.getname()<<endl;  
}  
class Cook:public Person  
{  
public:  
    Cook(int a,string nam,double s);  
    void getCake(int );  
private:  
    double salary;  
};  
Cook::Cook(int a,string nam,double s):Person(a,nam),salary(s){}  
void Cook::getCake(int n)  
{  
    cout<<name<<" cook "<<n<<" cake."<<endl;  
}  
int main()  
{  
    Person tom(120,"Tom");  
    Police jack(30,"Jack",2);  
    Cook john(24,"John",5000);  
    jack.arrest(tom);  
    john.getCake(4);  
    return 0;  
}  
0 0
原创粉丝点击