项目2-职员有薪水了(1)(第10,11周补充项目)
2016-05-19 08:54
441 查看
*Copyright (c) 2014,烟台大学计算机学院
*All right reserved.
*文件名称:test.cpp
*作 者:韩双志
*完成日期:2016年5月19日
*版本号:v1.0
*
*问题描述:定义一个名为CPerson的类,有以下私有成员:姓名、身份证号、性别和年龄,成员函数:构造函数、析构函数、输出信息的函数。并在此基础上派生出CEmployee类,派生类CEmployee增加了两个新的数据成员,分别用于表示部门和薪水。要求派生类CEmployee的构造函数显示调用基类CPerson的构造函数,并为派生类CEmployee定义析构函数,定义输出信息的函数
*输入描述:输入姓名,ID,性别,专业,薪水
*输出描述:输出姓名,ID,性别,专业,薪水
/*
#include <iostream>
#include<cstring>
using namespace std;
class CPerson//员工信息
{
protected:
string m_szName;
string m_szId;
string m_nSex;//0:women,1:man
int m_nAge;
public:
CPerson(string name,string id,string sex,int age);//复制构造函数
void Show1();
~CPerson();//析构函数
};
class CEmployee:public CPerson
{
private:
string m_szDepartment;//专业
double m_Salary;//薪水
public:
CEmployee(string name,string id,string sex,int age,string department,double salary);
void Show2();
~CEmployee();
};
//复制构造函数的实现
CPerson::CPerson(string name,string id,string sex,int age):m_szName(name),m_szId(id),m_nSex(sex),m_nAge(age){}
CEmployee::CEmployee(string name,string id,string sex,int age,string department,double salary):CPerson(name,id,sex,age),
m_szDepartment(department),m_Salary(salary){}
void CPerson::Show1()//输出的信息
{
cout<<"name "<<"id "<<"sex "<<"age "<<"deparment "<<"salary"<<endl;
cout<<m_szName<<" "<<m_szId<<" "<<m_nSex<<" "<<m_nAge<<" " ;
}
CPerson::~CPerson()//析构函数
{
cout<<endl;
}
void CEmployee::Show2()
{
CPerson::Show1();
cout<<m_szDepartment<<" "<<m_Salary<<" "<<endl;
}
CEmployee::~CEmployee()//析构函数的实现
{
cout<<"半:"<<endl;
}
int main()
{
string name,id,department;
string sex;
int 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;
}
*/
运行结果:
知识点结构:
类的继承,类的派生
学习心得
学会了类的继承,与类的派生
*All right reserved.
*文件名称:test.cpp
*作 者:韩双志
*完成日期:2016年5月19日
*版本号:v1.0
*
*问题描述:定义一个名为CPerson的类,有以下私有成员:姓名、身份证号、性别和年龄,成员函数:构造函数、析构函数、输出信息的函数。并在此基础上派生出CEmployee类,派生类CEmployee增加了两个新的数据成员,分别用于表示部门和薪水。要求派生类CEmployee的构造函数显示调用基类CPerson的构造函数,并为派生类CEmployee定义析构函数,定义输出信息的函数
*输入描述:输入姓名,ID,性别,专业,薪水
*输出描述:输出姓名,ID,性别,专业,薪水
/*
#include <iostream>
#include<cstring>
using namespace std;
class CPerson//员工信息
{
protected:
string m_szName;
string m_szId;
string m_nSex;//0:women,1:man
int m_nAge;
public:
CPerson(string name,string id,string sex,int age);//复制构造函数
void Show1();
~CPerson();//析构函数
};
class CEmployee:public CPerson
{
private:
string m_szDepartment;//专业
double m_Salary;//薪水
public:
CEmployee(string name,string id,string sex,int age,string department,double salary);
void Show2();
~CEmployee();
};
//复制构造函数的实现
CPerson::CPerson(string name,string id,string sex,int age):m_szName(name),m_szId(id),m_nSex(sex),m_nAge(age){}
CEmployee::CEmployee(string name,string id,string sex,int age,string department,double salary):CPerson(name,id,sex,age),
m_szDepartment(department),m_Salary(salary){}
void CPerson::Show1()//输出的信息
{
cout<<"name "<<"id "<<"sex "<<"age "<<"deparment "<<"salary"<<endl;
cout<<m_szName<<" "<<m_szId<<" "<<m_nSex<<" "<<m_nAge<<" " ;
}
CPerson::~CPerson()//析构函数
{
cout<<endl;
}
void CEmployee::Show2()
{
CPerson::Show1();
cout<<m_szDepartment<<" "<<m_Salary<<" "<<endl;
}
CEmployee::~CEmployee()//析构函数的实现
{
cout<<"半:"<<endl;
}
int main()
{
string name,id,department;
string sex;
int 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;
}
*/
运行结果:
知识点结构:
类的继承,类的派生
学习心得
学会了类的继承,与类的派生
相关文章推荐
- SpringMVC+Hibernate+Spring整合实例
- 初级Java工程师面试指导
- [绍棠] ios常见问题解决
- 第九周项目3-人数不定的工资类
- JS Attribute属性操作详解
- 第10,11周 项目三(2)
- beyond compare 比较class差异
- DELPHI 中 Window 消息大全使用详解
- 第十周项目训练3
- Java的接口和抽象类详解
- 報告。連絡。相談
- c++第6次实验 矩阵求和
- C++ 派生类和virtual
- 数据库原理 知识点总结
- 【BZOJ3571】[Hnoi2014]画框【最小乘积匹配】
- 在Android上打造属于自己的Rxjava框架(三)操作符变换
- 数据库原理_复习总结
- 整理STM32GPIO输出速率问题
- javascript闭包学习笔记
- 第12周项目2:Time类中的运算符重载