您的位置:首页 > 其它

简单的雇员管理系统

2011-11-26 23:23 417 查看




实验四  继实验四  继承与派生

实验名称:继承与派生                

一、实验目的和任务

1.理解继承的含义;

2.学习从现有类派生出新类的方式;

3.了解在派生类中如何使用基类的成员。

二、、实验内容和步骤

1.新建一个雇员类,它的数据成员有雇员代号,年龄,工资,性别,姓名,输入雇员资料方法,打印雇员资料方法。

2.以此雇员类为基类,从中派生出教师类,其中要求在教师类中加入一个计算教师工资的方法,教师工资=基本工资(1000)+课时(月工作量)×30。

3.以此雇员类为基类,从中派生出实验员类,其中要求在实验员类中加入一个计算实验员工资的方法,实验员工资=基本工资(800)+实验室补助(150)+值班课时(月工作量)×5。

4. 以此雇员类为基类,从中派生出行政人员类,其中要求在行政人员类中加入一个计算行政人员工资的方法,行政人员工资=基本工资(2000)+行政补贴(200)。

5.编写一个完整的程序,要求用户从键盘输入雇员的信息,然后在屏幕显示这些信息。

【任务分解】



【adminstrator.h】

#ifndef EMPLOYEE
#define EMPLOYEE
#include"employee.h"
#endif
using namespace std;
class Adminstrator : public Employee
{
private:
int dutytime,AdSalary;
public:
Adminstrator(){}

Adminstrator(string na,char se,int ag,int da)
:Employee(na,se,ag,da)
{}

void showData()
{
Employee::showEmployee(); //调用基类的成员函数
cout<<"应发工资:"<<AdSalary<<endl;
}
void inputData()
{Employee::inputEmployee(); //调用基类的成员函数
}
void calPay()
{AdSalary=2200;}
};

【employee.h】
#include<iostream>
#include<string>
using namespace std;

class Employee
{
protected:
//雇员代号,姓名,性别,年龄,工资,输入雇员资料方法,打印雇员资料方法
int age,salary,date;
char sex;
string name;
public:
Employee()
{}
Employee(string na,char se,int ag,int da)
{name=na;sex=se;age=ag;date=da;}

void inputEmployee() // 用户从键盘输入资料
{
cout<<"请输入雇员姓名:"<<endl;
cin>>name;
cout<<"请输入雇员性别:(m or f)"<<endl;
cin>>sex;
cout<<"请输入雇员年龄:"<<endl;
cin>>age;
cout<<"请输入受聘日期:"<<endl;
cin>>date;
}

void showEmployee() //显示雇员姓名和受聘日期
{
cout<<"雇员姓名:"<<name<<endl
<<"雇员性别:";
if (sex=='f') cout<<"女"<<endl;
else if(sex=='m') cout<<"男"<<endl;
else cout<<"性别设置错误!"<<endl;
cout<<"雇员年龄:"<<age<<endl
<<"受聘日期:"<<date<<endl;
}
};


【experimenter.h】
#ifndef EMPLOYEE
#define EMPLOYEE
#include"employee.h"
#endif
using namespace std;
class Experimenter : public Employee
{
private:
int dutytime,ExSalary;
public:
Experimenter(){}

Experimenter(string na,char se,int ag,int da,int the_dutytime)
:Employee(na,se,ag,da)
{
dutytime=the_dutytime;
}

int get_dutytime()
{
return dutytime;
}
void showData()
{
Employee::showEmployee(); //调用基类的成员函数
cout<<"值班课时:"<<dutytime<<endl;
cout<<"应发工资:"<<ExSalary<<endl;
}
void inputData()
{Employee::inputEmployee(); //调用基类的成员函数
cout<<"请输入实验员值班课时(月工作量):"<<endl;
cin>>dutytime;
}
void calPay()
{ExSalary=800+150+dutytime*5;}
};

【teacher.h】
#ifndef EMPLOYEE
#define EMPLOYEE
#include"employee.h"
#endif
using namespace std;
class Teacher : public Employee
{
private:
int classtime,TeSalary;
public:
Teacher(){}

Teacher(string na,char se,int ag,int da,int the_classtime)
:Employee(na,se,ag,da)
{
classtime=the_classtime;
}

int get_classtime()
{
return classtime;
}
void showData()
{
Employee::showEmployee(); //调用基类的成员函数
cout<<"教学课时:"<<classtime<<endl;
cout<<"教师工资:"<<TeSalary<<endl;
}
void inputData()
{Employee::inputEmployee(); //调用基类的成员函数
cout<<"请输入教师教学课时(月工作量):"<<endl;
cin>>classtime;
}
void calPay()
{TeSalary=1000+classtime*30;}
};

【main.cpp】
#include"adminstrator.h"
#include"experimenter.h"
#include"teacher.h"
#include<windows.h>
using namespace std;

void main()
{
system("Color 2f");
system("Title MG魔蛋雇员管理系统2011 (BetaII)");
cout<<"********************************************"<<endl;
cout<<"*************MG魔蛋雇员管理系统*************"<<endl;
cout<<"********************************************"<<endl<<endl;
int m,n;
cout<<"请输入雇员代码:"<<endl;
cin>>m;
cout<<"请输入雇员类别(1、2、3):"<<endl;
cout<<"n: 雇员类别:"<<endl;
cout<<"1 教师"<<endl;
cout<<"2 实验员"<<endl;
cout<<"3 行政管理"<<endl;
cin>>n;
cout<<endl;
if(n==1)
{cout<<">>>>>>>>>>>>>>>>>>教师<<<<<<<<<<<<<<<<<<"<<endl<<endl;
Teacher m;
m.inputData();
m.calPay();
system("cls");
m.showData();
cout<<endl<<endl;}

else if (n==2)
{cout<<">>>>>>>>>>>>>>>>>实验员<<<<<<<<<<<<<<<<<"<<endl<<endl;
Experimenter m;
m.inputData();
m.calPay();
m.calPay();
system("cls");
m.showData();
cout<<endl<<endl;}

else if (n==3)
{cout<<">>>>>>>>>>>>>>>>行政管理<<<<<<<<<<<<<<<<"<<endl<<endl;
Adminstrator m;
m.inputData();
m.calPay();
m.calPay();
system("cls");
m.showData();
cout<<endl<<endl;}

system("pause");
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  system string 工作 任务