第10、11周-项目3(1)
2016-05-09 20:33
267 查看
问题及代码:
运行结果:
/*Copyright (c)2016,烟台大学计算机与控制工程学院 *All rights reserved. *文件名称:main.cpp *作 者:王艺霖 *完成日期:2016年5月9日 *版 本 号:v1.0 *问题描述:各个成员函数,只要输出相关的信息即可,暂不深究其业务功能 请为各个类增加构造函数 在实现中,可以增加需要的其他函数 自行编制main函数,完成初步的测试 *输入描述: *输出描述: */ #include<iostream> #include<string> using namespace std; class Person { public: Person(int a,string n); void action(); string getname() { return name; } private: int age; string name; }; Person::Person(int a,string n):age(a),name(n){}; void Person::action() { cout<<name<<"开始干活!"<<endl; } class Polic: public Person { public: Polic(int a,string n,int l); void arrest(Person); private: int level; }; Polic::Polic(int a,string n,int l):Person(a,n),level(l){}; void Polic::arrest(Person w) { cout<<"警察"<<getname()<<"抓获"<<w.getname()<<endl; } class Cook: public Person { public: Cook(int a,string nam,double s); void getCake(int); private: double salary; }; Cook::Cook(int a,string n,double s):Person(a,n),salary(s){}; void Cook::getCake(int n) { cout<<"厨师"<<getname()<<"送给她"<<n<<"个蛋糕"<<endl; } int main() { Person Lz(19,"lz"); Polic Wyl(19,"wyl",2); Cook Xxz(2,"xxl",10000); Wyl.arrest(Lz); Xxz.getCake(10); return 0; }
运行结果:
相关文章推荐
- leetcode.153. Find Minimum in Rotated Sorted Array
- struts2页面属性值回显
- Python学习笔记(二)列表统计词频
- android-----Fragment详解及其应用
- 希尔排序算法
- CentOS 6.5环境下使用HAProxy+apache实现web服务的动静分离
- 解决Linux下yum安装无法解析URL的问题
- 【连载】关系型数据库是如何工作的?(10) - 查询管理器之parser
- OC下载网页
- UVa 378 - Intersecting Lines
- Hadoop学习(四)— MapReduce入门
- php 字符串
- 哈工大深研院数字图像处理第二次大作业:水果自动识别(2)HSV空间聚类及SIFT算法目标识别
- HDU 4089 Activation 概率dp好题
- 【全排列】HDU1027Ignatius and the Princess II/HDU1716排列2
- Leetcode 198. House Robber
- Notification
- BOM—浏览器对象模型
- 30.丑数
- Connect 源码解析(一)