第十/十一周训练4-1

#include<iostream>
#include<string>
using namespace std;
class Person
{
private:
int age;
string name;
public:
Person(int ag,string na):age(ag),name(na){}
void action()
{
cout<<age<<"   "<<name<<endl;
}
};
class Polic:public Person
{
private:
int level;
public:
Polic(int ag,string na,int le):Person(ag,na),level(le){}
void arrest()
{
action();
cout<<level<<endl;
}
};
class Cook:public Person
{
private:
double salary;
public:
Cook(int ag,string na,double sa):Person(ag,na),salary(sa){}
void getCake()
{
action();
cout<<salary<<endl;
}
};
int main()
{
    Polic A(1,"asd",3);
A.arrest();
Cook B(4,"qwrr",6);
B.getCake();
}

你可能感兴趣的:(第十/十一周训练4-1)