/*copyright(c)2016.烟台大学计算机学院 * All rights reserved, * 文件名称:text.Cpp * 作者:舒文超 * 完成日期:2016年4月30日 * 版本号:vc++6.0 * 问题描述:(1)根据下面的类图,定义各个类: 这里写图片描述。(图片见附件) 要求:各个成员函数,只要输出相关的信息即可, 暂不深究其业务功能请为各个类增加构造函 数在实现中,可以增加需要的其他函数自行 编制main函数,完成初步的测试。 */ #include <iostream> using namespace std; class Person { public: Person(int a, string n,string w):age(a),name(n),work(w){} void action(); string getName() { return name; } private: int age; string name; string work; }; void Person::action() { cout<<name<<" is a "<<work<<"."<<endl; } class Police: public Person { public: Police(int a, string n,string w, int l); void arrest(Person); private: int level; //级别 }; Police::Police(int a,string n,string w,int l):Person(a,n,w),level(l){} void Police::arrest(Person p) { action(); cout<<"Police "<<getName()<<" arrest " <<p.getName()<<endl; } class Cook: public Person { public: Cook(int a, string n,string w,double s); void getCake(int,Person); private: double salary; //薪水 }; Cook::Cook(int a, string n,string w,double s):Person(a,n,w),salary(s){} void Cook::getCake(int n,Person p) { action(); cout<<"Cooker "<<getName()<<" gave "<<p.getName()<<" "<<n<<" cakes."<<endl; } int main() { Person Bob(120,"Bob","public"); Police Tom(30,"Tom","police",2); Cook Jason(24,"Jason","cooker",5000); Tom.arrest(Bob); Jason.getCake(6,Bob); return 0; }