警察和厨师

  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. }  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值