- *Copyright (c) 2016,烟台大学计算机学院
- *All rights reserved.
- *文件名称:zwj.cpp
- *作 者:李才
- *完成日期:2016年6月5日
- *版 本 号:v1.06
- *
- *问题描述:警察和厨师
- *输入描述:
- *程序输出:
- */
- #include<iostream>
- #include<string>
- using namespace std;
- class Person
- {
- private:
- int age;
- string name;
- public:
- Person(int ,string);
- void action();
- // int getage(){return age;}
- string getname(){return name;}
- };
- Person::Person(int a,string nam):age(a),name(nam){}
- class Polic:public Person
- {
- protected:
- int level;
- public:
- Polic(int ,string ,int);
- void arrest(Person);
- };
- Polic::Polic(int a,string nam,int l):Person(a,nam),level(l){}
- class Cook:public Person
- {
- private:
- double salary;
- public:
- Cook(int ,string ,double);
- string getCake(int);
- };
- Cook::Cook(int a,string nam,double s):Person(a,nam),salary(s){}
- void Person::action()
- {
- cout<<name<<" have some action ."<<endl;
- }
- void Polic::arrest(Person p)
- {
- cout<<getname()<<" arrest "<<p.getname()<<endl;
- }
- string Cook::getCake(int a)
- {
- cout<<getname()<<" get "<<a<<" cakes."<<endl;
- return getname();
- }
- int main()
- {
- Person p(20,"person1");
- Polic police(23,"police2",3);
- Cook cook(19,"cook3",5000);
- police.arrest(p);
- cook.getCake(5);
- return 0;
- }