/* *Copyright(c) 2016, 烟台大学计算机与控制工程学院 *All rights reserved. *文件名称:main.cpp *作 者:李德坤 *完成日期:2016年5月1日 *版本号:v1.0 * *问题描述:各个成员函数,只要输出相关的信息即可,暂不深究其业务功能 请为各个类增加构造函数 在实现中,可以增加需要的其他函数 自行编制main函数,完成初步的测试 为Polic类和Cook类增加了对象成员,请扩充代码 *输入描述:无 *输出描述:按要求输出 */ #include<iostream> using namespace std; class Person { protected: int age; string name; public: Person(int a,string nam); void show(); void action(); void getName(); }; Person:: Person(int a,string nam) { age=a; name=nam; } void Person::show() { cout<<"姓名:"<<name<<endl<<"年龄:"<<age<<endl; } void Person::action() { cout<< Person::name<<"已经到达事发地,正在封锁现场。"<<endl; cout<<"*******************"<<endl; } class Polic:public Person { private: int level; Person leader; public: Polic(int policage,string policname,int policlevel,int leaderage,string leadername); void show(); void arrest(Person); }; Polic::Polic(int policage,string policname,int policlevel,int leaderage,string leadername):Person(policage,policname),leader(leaderage,leadername) { level=policlevel; } void Polic::show() { Person::show(); cout<<"等级:"<<level<<endl; cout<<"*******************"<<endl<<"他的领导是:"<<endl; leader.show(); } void Polic::arrest(Person a) { cout<<"*******************"<<endl; action(); a.show(); cout<< Person::name<<"已经把小偷逮捕"<<endl; cout<<"*******************"<<endl; } class Cook:public Person { private: double salary; Polic protector; public: Cook(int cookage,string cookname,double cooksalary,int page,string pname,int plevel,int lage,string lname); void show(); string getCake(int); }; Cook::Cook(int cookage,string cookname,double cooksalary,int page,string pname,int plevel,int lage,string lname):Person(cookage,cookname),protector(page,pname,plevel,lage,lname) { salary=cooksalary; } string Cook::getCake(int n) { string a; cout<<Person::name<<"得到"<<n<<"个蛋糕。"<<endl; cout<<"*******************"<<endl; return a; } void Cook::show() { Person::show(); cout<<"薪水:"<<salary<<endl; cout<<"*******************"<<endl<<"他所在区域警察是:"<<endl; protector.show(); cout<<"*******************"<<endl; } int main() { string s; Person xiaotou(26,"坏蛋小偷"); Polic polic(25,"警察小李",5,50,"上司警察老王"); polic.show(); polic.arrest(xiaotou); Cook cook(32,"厨师小刘",5000,25,"小李",5,50,"上司警察老王"); cook.show(); s=cook.getCake(100); return 0; }