公司员工信息管理系统
目 录
一 系统的背景 2
二 系统的编译环境和语言 2
三 系统类的设计 3
3.1 类的对象: 3
3.2 类的属性列表: 3
3.3 类的行为: 3
3.4 具体代码如下: 3
四 系统运行入口的设计 11
五 运行步骤 13
六 数据文件 16
七 参考文献 16
一 系统的背景
从事商业活动的公司迫切需要这样一个系统:它能高效的管理公司内部所有员工的个人信息,并能正确快速的对系统的使用者的操作做出回应,以提高效率,降低成本。
该系统能够满足以上的要求,使用户可以快速准确的管理公司员工的信息。
二 系统的编译环境和语言
该系统是采用C++语言在Turbo c下编译而成,。
因为在该系统中有明显的对象,即是公司的员工,且C++语言是一个非常强大的面向对象的语言,因此该系统使用C++编写将会简单,快速而有效。
Turbo C是一个经典且功能强大的编译器,是编译用C++语言写成的程序的首要工具。
三 系统类的设计
3.1 类的对象:
系统有两个类:
Employee :对象是公司里的每一个员工,是系统中最重要的类。
DBOperate :对象是系统的数据文件,完成对员工信息的保存和读取。
3.2 类的属性列表:
Employee :
员工的编号:EmployeeNum (long)
员工的姓名:EmployName (string)
员工所属部门:EmployeeDepart (string)
员工级别:EmployeeGrade (string)
员工工资:EmployeePay (float)
员工工龄:EmpoyeeWorkTime (long)
3.3 类的行为:
Employee :
添加新员工信息:NewInfo();
员工信息浏览:ShowInfo();
员工信息变更:RefreshInfo();
发放工资: Pay(int EG);//EG为员工级别
解聘员工: DeleteInfo();
DBOperate :
保存员工信息:WriteIn(int iflag);
读取员工信息:ReadOut();
更新员工总人数:RefreshMaxNum(int iflag);
注释:当iflag 为1时,人数增大;为零时,人数不变,即是修改;为 -1时,人数减少。
3.4 具体代码如下:
long Employee::EmployeeMaxNum = 1000;
float Employee::EmployeeBasePay = 1500;
int Employee::MaxNum()
{
int MN = 0;
ifstream myf("c:\\EmployeeMaxNum.txt");
myf>>MN;
myf.close();
return MN;
}
void Employee::NewInfo()
{
char tmpName[50];
cout<<"new Employee Name >"; //输入员工名字
cin>>tmpName;
Employee::EmployeeName = new char[strlen(tmpName)+1];
strcpy(Employee::EmployeeName,tmpName);
//////////////////////////////////////////
Employee::EmployeeNum = EmployeeMaxNum + Employee::MaxNum()+1; //自动分配员工编号,为基础标号+员工人数
//////////////////////////////////////////
char tmpDepart[50];
cout<<"new Employee Department >"; //输入员工部门名称
cin>>tmpDepart;
Employee::EmployeeDepart = new char[strlen(tmpDepart)+1];
strcpy(Employee::EmployeeDepart,tmpDepart);
//////////////////////////////////////////
cout<<"new Employee Grade (1:zhiyuan 2:zhuren 3:jingli 4:dongshizhang) >"; //输入员工等级,1为职员,2为主任,3为经理,4为董事长
cin>>Employee::EmployeeGrade;
while(Employee::EmployeeGrade !=1&&
Employee::EmployeeGrade !=2&&
Employee::EmployeeGrade !=3&&
Employee::EmployeeGrade !=4)
{
cout<<"Your Input Error! Input Again be careful:)"<<endl;
cout<<"new Employee Grade (1:zhiyuan 2:zhuren 3:jingli 4:dongshizhang) >";
cin>>Employee::EmployeeGrade;
}
//////////////////////////////////////////
cout<<"new EmployeeWorkTime >"; //输入员工合同期
cin>>Employee::EmployeeWorkTime;
//////////////////////////////////////////
Employee::EmployeePay = Employee::Pay(Employee::EmployeeGrade);
DBOperate dbo;
dbo.ReadOut(); //将原来的数据文件中的数据读出,并加入新的数据
int MaxNum = Employee::MaxNum();
EN[MaxNum] = Employee::EmployeeName;
ENum[MaxNum] = Employee::EmployeeNum;
ED[MaxNum] = Employee::EmployeeDepart;
EG[MaxNum] = Employee::EmployeeGrade;
EWT[MaxNum] = Employee::EmployeeWorkTime;
EP[MaxNum] = Employee::EmployeePay;
dbo.WriteIn(1); //将新的信息全部写入数据文件
return;
}
void Employee::ShowInfo()
{
for(int i=0;i<Employee::MaxNum();i++)
{//顺序输出所有员工的信息,Employee::MaxNum()为员工人数
cout<<"The Employee's Information:"<<endl;
cout<<"**********************************"<<endl;
cout<<"* EmployeeName >"<<EN[i]<<endl;
cout<<"* EmployeeNum >"<<ENum[i]<<endl;
cout<<"* EmployeeDepart >"<<ED[i]<<endl;
cout<<"* EmployeeGrade >"<<EG[i]<<endl;
cout<<"* EmployeeWorkTime >"<<EWT[i]<<endl;
cout<<"* EmployeePay >"<<EP[i]<<endl;
cout<<"**********************************"<<endl;
}
}
void Employee::RefreshInfo()
{
int cNum = 1000; //基础编号
DBOperate dbo;
dbo.ReadOut();
Employee::ShowInfo(); //先将所有员工信息输出
cout<<"Please input the Employee's Num >";
cin>>cNum;
int MN;
MN = Employee::MaxNum();
for(int i=0;i<MN;i++)
{
if(ENum[i] == cNum) //通过编号找到指定要更新的员工
{ //依次更新员工信息
cout<<"***********************************"<<endl;
cout<<"Your choice's the Employee"<<endl;
cout<<"**********************************"<<endl;
cout<<"* EmployeeName >"<<EN[i]<<endl;
cout<<"* EmployeeNum >"<<ENum[i]<<endl;
cout<<"* EmployeeDepart >"<<ED[i]<<endl;
cout<<"* EmployeeGrade >"<<EG[i]<<endl;
cout<<"* EmployeeWorkTime >"<<EWT[i]<<endl;
cout<<"* EmployeePay >"<<EP[i]<<endl;
cout<<"**********************************"<<endl;
cout<<"Input your Refresh:"<<endl;
char tmpName[50];
cout<<"new Employee Name >";
cin>>tmpName;
Employee::EmployeeName = new char[strlen(tmpName)+1];
strcpy(Employee::EmployeeName,tmpName);
//////////////////////////////////////////
EN[i] = Employee::EmployeeName;
//////////////////////////////////////////
char tmpDepart[50];
cout<<"new Employee Department >";
cin>>tmpDepart;
Employee::EmployeeDepart = new char[strlen(tmpDepart)+1];
strcpy(Employee::EmployeeDepart,tmpDepart);
ED[i] = Employee::EmployeeDepart;
//////////////////////////////////////////
cout<<"new Employee Grade (1:zhiyuan 2:zhuren 3:jingli 4:dongshizhang) >";
cin>>Employee::EmployeeGrade;
while(Employee::EmployeeGrade !=1&&
Employee::EmployeeGrade !=2&&
Employee::EmployeeGrade !=3&&
Employee::EmployeeGrade !=4)
{
cout<<"Your Input Error! Input Again be careful:)"<<endl;
cout<<"new Employee Grade (1:zhiyuan 2:zhuren 3:jingli 4:dongshizhang) >";
cin>>Employee::EmployeeGrade;
EG[i] = Employee::EmployeeGrade;
}
//////////////////////////////////////////
cout<<"new EmployeeWorkTime >";
cin>>Employee::EmployeeWorkTime;
//////////////////////////////////////////
Employee::EmployeePay = Employee::Pay(EG[i]);
EP[i] = Employee::EmployeePay;
break;
}
}
dbo.WriteIn(0); //将更新信息写入数据文件
}
void Employee::DeleteInfo()
{
int cNum = 1000;
DBOperate dbo;
dbo.ReadOut();
Employee::ShowInfo();
cout<<"Please input the Employee's Num >";
cin>>cNum;
int MN;
MN = Employee::MaxNum();
for(int i=0;i<MN;i++)
{
if(ENum[i] == cNum)
{
cout<<"***********************************"<<endl;
cout<<"Your choice's the Employee"<<endl;
cout<<"**********************************"<<endl;
cout<<"* EmployeeName >"<<EN[i]<<endl;
cout<<"* EmployeeNum >"<<ENum[i]<<endl;
cout<<"* EmployeeDepart >"<<ED[i]<<endl;
cout<<"* EmployeeGrade >"<<EG[i]<<endl;
cout<<"* EmployeeWorkTime >"<<EWT[i]<<endl;
cout<<"* EmployeePay >"<<EP[i]<<endl;
cout<<"**********************************"<<endl;
}
}
cout<<"Delete the Employee's Information (Y/N) >";
char c;
cin>>c;
if(i==MN-1) //如果指定要删除的员工信息在文件末尾,那么只要将员工人数减1就行
dbo.WriteIn(-1); //重新将信息写入数据文件
else
{
for(int j=i;j<MN-1;j++)
{
EN[j] = EN[j+1];
}
dbo.WriteIn(-1);
}
cout<<"Delete Success ! "<<endl;
}
float Employee::Pay(int EG)
{
float tmpPay;
tmpPay = Employee::EmployeeBasePay + EG*Employee::EmployeeBasePay;
return tmpPay;
}
void DBOperate::WriteIn(int iflag)
{
DBOperate::RefreshMaxNum(iflag);
ofstream myf("c:\\Employee.txt"); //打开C盘下的数据文件
Employee e;
int MN;
MN = e.MaxNum();
for(int i=0;i<MN;i++)
{
myf<<EN[i]<<'\n'<<ENum[i]<<'\n'<<ED[i]<<'\n'<<EG[i]<<'\n'<<EWT[i]<<'\n'<<EP[i]<<'\n'; //依次写入
}
myf.close();
return;
}
void DBOperate::ReadOut()
{
ifstream myf("c:\\Employee.txt");//打开C盘下的数据文件
char tmpName[50];
char tmpDepart[50];
Employee e;
int MN = 0;
MN = e.MaxNum();
for(int i=0 ;i<MN;i++)
{
myf>>tmpName>>DBOperate::EmployeeNum>>tmpDepart>>DBOperate::EmployeeGrade>>DBOperate::EmployeeWorkTime>>DBOperate::EmployeePay; //依次读出
DBOperate::EmployeeName = new char[strlen(tmpName)+1];
DBOperate::EmployeeDepart = new char[strlen(tmpDepart)+1];
strcpy(DBOperate::EmployeeName,tmpName);
strcpy(DBOperate::EmployeeDepart,tmpDepart);
EN[i] = DBOperate::EmployeeName;
ENum[i] = DBOperate::EmployeeNum;
ED[i] = DBOperate::EmployeeDepart;
EG[i] = DBOperate::EmployeeGrade;
EWT[i] = DBOperate::EmployeeWorkTime;
EP[i] = DBOperate::EmployeePay;
}
myf.close();
}
void DBOperate::RefreshMaxNum(int iflag)
{
int MaxNum = 0;
ifstream myif("c:\\EmployeeMaxNum.txt");
myif>>MaxNum;
cout<<MaxNum<<endl;
myif.close();
MaxNum = MaxNum+iflag; //将员工人数做相应变动
ofstream myof("c:\\EmployeeMaxNum.txt");
myof<<MaxNum;
myof.close();
}
四 系统运行入口的设计
提供一个操作界面入图:
注意:系统中有全局变量用于存储从数据文件中读出的员工信息
char *EN[50];
long ENum[50];
char *ED[50];
int EG[50];
long EWT[50];
float EP[50];
该系统的操作就是围绕这些全局变量展开。
代码如下:
void main()
{
int c2 = 0;
while(c2!=5)
{
cout<<"Employee Information Manage System"<<endl;
cout<<"******************************************"<<endl;
cout<<"* Employee List-----------1"<<endl;
cout<<"* Add New Employee Information-----------2"<<endl;
cout<<"* Refresh Employee Information-----------3"<<endl;
cout<<"* Delete Employee Information-----------4"<<endl;
cout<<"******************************************"<<endl;
cout<<"* Exit EIMS------------5"<<endl;
cout<<"******************************************"<<endl;
cout<<"Input your choice on here > ";
cin>>c2;
Employee e;
DBOperate dbo;
switch(c2)
{
case 1:
dbo.ReadOut(); e.ShowInfo(); break;
case 2:
e.NewInfo(); break;
case 3:
e.RefreshInfo(); break;
case 4:
e.DeleteInfo(); break;
case 5:
break;
default:
cout<<"Error! Your Choice doesn't Exit"<<endl;
}
if(c2 == 5)
break;
}
}
五 运行步骤
运行主界面:
【步骤1】:选择1,系统将已有的员工信息依次显示在屏幕上。
【步骤2】:选择2,系统将添加新的员工信息。
【步骤3】:选择3,系统将更新指定的员工信息。
【步骤4】:选择4,系统将删除指定的员工信息。
【步骤5】:选择5,退出系统。
六 数据文件
Employee.txt 存储员工的基本信息
EmployeeMaxNum.txt 存储员工的人数
数据文件都存放在C盘根目录下。
该系统对数据文件的操作在系统运行过程中非常重要,是使整个系统正常运行的关键。
七 参考文献
【1】《C语言程序设计》 谭浩强编著 清华大学出版社
【2】《C++ 程序设计教程》 钱能主编 清华大学出版社
八 附录
完整代码:
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
char *EN[50];
long ENum[50];
char *ED[50];
int EG[50];
long EWT[50];
float EP[50];
class Employee
{
public:
char *EmployeeName;
long EmployeeNum;
char *EmployeeDepart;
int EmployeeGrade;
long EmployeeWorkTime;
float EmployeePay;
static long EmployeeMaxNum;
static float EmployeeBasePay;
void NewInfo();
void ShowInfo();
void RefreshInfo();
void DeleteInfo();
float Pay(int EG);
int MaxNum();
};
class DBOperate
{
public:
char *EmployeeName;
long EmployeeNum;
char *EmployeeDepart;
int EmployeeGrade;
long EmployeeWorkTime;
float EmployeePay;
static long EmployeeMaxNum;
static float EmployeeBasePay;
void WriteIn(int iflag);
void ReadOut();
void RefreshMaxNum(int iflag);//i=1 or -1 or 0
};
long Employee::EmployeeMaxNum = 1000;
float Employee::EmployeeBasePay = 1500;
int Employee::MaxNum()
{
int MN = 0;
ifstream myf;
myf.open("c:\\EmployeeMaxNum.txt");
myf>>MN;
cout<<MN<<endl;
myf.close();
return MN;
}
void Employee::NewInfo()
{
char tmpName[50];
cout<<"new Employee Name >";
cin>>tmpName;
Employee::EmployeeName = new char[strlen(tmpName)+1];
strcpy(Employee::EmployeeName,tmpName);
//////////////////////////////////////////
Employee::EmployeeNum = EmployeeMaxNum + Employee::MaxNum()+1;
//////////////////////////////////////////
char tmpDepart[50];
cout<<"new Employee Department >";
cin>>tmpDepart;
Employee::EmployeeDepart = new char[strlen(tmpDepart)+1];
strcpy(Employee::EmployeeDepart,tmpDepart);
//////////////////////////////////////////
cout<<"new Employee Grade (1:zhiyuan 2:zhuren 3:jingli 4:dongshizhang) >";
cin>>Employee::EmployeeGrade;
while(Employee::EmployeeGrade !=1&&
Employee::EmployeeGrade !=2&&
Employee::EmployeeGrade !=3&&
Employee::EmployeeGrade !=4)
{
cout<<"Your Input Error! Input Again be careful:)"<<endl;
cout<<"new Employee Grade (1:zhiyuan 2:zhuren 3:jingli 4:dongshizhang) >";
cin>>Employee::EmployeeGrade;
}
//////////////////////////////////////////
cout<<"new EmployeeWorkTime >";
cin>>Employee::EmployeeWorkTime;
//////////////////////////////////////////
Employee::EmployeePay = Employee::Pay(Employee::EmployeeGrade);
DBOperate dbo;
dbo.ReadOut();
int MaxNum = Employee::MaxNum();
EN[MaxNum] = Employee::EmployeeName;
ENum[MaxNum] = Employee::EmployeeNum;
ED[MaxNum] = Employee::EmployeeDepart;
EG[MaxNum] = Employee::EmployeeGrade;
EWT[MaxNum] = Employee::EmployeeWorkTime;
EP[MaxNum] = Employee::EmployeePay;
dbo.WriteIn(1);
cout<<"Add Success"<<endl;
return;
}
void Employee::ShowInfo()
{
for(int i=0;i<Employee::MaxNum();i++)
{
cout<<"The Employee's Information:"<<endl;
cout<<"**********************************"<<endl;
cout<<"* EmployeeName >"<<EN[i]<<endl;
cout<<"* EmployeeNum >"<<ENum[i]<<endl;
cout<<"* EmployeeDepart >"<<ED[i]<<endl;
cout<<"* EmployeeGrade >"<<EG[i]<<endl;
cout<<"* EmployeeWorkTime >"<<EWT[i]<<endl;
cout<<"* EmployeePay >"<<EP[i]<<endl;
cout<<"**********************************"<<endl;
}
}
void Employee::RefreshInfo()
{
int cNum = 1000;
DBOperate dbo;
dbo.ReadOut();
Employee::ShowInfo();
cout<<"Please input the Employee's Num >";
cin>>cNum;
int MN;
MN = Employee::MaxNum();
for(int i=0;i<MN;i++)
{
if(ENum[i] == cNum)
{
cout<<"***********************************"<<endl;
cout<<"Your choice's the Employee"<<endl;
cout<<"**********************************"<<endl;
cout<<"* EmployeeName >"<<EN[i]<<endl;
cout<<"* EmployeeNum >"<<ENum[i]<<endl;
cout<<"* EmployeeDepart >"<<ED[i]<<endl;
cout<<"* EmployeeGrade >"<<EG[i]<<endl;
cout<<"* EmployeeWorkTime >"<<EWT[i]<<endl;
cout<<"* EmployeePay >"<<EP[i]<<endl;
cout<<"**********************************"<<endl;
cout<<"Input your Refresh:"<<endl;
char tmpName[50];
cout<<"new Employee Name >";
cin>>tmpName;
Employee::EmployeeName = new char[strlen(tmpName)+1];
strcpy(Employee::EmployeeName,tmpName);
//////////////////////////////////////////
EN[i] = Employee::EmployeeName;
//////////////////////////////////////////
char tmpDepart[50];
cout<<"new Employee Department >";
cin>>tmpDepart;
Employee::EmployeeDepart = new char[strlen(tmpDepart)+1];
strcpy(Employee::EmployeeDepart,tmpDepart);
ED[i] = Employee::EmployeeDepart;
//////////////////////////////////////////
cout<<"new Employee Grade (1:zhiyuan 2:zhuren 3:jingli 4:dongshizhang) >";
cin>>Employee::EmployeeGrade;
while(Employee::EmployeeGrade !=1&&
Employee::EmployeeGrade !=2&&
Employee::EmployeeGrade !=3&&
Employee::EmployeeGrade !=4)
{
cout<<"Your Input Error! Input Again be careful:)"<<endl;
cout<<"new Employee Grade (1:zhiyuan 2:zhuren 3:jingli 4:dongshizhang) >";
cin>>Employee::EmployeeGrade;
EG[i] = Employee::EmployeeGrade;
}
//////////////////////////////////////////
cout<<"new EmployeeWorkTime >";
cin>>Employee::EmployeeWorkTime;
//////////////////////////////////////////
Employee::EmployeePay = Employee::Pay(EG[i]);
EP[i] = Employee::EmployeePay;
break;
}
}
dbo.WriteIn(0);
}
void Employee::DeleteInfo()
{
int cNum = 1000;
DBOperate dbo;
dbo.ReadOut();
Employee::ShowInfo();
cout<<"Please input the Employee's Num >";
cin>>cNum;
int MN;
MN = Employee::MaxNum();
for(int i=0;i<MN;i++)
{
if(ENum[i] == cNum)
{
cout<<"***********************************"<<endl;
cout<<"Your choice's the Employee"<<endl;
cout<<"**********************************"<<endl;
cout<<"* EmployeeName >"<<EN[i]<<endl;
cout<<"* EmployeeNum >"<<ENum[i]<<endl;
cout<<"* EmployeeDepart >"<<ED[i]<<endl;
cout<<"* EmployeeGrade >"<<EG[i]<<endl;
cout<<"* EmployeeWorkTime >"<<EWT[i]<<endl;
cout<<"* EmployeePay >"<<EP[i]<<endl;
cout<<"**********************************"<<endl;
}
}
if(i==MN-1)
dbo.WriteIn(-1);
else
{
for(int j=i;j<MN-1;j++)
{
EN[j] = EN[j+1];
}
dbo.WriteIn(-1);
}
cout<<"Delete Success ! "<<endl;
}
float Employee::Pay(int EG)
{
float tmpPay;
tmpPay = Employee::EmployeeBasePay + EG*Employee::EmployeeBasePay;
return tmpPay;
}
/////////////////////////////////////////////////
void DBOperate::WriteIn(int iflag)
{
DBOperate::RefreshMaxNum(iflag);
ofstream myf("c:\\Employee.txt");
Employee e;
int MN;
MN = e.MaxNum();
for(int i=0;i<MN;i++)
{
myf<<EN[i]<<'\n'<<ENum[i]<<'\n'<<ED[i]<<'\n'<<EG[i]<<'\n'<<EWT[i]<<'\n'<<EP[i]<<'\n';
}
myf.close();
return;
}
void DBOperate::ReadOut()
{
ifstream myf("c:\\Employee.txt");
char tmpName[50];
char tmpDepart[50];
Employee e;
int MN = 0;
MN = e.MaxNum();
for(int i=0 ;i<MN;i++)
{
myf>>tmpName>>DBOperate::EmployeeNum>>tmpDepart>>DBOperate::EmployeeGrade>>DBOperate::EmployeeWorkTime>>DBOperate::EmployeePay;
DBOperate::EmployeeName = new char[strlen(tmpName)+1];
DBOperate::EmployeeDepart = new char[strlen(tmpDepart)+1];
strcpy(DBOperate::EmployeeName,tmpName);
strcpy(DBOperate::EmployeeDepart,tmpDepart);
EN[i] = DBOperate::EmployeeName;
ENum[i] = DBOperate::EmployeeNum;
ED[i] = DBOperate::EmployeeDepart;
EG[i] = DBOperate::EmployeeGrade;
EWT[i] = DBOperate::EmployeeWorkTime;
EP[i] = DBOperate::EmployeePay;
}
myf.close();
}
void DBOperate::RefreshMaxNum(int iflag)
{
int MaxNum = 0;
ifstream myif("c:\\EmployeeMaxNum.txt");
myif>>MaxNum;
myif.close();
MaxNum = MaxNum+iflag;
ofstream myof("c:\\EmployeeMaxNum.txt");
myof<<MaxNum;
myof.close();
}
//////////////main////////////////
void main()
{
int c2 = 0;
while(c2!=5)
{
cout<<"Employee Information Manage System"<<endl;
cout<<"******************************************"<<endl;
cout<<"* Employee List-----------1"<<endl;
cout<<"* Add New Employee Information-----------2"<<endl;
cout<<"* Refresh Employee Information-----------3"<<endl;
cout<<"* Delete Employee Information-----------4"<<endl;
cout<<"******************************************"<<endl;
cout<<"* Exit EIMS------------5"<<endl;
cout<<"******************************************"<<endl;
cout<<"Input your choice on here > ";
cin>>c2;
Employee e;
DBOperate dbo;
switch(c2)
{
case 1:
dbo.ReadOut();
e.ShowInfo();
break;
case 2:
e.NewInfo();
break;
case 3:
e.RefreshInfo();
break;
case 4:
e.DeleteInfo();
break;
case 5:
break;
default:
cout<<"Error! Your Choice doesn't Exit"<<endl;
}
if(c2 == 5)
break;
}
exit(1);
}