公司员工管理系统方案

公司员工管理系统方案
公司员工管理系统方案

/////////////////////////////////////////////////////////

//公司员工管理系统--CEMS

#include //文件操作头文件

#include //包含system()等函数的头文件#include //字符串处理头文件

#include //输入输出流重载需要的头文件#include

//////////////////////////////////////////////////////////

// 工资明细结构体

typedef struct WAGE

{

float Base_Wage; // 基本工资

float Merit_Wage; // 绩效工资

float Sum_Wage; // 总工资

}WAGE;

// 包括职工、职工号的工资记录

typedef struct Emplo_Wage

{

char id[10]; // 职工编号

char name[10]; // 职工

WAGE data; // 工资

}Emplo_Wage;

typedef struct Node

{

char E_id[10]; //职工号

char E_name[10]; //

char E_sex[3]; //性别

char E_dep[20]; //部门

char E_job[20]; //职务

float E_wage; //工资

struct Node *prior; //前驱指针

struct Node *next; //后继指针

}Node,*DLink;

//////////////////////////////////////////////////////////

// 工资大于1000的员工,超过部门需要按税率交税

float Tax_Rate1=0.05f; // 3000 以下

float Tax_Rate2=0.1f; // 3000-8000

float Tax_Rate3=0.15f; // 8000 以上

void SetWage(DLink p);

//////////////////////////////////////////////////////////

// 职工类

class employee

{

private:

Node data; // 结构体类型的数据成员public:

friend ostream & operator<<(ostream & stream,const DLink p); //友元重载输出

流运算符

friend istream & operator>>(istream & stream,DLink p);

//友元重载输入

流运算符

employee(); // 构造函数

DLink CreateLink(); // 创建链表

DLink InsertNode(DLink Head); // 插入一个结点};

///////////////////////////////////////////////////////////

// 全局常量,一个结点的大小

const int NUM=sizeof(Node);

///////////////////////////////////////////////////////////

// 重载输出流运算符

ostream & operator<<(ostream & stream,const DLink p)

{

stream<E_id<

(10)<E_name<E_sex

<E_dep<

(15)<E_job<E_wage<

}

///////////////////////////////////////////////////////////

// 重载输入流运算符

istream & operator>>(istream & stream,DLink p)

{

cout<<"姓名:"; //输入

stream>>p->E_name;

cout<<"性别:"; //输入性别

stream>>p->E_sex;

cout<<"部门:"; //输入所在部门

stream>>p->E_dep;

cout<<"职务:"; //输入职务

stream>>p->E_job;

SetWage(p); //输入工资

cout<

return stream;

}

//////////////////////////////////////////////////////////

//构造函数

employee::employee()

{ }

//////////////////////////////////////////////////////////

//创建链表(申请一个头结点)

DLink employee::CreateLink()

{

DLink Head;

Head=new Node; //申请一个空间

Head->prior=NULL;

Head->next=NULL;

return Head;

}

//////////////////////////////////////////////////////////

//插入结点

DLink employee::InsertNode(DLink Head)

{

DLink p;

ofstream file("EmployeeInfo.txt",ios::app); // 打开文件if(!file)

{ cout<<"Cannot open the file!\n"; return 0; }

p=new Node;

cout<<"请输入员工信息<以'00'结束>:\n";

cout<<"职工号:";

cin>>p->E_id;

while(strcmp(p->E_id,"00")) //循环输入,以"00"结束输入

{

cin>>p;

p->prior=Head;

p->next=Head->next;

if(Head->next!=NULL) //如果不是空链

Head->next->prior=p;

Head->next=p;

file.write((char *)p,NUM);

p=new Node;

cout<<"请输入员工信息<以'00'结束>:\n";

cout<<"ID:";

cin>>p->E_id;

}

file.close(); //关闭文件

printf("录入完毕...\n");

return Head;

}

///////////////////////////////////////////////////////////

//输出格式

void Print_Format()

{

cout<

"<

<<""<

<

"<

<

//////////////////////////////////////////////////////////

//设置工资税率

void SetTRate()

{

do{

cout<<"请输入税率<3000以下><小数形式(0.0-1.0)>:";

cin>>Tax_Rate1;

}while(Tax_Rate1>1||Tax_Rate1<0);

do{

cout<<"请输入税率<3000-8000><小数形式(0.0-1.0)>:";

cin>>Tax_Rate2;

}while(Tax_Rate2>1||Tax_Rate2<0);

do{

cout<<"请输入税率<8000以上><小数形式(0.0-1.0)>:";

cin>>Tax_Rate3;

}while(Tax_Rate3>1||Tax_Rate3<0);

}

//////////////////////////////////////////////////////////

//设置一个员工的明细工资

void SetWage(DLink p)

{

// int flag=0;

float sum;

Emplo_Wage *s;

s = new Emplo_Wage;

// q = new Emplo_Wage;

fstream file;

file.open("Employee_Wage_Info.txt",ios::app);

if(!file)

{ cout<<"打开工资文件失败!"<

cout<<"基本工资:";

cin>>s->data.Base_Wage; // 设置基本工资

cout<<"绩效工资:";

cin>>s->data.Merit_Wage; // 设置绩效工资

sum=s->data.Base_Wage + s->data.Merit_Wage;

if(sum<1000)

s->data.Sum_Wage=sum;

else if(sum<3000)

s->data.Sum_Wage=(sum-1000) * (1-Tax_Rate1)+1000;

else if(sum<8000)

s->data.Sum_Wage=(sum-3000) * (1-Tax_Rate2)+3000;

else

s->data.Sum_Wage=(sum-8000) * (1-Tax_Rate3)+8000;

p->E_wage=s->data.Sum_Wage; // 总工资

strcpy(s->id , p->E_id);

strcpy(s->name , p->E_name);

file.write((char *)s,sizeof(Emplo_Wage)); // 写入文件file.close();

}

//////////////////////////////////////////////////////////

//输出

void Print()

{

int n,count=0; //n--输入的每屏显示的记录数,count--计数DLink p;

ifstream file("EmployeeInfo.txt"); // 打开文件if(!file)

{ cout<<"Cannot open the file!\n"; return; }

p=new Node;

cout<<"每一屏显示多少记录? :";

cin>>n;

system("cls"); //清屏

Print_Format(); //输出字段名

while(!file.eof())

{

file.read((char *)p,NUM);

if(file.fail())

break;

if(n==count) //控制每一屏显示的记录条数

{

system("pause"); //暂停

system("cls"); //清屏

count=0; //计数器清零

Print_Format();

}

cout<

count++;

}

}

//////////////////////////////////////////////////////////

//修改函数

void Amend()

{

int n; //用于选择修改选项

char id[10]; //存放输入的需要修改信息的职工号

DLink p;

p=new Node;

fstream file;

file.open("EmployeeInfo.txt",ios::in|ios::out); // 以读写方式打开

if(!file)

{ cout<<"Cannot open the file!\n"; return; }

cout<<"请输入需要修改的职工号:";

cin>>id;

while(!file.eof())

{

file.read((char *)p,NUM);

if(file.fail())

break;

if(!strcmp(p->E_id,id))

break;

}

if(file.eof())

{

printf("没有这个职工号!\n");

return;

}

cout<<"可以修改的项目有:1-部门2-职务3-工资\n";

cout<<"全部修改请按0,否则输入对应的项目号:";

cin>>n;

if(n==0) // 修改所在部门、职务、工资

{

cout<<"新的部门名称:";

cin>>p->E_dep;

cout<<"新的职务:";

cin>>p->E_job;

SetWage(p);

}

else if(n==1) // 修改所在部门

{

cout<<"新的部门名称:";

cin>>p->E_dep;

}

else if(n==2) // 修改职务

{

cout<<"新的职务:";

cin>>p->E_job;

}

else if(n==3) // 修改工资

{

SetWage(p);

}

else

printf("输入错误!\n");

file.seekp(-1*NUM,ios::cur); //写指针回跳一条记录,以更新记录file.write((char *)p,NUM); //写入更新后的记录

if(n==0||n==1||n==2||n==3)

printf("修改成功!\n"); //操作提示

file.close(); //关闭文件

}

/////////////////////////////////////////////////////////

//查询函数

void Query()

{

char Query_Value[20]; //存放输入的需要查询的或部门名称

int flag=0,n; //是否查询到的标志

DLink p;

p=new Node;

ifstream file("EmployeeInfo.txt"); //打开文件

if(!file)

{ cout<<"Cannot open the file!\n"; return; }

cout<<"通过哪种方式查询:"<

cout<<"\t1-- 2--所在部门"<

cout<<"请选择:";

cin>>n;

if(n==1)

{

cout<<"输入需查询的职工:";

cin>>Query_Value;

}

else if(n==2)

{

cout<<"输入需查询的职工所在部门:";

cin>>Query_Value;

}

else

{ cout<<"输入错误!"<

while(!file.eof())

{

file.read((char *)p,NUM);

if(file.fail())

break;

if(n==1) // 按查找

{

if(!strcmp(p->E_name,Query_Value))

{ Print_Format(); cout<

}

else if(n==2) //按所在部门查找

{

if(!strcmp(p->E_dep,Query_Value))

{ Print_Format(); cout<

}

}

if(flag==0)

printf("查询失败,没有相应记录!\n");

file.close(); //关闭文件}

//////////////////////////////////////////////////////////

//删除函数

void Delete()

{

char id[10]; //存放输入的职工号

char name[10]; //存放输入的职工

int count1=0,count2=0; //count1-总的记录数,count2-删除记录以后的总记录数

DLink p;

p=new Node;

ifstream file("EmployeeInfo.txt");

if(!file)

{ cout<<"Cannot open the file!\n"; return; }

ofstream newfile("NewEmployeeInfo.txt");

if(!newfile)

{ cout<<"Cannot open the file!\n"; return; }

cout<<"请输入需要删除的职工号:";

cin>>id;

cout<<"请输入需要删除的职工:";

cin>>name;

while(!file.eof())

{

file.read((char *)p,NUM);

count1++;

if(file.fail())

break;

if(strcmp(p->E_name,name)||strcmp(p->E_id,id))

{

newfile.write((char *)p,NUM);

count2++;

}

}

file.close(); //关闭文件newfile.close(); //关闭文件

remove("EmployeeInfo.txt"); // 删除原来的

EmployeeInfo.txt

rename("NewEmployeeInfo.txt","EmployeeInfo.txt"); // 重命名

if(count1==count2)

printf("没有这个记录!\n");

else

printf("删除成功!\n");

}

/////////////////////////////////////////////////////////

// 查看职工工资明细

void showwage()

{

int n;

char temp1[10];

Emplo_Wage temp2;

ifstream file("Employee_Wage_Info.txt");

if(!file)

{ cout<<"职工工资表文件不能打开!"<

cout<<"请选择操作项:"<

cout<<"1--查看某个职工工资明细2--查看全部职工工资明细"<

cin>>n;

if(n==1) // 输出某一个职工的工资明细

{

cout<<"请输入职工编号:";

cin>>temp1;

}

else if(n!=2)

{ cout<<"输入错误!"<

cout<

"<

<<""

<

"<

<

<

while(!file.eof())

{

file.read((char *)&temp2,sizeof(Emplo_Wage));

if(file.fail())

break;

if(n==1) // 输出某一个职工的工资明细

{

if(!strcmp(temp2.id,temp1))

cout<

<

<

<

<

break;

}

else // 输出全部职工的工资明细

{

cout<

<

<

<

<

}

}

}

//////////////////////////////////////////////////////////

//欢迎界面

void startface()

{

system("color 0A"); //设置屏幕显示的前景色、背景色

system("cls"); //清屏

//

cout<<"************************************************************** *****************"<

dl;

cout<

cout<<" ********************** ******************

"<

cout<<" *

*

"<

cout<<" * 欢迎进入公司员工管理系统*

"<

cout<<" *

*

"<

cout<<" ********************** ******************

"<

cout<

}

//////////////////////////////////////////////////////////

//主菜单

void menu()

{

system("cls"); //清屏

cout<

cout<<" | *********************** 主菜

单********************** |"<

cout<<" |

|"<

cout<<" | 1、设置工资税率|"<

cout<<" | 2、

插入职工信息|"<

cout<<" | 3、显示职工信息|"<

cout<<" | 4、删除职工信息|"<

cout<<" | 5、修改职工信息|"<

cout<<" | 6、查询职工信息|"<

cout<<" | 7、查看职工工资明细|"<

cout<<" | 8、退出系统|"<

|"<

}

//////////////////////////////////////////////////////////

//主函数

void main()

{

int n;

employee EM; //定义一个对象

DLink Head; //定义一个链表

startface(); //调用欢迎界面函数

while(1) //菜单循环

{

system("cls");

menu();

cout<<"请选择:";

cin>>n;

switch(n)

{

case 1: SetTRate();

system("pause");

break;

case 2: Head=EM.CreateLink();

Head=EM.InsertNode(Head);

system("pause");

break;

case 3: Print();

system("pause");

break;

case 4: Delete();

system("pause"); break;

case 5: Amend();

system("pause"); break;

case 6: Query();

system("pause"); break;

case 7: showwage();

system("pause"); break;

case 8: exit(0);

default:printf("输入错误!\n"); system("pause");

}

}

}

相关主题
相关文档
最新文档