第二学期第11周项目2--职员有薪水了(1)
来源:互联网 发布:淘宝店工商注册 编辑:程序博客网 时间:2024/05/16 10:16
/* * Copyright (c) 2013, 烟台大学计算机学院 * All rights reserved. * 作 者: 沈远宏 * 完成日期:2014年05月06日 * 版 本 号:v1.0 * 问题描述:定义一个名为CPerson的类,有以下私有成员:姓名、身份证号、性别和年龄,成员函数:构造函数、析构函数、输出信息的函数。 并在此基础上派生出CEmployee类,派生类CEmployee增加了两个新的数据成员,分别用于表示部门和薪水。要求派生类CEmployee 的构造函数显示调用基类CPerson的构造函数,并为派生类CEmployee定义析构函数,定义输出信息的函数。 * 输出:职员的信息*/#include <iostream>using namespace std;class CPerson{protected: string m_szName; //姓名 string m_szId; //身份证号 int m_nSex;//0:women,1:man //性别 int m_nAge; //年龄public: CPerson(string name,string id,int sex,int age):m_szName(name),m_szId(id),m_nSex(sex),m_nAge(age){} void Show1(); ~CPerson() { cout<<"已释放1"<<endl; }};class CEmployee:public CPerson{private: string m_szDepartment; //部门 double m_Salary; //薪水public: CEmployee(string name,string id,int sex,int age,string department,double salary):CPerson(name,id,sex,age),m_szDepartment(department),m_Salary(salary){} void Show2(); ~CEmployee() { cout<<"已释放2"<<endl; }};void CPerson::Show1(){ cout<<"姓名 "<<m_szName<<"\t身份证号 "<<m_szId; if(m_nSex==0) { cout<<"\t性别 女"; } else { cout<<"\t性别 男"; } cout<<"\t年龄 "<<m_nAge<<endl;}void CEmployee::Show2(){ Show1(); cout<<"该职员的部门为 "<<m_szDepartment<<"\t薪水为 "<<m_Salary<<endl;}int main(){ string name,id,department; int sex,age; double salary; cout<<"input employee's name,id,sex(0:women,1:man),age,department,salary:\n"; cin>>name>>id>>sex>>age>>department>>salary; CEmployee employee1(name,id,sex,age,department,salary); employee1.Show2(); return 0;}
运行结果:
心得体会:
希望以后工作的地方统计我的工资能有好多0
0 0
- 第二学期第11周项目2--职员有薪水了(1)
- 第二学期第11周项目2--职员有薪水了(2)
- 大一第二学期第11周【项目2—职员有薪水了】
- 第11周 【项目2 - 职员有薪水了】(1)
- 第11周项目2 - 职员有薪水了(1)
- 项目2-职员有薪水了(1)(第10,11周补充项目)
- 第11周 【项目2 - 职员有薪水了】(2)
- 第11周项目2 - 职员有薪水了(2)
- 第11周 项目2 职员有薪水了
- 第11周项目2职员有薪水了
- 第11周项目2-职员有薪水了
- 第10周项目2-1职员有薪水了
- 第11周项目2-职员有薪水了(1)
- 第11周 项目2 职员有薪水了(1)
- 第11周补充项目2-职员有薪水了(1)
- 第11周补充(2)职员有薪水了!
- 第九周项目 2 职员有薪水了(1)
- 第11周 项目2-2 职员有薪水了(2)
- cocos2d-x项目101次相遇: Scenes , Director, Layers, Sprites
- i2c tool 的使用
- 【翻译】动态图像监测开源代码 motion 学习-----Motion Guide - Getting It Running(让motion动起来)
- Cannot find a free socket for the debugger Eclipse调试
- Regular Expression - 正则表达式
- 第二学期第11周项目2--职员有薪水了(1)
- 关于哈希算法
- vmware虚拟机上Redhat操作系统安装arm-linux-gcc交叉编译环境
- Zigbee网络设备启动—主要函数说明
- cocos2d-x项目101次相遇:建立图片菜单
- WPF 用Clip属性实现蒙板特效
- 配置putty隧道登录远程window远程或远程数据库【转载】
- check a int number is power of 2?
- cocos2d-x项目101次相遇:在HelloWorld上--建立新场景