#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
class Employee
{
protected:
int id; //雇员代号
string name; //雇员名字
string sex; //雇员性别
int age; //雇员年龄
float salary; //雇员工资
public:
Employee() {}
~Employee() {}
Employee(int i,string na,string s,int a,float sa):id(i),name(na),sex(s),age(a),salary(sa) {}
const string getName()const
{
return name;
}
const int setId(int c)
{
id=c;
}
const int getId()const
{
return id;
}
const string setSex(string c)
{
sex=c;
}
const string getSex()const
{
return sex;
}
const int setAge(int c)
{
c=age;
}
const int getAge()const
{
return age;
}
void input() //输入数据函数
{
cin>>id>>name>>sex>>age;
}
void display()const //输出数据函数
{
cout<<getId()<<setw(8)<<getName()<<setw(9)<<getSex()<<setw(10)<<getAge();
}
};
class Teacher:public Employee
{
protected:
int hour; //教师课时
float basepay=1000; //基本工资
double TeSalary; //教师工资
public:
Teacher() {}
~Teacher() {}
Teacher(int i,string na,string s,int a,float sa,int h,float b):Employee(i,na,s,a,sa)
{
h=hour;
b=basepay;
}
void input() //教师类的输入函数
{
Employee::input(); //调用基类版本,输入代号、姓名、年龄、性别
cin>>hour; //输入课时
}
void display() //教师类的输出函数
{
cout<<id<<setw(8)<<name<<setw(6)<<sex<<setw(9)<<age<<setw(10)<<gethour()<<setw(10)<<basepay<<setw(10)<<getpay()<<endl;
}
int sethour()
{
cin>>hour;
}
int gethour()
{
return hour;
}
float getpay() //计算教师工资函数
{
TeSalary=basepay+hour*30;
return TeSalary;
}
void inputT(Teacher *t,int b,int a) //输入教师信息函数
{
cout<<"教师id"<<setw(5)<<"姓名"<<setw(5)<<"性别"<<setw(5)<<"年龄"<<setw(5)<<"课时\n";
for(int i=0; i<a+b; i++)
{
t[i].input();
}
}
void show(Teacher *t,int a) //输出教师信息函数
{
cout<<"教师id"<<setw(5)<<"姓名"<<setw(8)<<"性别"<<setw(10)<<"年龄"<<setw(9)<<"课时"<<setw(12)<<"基本工资"<<setw(10)<<"总工资"<<endl;
for(int i=0; i<a; i++)
{
t[i].display();
}
}
};
class Labworker:public Employee
{
protected:
int hour; //实验员值班时间
float basepay=800;//实验员的基本工资
float subsidy=150;//实验室补助
float LaSalary;
public:
Labworker() {}
~Labworker() {}
Labworker(int i,string na,string s,int a,float sa,int h,float b,float su):Employee(i,na,s,a,sa)
{
h=hour;
b=basepay;
su=subsidy;
}
void input()
{
Employee::input(); //调用基类版本,输入代号、姓名、年龄、性别
cin>>hour; //输入值班时间
}
void display() //实验员类的输出函数
{
cout<<id<<setw(10)<<name<<setw(7)<<sex<<setw(10)<<age<<setw(10)<<gethour()<<setw(16)<<getbasepay()<<setw(16)<<getsubsidy()<<setw(16)<<getpay()<<endl;
}
int gethour()
{
return hour;
}
float getbasepay()
{
return basepay;
}
float getsubsidy()
{
return subsidy;
}
float getpay()
{
LaSalary=basepay+subsidy+(hour*5);
return LaSalary;
}
void inputL(Labworker *l,int b,int a) //输入实验员类信息函数
{
cout<<"实验员id"<<setw(5)<<"姓名"<<setw(10)<<"性别"<<setw(10)<<"年龄"<<setw(14)<<"值班时间\n";
for(int i=b; i<a+b; i++)
{
l[i].input();
}
}
void show(Labworker *l,int a) //输出实验员信息函数
{
cout<<"实验员id"<<setw(5)<<"姓名"<<setw(10)<<"性别"<<setw(10)<<"年龄"<<setw(14)<<"值班时间"<<setw(14)<<"基本工资"<<setw(16)<<"实验室补助"<<setw(14)<<"总工资"<<endl;
for(int i=0; i<a; i++)
{
l[i].display();
}
}
};
class Admin:public Employee
{
protected:
float subsidy=200;//行政补贴
float basepay=900;//基本工资
float AdSalary; //行政人员工资
public:
Admin() {}
~Admin() {}
Admin(int i,string na,string s,int a,float sa,int h,float b,float su):Employee(i,na,s,a,sa)
{
b=basepay;
su=subsidy;
}
void input() //行政人员类的输入函数
{
Employee::input(); //调用基类,输入代号、姓名、年龄、性别
}
void display() //行政人员类的输出函数
{
cout<<id<<setw(11)<<name<<setw(9)<<sex<<setw(10)<<age<<setw(16)<<getbasepay()<<setw(16)<<getsubsidy()<<setw(16)<<getpay()<<endl;
}
float getbasepay()
{
return basepay;
}
float getsubsidy()
{
return subsidy;
}
float getpay()
{
AdSalary=basepay+subsidy;
return AdSalary;
}
void inputA(Admin *A,int b,int a) //输入行政人员信息函数
{
cout<<"行政人员id"<<setw(5)<<"姓名"<<setw(5)<<"性别"<<setw(6)<<"年龄\n";
for(int i=0; i<a+b; i++)
{
A[i].input();
}
}
void show(Admin *A,int a) //输出行政人员信息函数
{
cout<<"行政人员id"<<setw(5)<<"姓名"<<setw(10)<<"性别"<<setw(10)<<"年龄"<<setw(16)<<"基本工资"<<setw(16)<<"行政补贴"<<setw(16)<<"总工资"<<endl;
for(int i=0; i<a; i++)
{
A[i].display();
}
}
};
main()
{
int a1=0,a2=0,a3=0;
int b1=0,b2=0,b3=0;
int option; //定义一个选择变量
Teacher t[10];
Labworker l[10];
Admin A[10];
Teacher Teacher; //创建教师对象
Labworker Labworker; //创建实验员对象
Admin Admin; //创建行政人员对象
while(1)
{
cout<<"\t\t\t\t***********************************"<<endl;
cout<<"\t\t\t\t*****继承和派生类的设计与应用******"<<endl;
cout<<"\t\t\t\t*******1、输入教师信息 *******"<<endl;
cout<<"\t\t\t\t*******2、输出教师信息 *******"<<endl;
cout<<"\t\t\t\t*******3、输入实验员信息 *******"<<endl;
cout<<"\t\t\t\t*******4、输出实验员信息 *******"<<endl;
cout<<"\t\t\t\t*******5、输入行政人员信息 *******"<<endl;
cout<<"\t\t\t\t*******6、输出行政人员信息 *******"<<endl;
cout<<"\t\t\t\t*******0、退出 *******"<<endl;
cout<<"\t\t\t\t***********************************"<<endl;
cout<<"\t\t\t\t请选择菜单项:";
cin>>option;
switch(option)
{
case 1:
{
cout<<"确定要输入教师信息的人数:"<<endl;
b1=a1+b1;
cin>>a1;
cout<<"请输入教师信息:"<<endl;
Teacher.inputT(t,b1,a1);
break;
}
case 2:
{
if(a1!=0)
{
Teacher.show(t,b1+a1);
}
else cout<<"无教师信息"<<endl;
break;
}
case 3:
{
cout<<"确定要输入实验员信息的人数:"<<endl;
b2=a2+b2;
cin>>a2;
cout<<"请输入实验员信息:"<<endl;
Labworker.inputL(l,b2,a2);
break;
}
case 4:
{
if(a2!=0)
{
Labworker.show(l,b2+a2);
}
else cout<<"无实验员信息"<<endl;
break;
}
case 5:
{
cout<<"确定要输入行政人员信息的人数:"<<endl;
b3=a3+b3;
cin>>a3;
cout<<"请输入行政人员信息:"<<endl;
Admin.inputA(A,b3,a3);
break;
}
没有合适的资源?快使用搜索试试~ 我知道了~
新建一个雇员类,它的数据成员有雇员代号,年龄,工资,性别, 姓名,输入雇员资料方法,打印雇员资料方法。
共1个文件
txt:1个
需积分: 44 21 下载量 7 浏览量
2018-06-24
09:41:02
上传
评论 4
收藏 2KB RAR 举报
温馨提示
编写程序,新建一个雇员类,它的数据成员有雇员代号,年龄,工资,性别, 姓名,输入雇员资料方法,打印雇员资料方法。以此雇员类为基类,从中派生出教师类,其中要求在教师类中加入一个计算教师工资的方法,教师工资=基本工资(1000)+课时(月工作量)×30。以此雇员类为基类,从中派生出实验员类, 其中要求在实验员类中加入一个计算实验员工资的方法,实验员工资=基本工资 (800)+实验室补助(150)+值班时间(月工作量)×5。以此雇员类为基类,从中派生出行政人员类,其中要求在行政人员类中加入一个计算行政人员工资的方法,行政人员工资=基本工资(900)+行政补贴(200)。分别实现输入输出教师、实验人员、行政人员信息和计算教师、实验人员、行政人员工资的方法。
资源推荐
资源详情
资源评论
收起资源包目录
c++.rar (1个子文件)
c++.txt 8KB
共 1 条
- 1
资源评论
泰山顶上一抔土
- 粉丝: 3
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功