警察和厨师

来源:互联网 发布:mac系统 文件夹 编辑:程序博客网 时间:2024/05/16 00:34
  1.  *Copyright (c) 2016,烟台大学计算机学院 
  2.  *All rights reserved. 
  3.  *文件名称:zwj.cpp 
  4.  *作    者:李才 
  5.  *完成日期:2016年6月5日 
  6.  *版 本 号:v1.06
  7.  * 
  8.  *问题描述:警察和厨师 
  9.  *输入描述: 
  10.  *程序输出: 
  11.  */  
  12. #include<iostream>  
  13. #include<string>  
  14. using namespace std;  
  15. class Person  
  16. {  
  17. private:  
  18.     int age;  
  19.     string name;  
  20. public:  
  21.     Person(int ,string);  
  22.     void action();  
  23.    // int  getage(){return age;}  
  24.     string getname(){return name;}  
  25. };  
  26. Person::Person(int a,string nam):age(a),name(nam){}  
  27. class Polic:public Person  
  28. {  
  29. protected:  
  30.     int level;  
  31. public:  
  32.     Polic(int ,string  ,int);  
  33.     void arrest(Person);  
  34. };  
  35. Polic::Polic(int a,string nam,int l):Person(a,nam),level(l){}  
  36. class Cook:public Person  
  37. {  
  38. private:  
  39.   
  40.     double salary;  
  41. public:  
  42.     Cook(int ,string ,double);  
  43.     string getCake(int);  
  44. };  
  45. Cook::Cook(int a,string nam,double s):Person(a,nam),salary(s){}  
  46. void Person::action()  
  47. {  
  48.     cout<<name<<" have some action ."<<endl;  
  49. }  
  50. void Polic::arrest(Person p)  
  51. {  
  52.     cout<<getname()<<" arrest "<<p.getname()<<endl;  
  53. }  
  54. string Cook::getCake(int a)  
  55. {  
  56.     cout<<getname()<<" get "<<a<<" cakes."<<endl;  
  57.     return getname();  
  58.   
  59.   
  60. }  
  61. int main()  
  62. {  
  63.     Person p(20,"person1");  
  64.     Polic police(23,"police2",3);  
  65.     Cook cook(19,"cook3",5000);  
  66.     police.arrest(p);  
  67.     cook.getCake(5);  
  68.     return 0;  
  69.   
  70. }  
0 0