第十周第十一周项目3警察与厨师的派生类
2016-05-10 17:29
260 查看
/*Copyright (c) 2016,烟台大学计算机学院 *All rights reserved. *文件名称 : *作 者 : 李钊 *完成日期 : 2016年5月10号 *版 本 号 : v1.0 * *问题描述 : 警察与厨师的派生类 *输入描述 : *程序输出 : 人的行为警察的动作厨师的动作 */ #include <iostream> using namespace std; class Person { protected: int age; string name; public: void action(); Person(int a,string nam); string getname(); }; Person::Person(int a,string nam) { age=a; name=nam; } string Person::getname() { return name; } void Person::action() { cout<<"she is "<<name<<" she steal a heart "<<endl; } class Police:public Person { private: int level; public: Police(int a,string nam,int l); void arrest(Person); }; Police::Police(int a,string nam,int l):Person(a,nam),level(l){} void Police::arrest(Person human) { cout<<name<<" arrest "<<human.getname()<<" because she steal something from "<<name<<endl; } class Cooker:public Person { private: double salary; public: void cooking(); Cooker(int a,string nam,double s); }; Cooker::Cooker(int a,string nam,double s):Person(a,nam),salary(s){} void Cooker::cooking() { cout<<"she make a cake for lizhao and get "<<salary<<endl; } int main() { Person w(19,"wangyilin"); Police l(18,"lizhao",100); Cooker p(20,"laowang",1500); w.action(); l.arrest(w); p.cooking(); return 0; }
运行结果:
学习心得:
派生类的简单运用
知识点总结:
继承
相关文章推荐
- XML解析-第三方和系统方法
- C++第五次实验
- android: 使用 AsyncTask
- wdcp LNMP,php 网页显示源代码
- Android特效开发(仿zaker用手向上推动的效果(推动门效果))
- Selenium2Library与HttpLibrary.HTTP
- Python下使用OpenCV教程(图像的载入、显示和保存)
- 基于Hiredis异步API的聊天系统实现
- 设计模式——模板方法模式
- Android WebView 视频播放解决
- Spring基础知识(3)
- 没有上司的晚会 树形动态规划
- 留存的网址
- 文章标题
- 设计模式:10)责任链模式
- JVM内存分析
- android: 多线程编程基础
- Django剖析
- 进度条样式
- php的数组的函数