当前位置:文档之家› 工资管理系统源代码c++

工资管理系统源代码c++

#include<fstream.h>
#include<string>
class STAFF //定义一个STAFF类,包含7个公有数据成员和2个成员函数
{
public:
int login;char name[20];int no;char sex[20];char year[20];char level[20];
void input(); //成员函数声明
void output();
};
void STAFF::input() //定义成员函数input(),用于输入员工信息
{
cout<<"\n\t\t 输入姓名:";cin>>name;
cout<<"\n\t\t 输入员编号:";cin>>no;
cout<<"\n\t\t 输入员工性别:";cin>>sex;
cout<<"\n\t\t 输入记录时间(2014/2/1):";cin>>year;
cout<<"\n\t\t 输入员工工资等级:";cin>>level;
cout<<"\n\t\t ******输入完成******\n"<<endl;
}
void STAFF::output() //定义成员函数output(),用于输出员工信息
{
//cout<<"\n\t\t 录入序号:"<<login<<"\n";
cout<<"\n\t\t 姓名:"<<name<<"\n";
cout<<"\n\t\t 编号:"<<no<<"\n";
cout<<"\n\t\t 性别:"<<sex<<"\n";
cout<<"\n\t\t 记录时间:"<<year<<"\n";
cout<<"\n\t\t 工资等级:"<<level<<endl;
}
void screen(); //自定义函数screen()的声明,该函数用于显示系统主菜单
int count() //count()用于计算文件中存储有几个员工的信息
{
ifstream infile("staff_information.dat",ios::in|ios::binary|ios::nocreate);
infile.seekg(0,ios::end); //文件指针移到文件尾
return infile.tellg()/sizeof(STAFF);
}
void xinzeng() //xinzeng():增加员工信息
{
STAFF st;
ofstream outfile("staff_information.dat",ios::out|ios::binary|ios::app);
if (!outfile)
{
cout<<"\n\t\t 文件打开错误!";
return;
}
st.login=count()+1; //录入员工信息时,计算对应的登录号
cout<<"\n\n\t\t 第"<<st.login<<"个员工\n";
st.input();
outfile.write((char*)&st,sizeof(st));
outfile.close();
system("pause");
screen(); //函数结束,返回主菜单
}
void liulan() //liulan():浏览所有员工信息
{
STAFF st;
ifstream infile("staff_information.dat",ios::in|ios::binary|ios::nocreate);
if(!infile)
{
cout<<"\n\t\t 打开输入文件出错!\n"<<endl;
system("pause");
screen();
}
infile.seekg(0,ios::end);//文件指针移到文件尾
if(!infile.tellg()) //判断文件内信息是否为空
cout<<"\n\t\t 系统内员工信息为空!"<<endl;
else
{
infile.seekg(0,ios::beg); //文件指针回到文件头
cout<<"\n***********

*********************共有"<<count()<<"条记录*************************************\n";
cout<<"\n姓名\t编号\t性别\t记录时间(2014/01/01)\t工资等级"<<endl;
for(int j=1;j<=count();j++)
{
infile.read((char*)&st,sizeof(st));
cout<<https://www.doczj.com/doc/d116696268.html,<<"\t"<<st.no<<"\t"<<st.sex<<"\t"<<st.year<<"\t\t"<<st.level<<endl;
}
}
system("pause");
screen(); //函数结束,返回主菜单
}
void chaxun(); //后面的by_name()和by_author()会调用chaxun(
),所以须添加函数声明
void by_name() //by_name():按姓名查找并输出
{
cout<<"\n\t\t 输入姓名:";
char na[20];cin>>na;
STAFF st;
ifstream infile("staff_information.dat",ios::in|ios::binary|ios::nocreate);
if(!infile)
{
cout<<"\n\t\t 打开输入文件出错!\n"<<endl;
system("pause");
chaxun();
}
int i=count(),k=0; //i存储文件中员工的数量,k用于判断所查的文件名是否存在
for(int j=1;j<=i;j++)
{
infile.read((char*)&st,sizeof(st));
if(strcmp(na,https://www.doczj.com/doc/d116696268.html,)!=0) //比较输入的文件名和文件中存储的文件名
k++; //当两文件名不相同时,k自增1,否则不变
}
if(k==i) //若k=i,说明文件中没有一个文件名与输入的相同,即所查的文件名不存在
{
cout<<"\n\t\t 没有找到该员工!\n"<<endl;
}
else
{
infile.seekg(0);
cout<<"\n\n";
for(int j=1;j<=i;j++)
{
infile.read((char*)&st,sizeof(st));
if(strcmp(na,https://www.doczj.com/doc/d116696268.html,)==0) //找到文件名,输出对应的信息
{
st.output();
}
}
}
system("pause");
chaxun(); //结束查询,返回子菜单
}
void by_no() //按编号查找并输出
{
cout<<"\n\t\t 输入编号:";
int n;cin>>n;
STAFF st;
ifstream infile("staff_information.dat",ios::in|ios::binary|ios::nocreate);
if(!infile)
{
cout<<"\n\t\t 打开输入文件出错!\n"<<endl;
system("pause");
chaxun();
}
int i=count(),k=0;
for(int j=1;j<=i;j++)
{
infile.read((char*)&st,sizeof(st));
if(n!=st.no)
k++;
}
if(k==i)
{
cout<<"\n\t\t 没有找到该员工编号!\n"<<endl;
}
else
{
infile.seekg(0);
cout<<"\n\n";
for(int j=1;j<=i;j++)
{
infile.read((char*)&st,sizeof(st));
if(n==st.no)
{
st.output();
}
}
}
infile.close();
system("pause");
chaxun();
}
void chaxun() //chaxun():建立查询子菜单
{
system("cls");
cout<<" ╔═════════════════════════════════════╗\n";
cout<<" ║

║\n";
cout<<" ║ 1 按 姓 名 2 按 编 号 ║\n";
cout<<" ║ ║\n";
cout<<" ║ 0:退出 ║\n";
cout<<" ╚═════════════════════════════════════╝\n";
cout<<"请选择(0-2):";
int option1;cin>>option1;
switch(option1)
{
case 1:by_name();break;
case 2:by_no();break;
case 0:screen();break;
default:
cout<<"\n\t\t 输入错误";
system("pause");
chaxun();
}
}
void xiugai() //修改 按姓名查找并输出
{
cout<<"\n\t\t 输入
姓名:";
char na[20];cin>>na;
STAFF st;
fstream mfile("staff_information.dat",ios::in|ios::out|ios::binary|ios::nocreate);
if(!mfile)
{
cout<<"\n\t\t 打开输入文件出错!\n"<<endl;
return;
}
int i=count(),k=0; //i存储文件中书的数量,k用于判断所查的文件名是否存在
for(int j=1;j<=i;j++)
{
mfile.read((char*)&st,sizeof(st));
if(strcmp(na,https://www.doczj.com/doc/d116696268.html,)!=0) //比较输入的文件名和文件中存储的文件名
k++; //当两文件名不相同时,k自增1,否则不变
}
if(k==i) //若k=i,说明文件中没有一个文件名与输入的相同,即所查的文件名不存在
{
cout<<"\n\t\t 没有找到该员工!\n"<<endl;
}
else
{
mfile.seekg(0);
cout<<"\n\n";
for(int j=1;j<=i;j++)
{
mfile.read((char*)&st,sizeof(st));
if(strcmp(na,https://www.doczj.com/doc/d116696268.html,)==0) //找到文件名,输出对应的信息
{
mfile.seekg((j-1)*sizeof(st)); //文件指针移到开始修改的位置
mfile.read((char*)&st,sizeof(st));
st.output();
cout<<"对信息进行修改"<<endl;
st.input();
mfile.seekg((j-1)*sizeof(st)); //文件指针移回开始修改的位置
mfile.write((char*)&st,sizeof(st)); //重新写入该信息
cout<<"\n\t\t ******修改成功******\n"<<endl;
}
}
}
mfile.close();
system("pause");
screen(); //结束查询,返回子菜单
}
void shanchu() //删除员工信息
{
STAFF st;int n;
cout<<"\n\n\t\t 输入要删除的员工编号:";cin>>n;
ifstream infile("staff_information.dat",ios::in|ios::binary|ios::nocreate);
if(!infile)
{
cout<<"\n\t\t 打开输入文件出错!\n"<<endl;
return;
}
fstream mfile("staff_information2.dat",ios::out|ios::in|ios::binary);
//建立名为staff_information2的中间文件,存储除被删除员工以外的信


if (!mfile)
{
cout<<"\n\t\t 文件打开错误!"<<endl;
return;
}
int i=count(),k=0;
for(int j=1;j<=i;j++)
{
infile.read((char*)&st,sizeof(st));
if(n!=st.no) //比较输入的文件名和文件中存储的文件名
k++; //当两文件名不相同时,k自增1,否则不变
}
if(k==i) //若k=i,说明文件中没有一个文件名与输入的相同,即所查的文件名不存在
{
cout<<"\n\t\t 没有找到该员工编号!\n"<<endl;
infile.close();
mfile.close();
}
else
{
infile.seekg(0,ios::beg);
for(int j=1;j<=i;j++)
{
infile.read((char*)&st,sizeof(st));
if(n!=st.no)
//如果文件名不相同,则把信息复制到stok_information2.dat中
{
mfile.write((char*)&st,sizeof(st));
}
else
break; //如果文件名相同,则不复制信息,直接跳出循环
}
for(j++;j<=i;j++)
{
infile.read((char*)&st,sizeof(st));
st.login=st.lo
gin-1;
mfile.write((char*)&st,sizeof(st));
}

infile.close();
ofstream outfile("staff_information.dat",ios::out|ios::binary);
//建立重名文件,清空原有信息
if (!outfile)
{
cout<<"\n\t\t 文件打开错误!"<<endl;
return;
}
mfile.seekg(0,ios::beg); //文件指针移到文件头
for(j=1;j<i;j++)
{
mfile.read((char*)&st,sizeof(st));
//将stok_information2.dat中的信息复制到stok_information.dat
outfile.write((char*)&st,sizeof(st));
}
mfile.close();
outfile.close();
cout<<"\n\t\t ******删除成功******\n"<<endl;
}
system("pause");
screen();
}
void quanshan() //quanshan():删除文件中全部信息
{
ifstream infile("staff_information.dat",ios::in|ios::binary|ios::nocreate|ios::trunc);
if(!infile)
{
cout<<"\n\t\t 打开输入文件出错!\n"<<endl;
return;
}
infile.close();
cout<<"\n\t\t ******全删成功******\n"<<endl;
system("pause");
screen();
}
class RANK //定义一个BOOK类,包含7个公有数据成员和2个成员函数
{
public:
int login;char level[20];float bsgz;float gwgz;float jtbt;
void input(); //成员函数声明
void output();
};
void RANK::input() //定义成员函数input(),用于输入工资等级信息
{
cout<<"\n\t\t 输入工资等级:";cin>>level;
cout<<"\n\t\t 输入基本工资:";cin>>bsgz;
cout<<"\n\t\t 输入岗位工资:";cin>>gwgz;
cout<<"\n\t\t 输入交通补贴:";cin>>jtbt;
cout<<"\n\t\t ******输入完成******\n"<<endl;
}
void RANK::output() //定义成员函数output(),用于输出工资等级信息
{
cout<<"\n\t\t 工资等级:"<<level<<"\n";
cout&l

t;<"\n\t\t 基本工资:"<<bsgz<<"\n";
cout<<"\n\t\t 岗位工资:"<<gwgz<<"\n";
cout<<"\n\t\t 交通补贴:"<<jtbt<<"\n";
cout<<"\n\t\t ******输出完成******\n"<<endl;
}
void screen1(); //自定义函数screen1()的声明,该函数用于显示系统主菜单
int count1() //count1()用于计算文件中存储有几个等级的信息
{
ifstream infile("rank_information.dat",ios::in|ios::binary|ios::nocreate);
infile.seekg(0,ios::end); //文件指针移到文件尾
return infile.tellg()/sizeof(RANK);
}
void xinzeng1() //xinzeng1():增加等级信息
{
RANK ra;
ofstream outfile("rank_information.dat",ios::out|ios::binary|ios::app);//输出方式打开、二进制、追加、向文件输出的内容加到文件尾
if (!outfile)
{
cout<<"\n\t\t 文件打开错误!";
return;
}
ra.login=count1()+1; //录入新的等级时,计算对应的录入编号
cout<<"\n\n\t\t 第"<<ra.login<<"个等级录入\n";
ra.input();
outfile.write((char*)&ra,sizeof(ra));
outfile.close();
system("pause");
screen1();//函数结束,返回主菜单
}
void liulan1()
//liulan1():浏览所有信息
{
RANK ra;
ifstream infile("rank_information.dat",ios::in|ios::binary|ios::nocreate);
if(!infile)
{
cout<<"\n\t\t 打开输入文件出错!\n"<<endl;
system("pause");
screen1();
}
infile.seekg(0,ios::end);//文件指针移到文件尾
if(!infile.tellg()) //判断文件内信息是否为空
cout<<"\n\t\t 工资等级信息为空!"<<endl;
else
{
infile.seekg(0,ios::beg); //文件指针回到文件头
cout<<"\n********************************共有"<<count1()<<"条记录*************************************\n";
cout<<"工资等级\t基本工资\t岗位工资\t交通补贴";
for(int j=1;j<=count1();j++)
{
infile.read((char*)&ra,sizeof(ra));
cout<< "\n"<<ra.level<<"\t\t"<<ra.bsgz<<"\t\t"<<ra.gwgz<<"\t\t"<<ra.jtbt<<endl;
}
}
system("pause");
screen1();
}
void chaxun1(); //后面的by_name1()和by_author1()会调用chaxun1(),所以须添加函数声明
void by_level1() //by_name1():按等级查找并输出
{
cout<<"\n\t\t 输入工资等级:";
char l[20];cin>>l;
RANK ra;
ifstream infile("rank_information.dat",ios::in|ios::binary|ios::nocreate);
if(!infile)
{
cout<<"\n\t\t 打开输入文件出错!\n";
system("pause");
chaxun1();
}
int i=count1(),k=0; //i存

储文件中等级的数量,k用于判断所查的文件名是否存在
for(int j=1;j<=i;j++)
{
infile.read((char*)&ra,sizeof(ra));
if(strcmp(l,ra.level)!=0) //比较输入的文件名和文件中存储的文件名
k++; //当两文件名不相同时,k自增1,否则不变
}
if(k==i) //若k=i,说明文件中没有一个文件名与输入的相同,即所查的文件名不存在
{
cout<<"\n\t\t 没有找到该工资等级!\n"<<endl;
}
else
{
infile.seekg(0);
cout<<"\n\n";
for(int j=1;j<=i;j++)
{
infile.read((char*)&ra,sizeof(ra));
if(strcmp(l,ra.level)==0) //找到文件名,输出对应的信息
{
ra.output();
}
}
}
infile.close();
system("pause");
chaxun1(); //结束查询,返回子菜单
}
void by_gwgz1() //按岗位工资查找并输出
{
cout<<"\n\t\t 输入岗位工资:";
float g;cin>>g;
RANK ra;
ifstream infile("rank_information.dat",ios::in|ios::binary|ios::nocreate);
if(!infile)
{
cout<<"\n\t\t 打开输入文件出错!\n";
system("pause");
chaxun1();
}
int i=count1(),k=0;
for(int j=1;j<=i;j++)
{
infile.read((char*)&ra,sizeof(ra));
if(g!=ra.gwgz)
k++;
}
if(k==i)
{
cout<<"\n\t\t 没有找到该岗位工资!\n"<<endl;
}
else
{
infile.seekg(0);
cout<<"\n\n";
for(int j=1;j<=i;j++)
{
infile.read((char*)&ra,sizeof(ra));
if(g==ra.gwgz)
{
ra.output();
}
}
}
infile.close();
system("pause");
chaxun1();
}
void chaxun1() //chaxun1():建立查询
子菜单
{
system("cls");
cout<<" ╔═════════════════════════════════════╗\n";
cout<<" ║ ║\n";
cout<<" ║ 1 按工资等级 2 按岗位工资 ║\n";
cout<<" ║ ║\n";
cout<<" ║ 0:退出 ║\n";
cout<<" ╚═════════════════════════════════════╝\n";
cout<<"请选择(0-2):";
int option1;cin>>option1;
switch(option1)
{
case 1:by_level1();break;
case 2:by_gwgz1();break;
case 0:screen1();return;
default:cout<<"\n\t\t 输入错误"<<endl;
system("pause");
chaxun1();
}
}
void xiugai1() //by_name():按等级查找并输出
{
cout<<"\n\t\t 输入工资等级:";
char l[20];cin>>l;
RANK ra;
fstream mfile("ra

nk_information.dat",ios::in|ios::out|ios::binary|ios::nocreate);
if(!mfile)
{
cout<<"\n\t\t 打开输入文件出错!\n";
return;
}
int i=count1(),k=0; //i存储文件中书的数量,k用于判断所查的文件名是否存在
for(int j=1;j<=i;j++)
{
mfile.read((char*)&ra,sizeof(ra));
if(strcmp(l,ra.level)!=0) //比较输入的文件名和文件中存储的文件名
k++; //当两文件名不相同时,k自增1,否则不变
}
if(k==i) //若k=i,说明文件中没有一个文件名与输入的相同,即所查的文件名不存在
{
cout<<"\n\t\t 没有找到该工资等级!\n"<<endl;
}
else
{
mfile.seekg(0);
cout<<"\n\n";
for(int j=1;j<=i;j++)
{
mfile.read((char*)&ra,sizeof(ra));
if(strcmp(l,ra.level)==0) //找到文件名,输出对应的信息
{
mfile.seekg((j-1)*sizeof(ra)); //文件指针移到开始修改的位置
mfile.read((char*)&ra,sizeof(ra));
ra.output();
cout<<"对信息进行修改"<<endl;
ra.input();
mfile.seekg((j-1)*sizeof(ra)); //文件指针移回开始修改的位置
mfile.write((char*)&ra,sizeof(ra)); //重新写入该等级信息
cout<<"\n\t\t ******修改成功******\n"<<endl;
}
}
}
mfile.close();
system("pause");
screen1(); //结束查询,返回子菜单
}
void shanchu1() //删除等级信息
{
RANK ra;char l[20];
cout<<"\n\n\t\t 输入要删除的工资等级:";cin>>l;
ifstream infile("rank_information.dat",ios::in|ios::binary|ios::nocreate);
if(!infile)
{
cout<<"\n\t\t 打开输入文件出错!\n"<<endl;
return;
}
fstream mfile("rank_information2.dat",ios::out|ios::in|ios::binary);
//建立名为rank_information2的中间文件,存储除被删除等级
以外的信息
if (!mfile)
{
cout<<"\n\t\t 文件打开错误!"<<endl;
return;
}
int i=count1(),k=0;
for(int j=1;j<=i;j++)
{
infile.read((char*)&ra,sizeof(ra));
if(strcmp(l,ra.level)!=0) //比较输入的文件名和文件中存储的文件名
k++; //当两文件名不相同时,k自增1,否则不变
}
if(k==i) //若k=i,说明文件中没有一个文件名与输入的相同,即所查的文件名不存在
{
cout<<"\n\t\t 没有找到该等级!\n"<<endl;
infile.close();
mfile.close();
}
else
{
infile.seekg(0,ios::beg);
for(int j=1;j<=i;j++)
{
infile.read((char*)&ra,sizeof(ra));
if(strcmp(l,ra.level)!=0)
//如果文件名不相同,则把信息复制到rank_information2.dat中
{
mfile.write((char*)&ra,sizeof(ra));
}
else
break; //如果文件名相同,则不复制信息,直接跳出循环
}
for(j++;j<=i;j++)
{
infile.read((char*)&ra,sizeof(ra));
ra.login=ra.login-1;

mfile.write((char*)&ra,sizeof(ra));
}
infile.close();
ofstream outfile("rank_information.dat",ios::out|ios::binary);
//建立重名文件,清空原有信息
if (!outfile)
{
cout<<"\n\t\t 文件打开错误!"<<endl;
return;
}
mfile.seekg(0,ios::beg); //文件指针移到文件头
for(j=1;j<i;j++)
{
mfile.read((char*)&ra,sizeof(ra));
//将book_information2.dat中的信息复制到book_information.dat
outfile.write((char*)&ra,sizeof(ra));
}
mfile.close();
outfile.close();
cout<<"\n\t\t ******删除成功******\n"<<endl;
}
system("pause");
screen1();
}
void quanshan1() //quanshan1():删除文件中全部信息
{
ifstream infile("rank_information.dat",ios::in|ios::binary|ios::nocreate|ios::trunc);
if(!infile)
{
cout<<"\n\t\t 打开输入文件出错!\n";
return;
}
infile.close();
cout<<"\n\t\t ******全删成功******\n"<<endl;
system("pause");
screen1();
}

class CHANGE //定义一个CHANGE类,包含7个公有数据成员和2个成员函数
{
public:
int login;int no;char month[20];float jlgz;float cfgz;
void input(); //成员函数声明
void output();
};
void CHANGE::input() //定义成员函数input(),用于输入工资变动信息
{
cout<<"\n\t\t 输入员工编号:";cin>>no;
cout<<"\n\t\t 输入月份:";cin>>month;
cout<<"\n\t\t 输入奖励工资:";cin>>jlgz;
cout<<"\n\t\t 输入惩罚工资:";cin>>cfgz;
cout<<"\n\t\t ******输入完成******\n"<<endl;
}
void CHANGE::output() //定义成员函数output(),用于输出工资变动信息
{
cout<<"\n\t\t 员工编号:"<<no<<"\n";
cout<<"\n\t\t 月份:"<<month<<"\n";
cout<<"\n\t\t 奖励工资:"<<jlgz<<"\n";
cout<<"\n\t\t 惩罚工资:"<<cfgz<<"\n"<<endl;
}

void screen2(); //自定义函数screen2()的声明,该函数用于显示系统主菜单
int count2() //count2()用于计算文件中存储有几个等级的信息
{
ifstream infile("change_information.dat",ios::in|ios::binary|ios::nocreate);
infile.seekg(0,ios::end); //文件指针移到文件尾
return infile.tellg()/sizeof(CHANGE);
}
void xinzeng2() //xinzeng2():增加信息
{
CHANGE ch;
ofstream outfile("CHANGE_information.dat",ios::out|ios::binary|ios::app);//输出方式打开、二进制、追加、向文件输出的内容加到文件尾
if (!outfile)
{
cout<<"\n\t\t 文件打开错误!"<<endl;
return;
}
ch.login=count2()

+1; //录入新信息时,计算对应的录入编号
cout<<"\n\n\t\t 第"<<ch.login<<"个录入\n"<<endl;
ch.input();
outfile.write((char*)&ch,sizeof(ch));
outfile.close();
system("pause");
screen2();//函数结束,返回主菜单
}
void liulan2() //liulan2():浏览所有信息
{
CHANGE ch;
ifstream infile("CHANGE_information.dat",ios::in|ios::binary|ios::nocreate);
if(!infile)
{
cout<<"\n\t\t 打开输入文件出错!\n"<<endl;
system("pause");
screen2();
}
infile.seekg(0,ios::end);//文件指针移到文件尾
if(!infile.tellg()) //判断文件内信息是否为空
cout<<"\n\t\t 员工变动信息为空!"<<endl;
else
{
infile.seekg(0,ios::beg); //文件指针回到文件头
cout<<"\n********************************共有"<<count2()<<"条记录*************************************\n";
cout<<"编号\t月份\t奖励\t惩罚";
for(int j=1;j<=count2();j++)
{
infile.read((char*)&ch,sizeof(ch));
cout<< "\n"<<ch.no<<"\t"<<ch.month<<"\t"<<ch.jlgz<<"\t"<<ch.cfgz<<endl;
}
}
system("pause");
screen2();
}
void chaxun2() //后面的by_name2()和by_author2()会调用chaxun2(),所以须添加函数声明
{
cout<<"\n\t\t 输入员工编号:";
int n;cin>>n;
CHANGE ch;
ifstream infile("change_information.dat",ios::in|ios::binary|ios::nocreate);
if(!infile)
{
cout<<"\n\t\t 打开输入文件出错!\n";
system("pause");
chaxun2();
}
int i=count2(),k=0; //i存储文件中信息的数量,k用于判断所查的文件名是否存在
for(int j=1;j<=i;j++)
{
infile.read((char*)&ch,sizeof(ch));
if(n!=ch.no) //比较输入的文件名和文件中存储的文件名
k++; //当两文件名不相同时,k自增1,否则不变
}
if(k==i) //若k=i,说明文件中没有一个文件名与输入的相同,即所查的文件名不存在
{
cout<<"\n\t\t 没有找到该员工编号!\n"<<endl;
}
else
{
infile.seekg(0);
cout<<"\n\n";
for(int j=1;j<=i;j++)
{
infile.read((char*)&ch,sizeof(ch));
if(n==ch.no) //找到文件名,输出对应的信息
{
ch.output();
}
}
}
infile.close();
system("pa
use");
screen2(); //结束查询,返回子菜单
}


void xiugai2() //后面的by_name2()和by_author2()会调用chaxun2(),所以须添加函数声明
{
cout<<"\n\t\t 输入员工编号:";
int n;cin>>n;
CHANGE ch;
fstream mfile("change_information.dat",ios::in|ios::out|ios::binary|ios::nocreate);
if(!mfile)
{
cout<<"\n\t

\t 打开输入文件出错!\n";
return;
}
int i=count2(),k=0; //i存储文件中信息的数量,k用于判断所查的文件名是否存在
for(int j=1;j<=i;j++)
{
mfile.read((char*)&ch,sizeof(ch));
if(n!=ch.no) //比较输入的文件名和文件中存储的文件名
k++; //当两文件名不相同时,k自增1,否则不变
}
if(k==i) //若k=i,说明文件中没有一个文件名与输入的相同,即所查的文件名不存在
{
cout<<"\n\t\t 没有找到该员工编号!\n"<<endl;
}
else
{
mfile.seekg(0);
cout<<"\n\n";
for(int j=1;j<=i;j++)
{
mfile.read((char*)&ch,sizeof(ch));
if(n==ch.no) //找到文件名,输出对应的信息
{
mfile.seekg((j-1)*sizeof(ch)); //文件指针移到开始修改的位置
mfile.read((char*)&ch,sizeof(ch));
ch.output();
cout<<"对信息进行修改"<<endl;
ch.input();
mfile.seekg((j-1)*sizeof(ch)); //文件指针移回开始修改的位置
mfile.write((char*)&ch,sizeof(ch)); //重新写入该等级信息
cout<<"\n\t\t ******修改成功******\n"<<endl;
}
}
}
mfile.close();
system("pause");
screen2(); //结束查询,返回子菜单
}
void shanchu2() //删除信息
{
CHANGE ch;int n;
cout<<"\n\n\t\t 输入要删除的员工编号:";cin>>n;
ifstream infile("change_information.dat",ios::in|ios::binary|ios::nocreate);
if(!infile)
{
cout<<"\n\t\t 打开输入文件出错!\n"<<endl;
return;
}
fstream mfile("change_information2.dat",ios::out|ios::in|ios::binary);
//建立名为CHANGE_information2的中间文件,存储除被删除等级以外的信息
if (!mfile)
{
cout<<"\n\t\t 文件打开错误!"<<endl;
return;
}
int i=count2(),k=0;
for(int j=1;j<=i;j++)
{
infile.read((char*)&ch,sizeof(ch));
if(n!=ch.no) //比较输入的文件名和文件中存储的文件名
k++; //当两文件名不相同时,k自增1,否则不变
}
if(k==i) //若k=i,说明文件中没有一个文件名与输入的相同,即所查的文件名不存在
{
cout<<"\n\t\t 没有找到该员工编号!\n"<<endl;
infile.close();
mfile.close();
}
else
{
infile.seekg(0,ios::beg);
for(int j=1;j<=i;j++)
{
infile.read((char*)&ch,sizeof(ch));
if(n!=ch.no)
//如果文件名不相同,则把信息复制到CHANGE_information2.dat中
{
mfile.write((char*)&ch,sizeof(ch));
}
else
break;
//如果文件名相同,则不复制信息,直接跳出循环
}
for(j++;j<=i;j++)
{
infile.read((char*)&ch,sizeof(ch));
ch.login=ch.login-1;
mfile.write((char*)&ch,sizeof(ch));
}
infile.close();
ofstream outfile("change_information.dat",ios::out|ios::binary);
//建立重名文

件,清空原有信息
if (!outfile)
{
cout<<"\n\t\t 文件打开错误!"<<endl;
return;
}
mfile.seekg(0,ios::beg); //文件指针移到文件头
for(j=1;j<i;j++)
{
mfile.read((char*)&ch,sizeof(ch));
//将book_information2.dat中的信息复制到book_information.dat
outfile.write((char*)&ch,sizeof(ch));
}
mfile.close();
outfile.close();
cout<<"\n\t\t ******删除成功******\n"<<endl;
}
system("pause");
screen2();
}
void quanshan2() //quanshan2():删除文件中全部信息
{
ifstream infile("change_information.dat",ios::in|ios::binary|ios::nocreate|ios::trunc);
if(!infile)
{
cout<<"\n\t\t 打开输入文件出错!\n";
return;
}
infile.close();
cout<<"\n\t\t ******全删成功******\n"<<endl;
system("pause");
screen2();
}
void caidan();
void zuizhong() //liulan():浏览所有员工信息
{
STAFF st;
RANK ra;
CHANGE ch;
float yx[20],sum=0;
int t1,t2,i,l;
int NO[20];
ifstream infile("staff_information.dat",ios::in|ios::binary|ios::nocreate);
if(!infile)
{
cout<<"\n\t\t 打开输入文件出错!\n"<<endl;
caidan();
}
ifstream input("rank_information.dat",ios::in|ios::binary|ios::nocreate);
if(!input)
{
cout<<"\n\t\t 打开输入文件出错!\n"<<endl;
caidan();
}
ifstream inshuchu("CHANGE_information.dat",ios::in|ios::binary|ios::nocreate);
if(!inshuchu)
{
cout<<"\n\t\t 打开输入文件出错!\n";
caidan();
}
infile.seekg(0,ios::end);//文件指针移到文件尾
if(!infile.tellg()) //判断文件内信息是否为空
cout<<"\n\t\t 系统内员工信息为空!"<<endl;
else
{
infile.seekg(0,ios::beg); //文件指针回到文件头
cout<<"\n********************************共有"<<count()<<"条记录*************************************\n";
for(int j=1;j<=count();j++)
{
infile.read((char*)&st,sizeof(st));
cout<<"\n姓名\t\t编号\t\t性别\t\t记录时间\t工资等级"<<endl;
cout<<https://www.doczj.com/doc/d116696268.html,<<"\t\t"<<st.no<<"\t\t"<<st.sex<<"\t\t"<<st.year<<"\t"<<st.level<<endl;
NO[j]=st.no;
input.seekg(0,ios::beg);
for(int g=1;g<=count1();g++)
{
input.read((char*)&ra,sizeof(ra));
if(strcmp(st.level,ra.level)==0)
{
cout<<"基本工资\t岗位工资\t交通补贴";
cout<< "\n"<<ra.bsgz<<"\t\t"<<ra.gwgz<<"\t\t"<<ra.jtbt<<endl;
yx[j]=ra.bsgz+ra.gwgz+ra.jtbt;
inshuchu.seekg(0,ios::beg);
for(int h=1;h<=count2();h++)
{
inshuchu.read((char*)&c
h,sizeof(ch));
if(st.no==ch.no)
{

cout<<"月份\t\t奖励\t\t惩罚";
cout<< "\n"<<ch.month<<"\t\t"<<ch.jlgz<<"\t\t"<<ch.cfgz<<endl;
cout<<"该员工该月工资为"<<endl;
yx[j]=yx[j]+ch.jlgz-ch.cfgz;
cout<<"月薪="<<yx[j]<<endl;
}
}
}
}
}
for(i=1;i<=count();i++)
{
sum+=yx[i];
}
cout<<"\n\n所有员工的平均工资.."<<sum/count()<<"\n"<<endl;

cout<<"工资从小到大排序....\n";
for(i=count(); i>0; --i)
for(l=0; l<i; ++l)
{
if(yx[l]>yx[l+1])
{
t1=yx[l];
t2=NO[l];
yx[l]=yx[l+1];
NO[l]=NO[l+1];
yx[l+1]=t1;
NO[l+1]=t2;
}
}
for(i=1;i<=count();i++)
{
cout<<"\n月薪="<<yx[i]<<endl;
cout<<"该员工编号为"<<NO[i]<<endl;
}
}
system("pause");
caidan(); //函数结束,返回主菜单
}
void gongzi()
{
int i;
system("cls");
cout<<" ╔═════════════════════════════════════╗\n";
cout<<" ║ ║\n";
cout<<" ║ 1 工 资 等 级 ║\n";
cout<<" ║ ║\n";
cout<<" ║ 2 工 资 变 动 0 退 出 ║\n";
cout<<" ║ ║\n";
cout<<" ╚═════════════════════════════════════╝\n";
cout<<"请选择(0-2):";
cin>>i;
switch(i)
{
case 1:screen1();break;
case 2:screen2();break;
case 0:caidan();break;
default:
cout<<"\n\t\t 输入错误"<<endl;
system("pause");
gongzi();
}
}
void caidan()
{
int i;
system("cls");
cout<<" ╔═════════════════════════════════════╗\n";
cout<<" ║ ║\n";
cout<<" ║ 工 资 管 理 系 统 ║\n";
cout<<" ║ ║\n";
cout<<" ╠═════════════════════════════════════╣\n";
cout<<" ║ ║\n";
cout<<" ║

1 员 工 信 息 ║\n";
cout<<" ║ ║\n";
cout<<" ║ 2 工 资 管 理 ║\n";
cout<<" ║ ║\n";
cou
t<<" ║ 3 最 终 统 计 0 退 出 ║\n";
cout<<" ║ ║\n";
cout<<" ╚═════════════════════════════════════╝\n";
cout<<"请选择(0-3):";
cin>>i;
switch(i)
{
case 1:screen();break;
case 2:gongzi();break;
case 3:zuizhong();break;
case 0: break;
default:
cout<<"\n\t\t 输入错误"<<endl;
system("pause");
caidan();
}
}
void screen() //显示主界面
{
system("cls");
cout<<" ╔═════════════════════════════════════╗\n";
cout<<" ║ ║\n";
cout<<" ║ 员工信息管理 ║\n";
cout<<" ║ ║\n";
cout<<" ╠═════════════════════════════════════╣\n";
cout<<" ║ ║\n";
cout<<" ║ 1 新 增 2 浏 览 3 查 询 ║\n";
cout<<" ║ ║\n";
cout<<" ║ 4 修 改 5 删 除 6 全 删 ║\n";
cout<<" ║ ║\n";
cout<<" ║ 0 退 出 ║\n";
cout<<" ╚═════════════════════════════════════╝\n";
cout<<"请选择(0-6):";
int option;cin>>option;
switch(option)
{
case 1:xinzeng();break;
case 2:liulan();break;
case 3:chaxun();break;
case 4:xiugai();break;
case 5:shanchu();break;
case 6:quanshan();break;
case 0:caidan();break;
default:cout<<"\n\t\t 输入错误"<<endl;
system("pause");
scr

een();
}
}

void screen1() //显示主界面
{
system("cls");
cout<<" ╔═════════════════════════════════════╗\n";
cout<<" ║ ║\n";
cout<<" ║ 工资等级信息管理 ║\n";
cout<<" ║ ║\n";
cout<<" ╠═════════════════════════════════════╣\n";
cout<<" ║
║\n";
cout<<" ║ 1 新 增 2 浏 览 3 查 询 ║\n";
cout<<" ║ ║\n";
cout<<" ║ 4 修 改 5 删 除 6 全 删 ║\n";
cout<<" ║ ║\n";
cout<<" ║ 0 退 出 ║\n";
cout<<" ╚═════════════════════════════════════╝\n";
cout<<"请选择(0-6):";
int option;cin>>option;
switch(option)
{
case 1:xinzeng1();break;
case 2:liulan1();break;
case 3:chaxun1();break;
case 4:xiugai1();break;
case 5:shanchu1();break;
case 6:quanshan1();break;
case 0:gongzi();break;
default:
cout<<"\n\t\t 输入错误"<<endl;
system("pause");
screen1();
}
}
void screen2() //显示主界面
{
system("cls");
cout<<" ╔═════════════════════════════════════╗\n";
cout<<" ║ ║\n";
cout<<" ║ 工资变动信息管理 ║\n";
cout<<" ║ ║\n";
cout<<" ╠═════════════════════════════════════╣\n";
cout<<" ║ ║\n";
cout<<" ║ 1 新 增 2 浏 览 3 查 询 ║\n";
cout<<" ║

║\n";
cout<<" ║ 4 修 改 5 删 除 6 全 删 ║\n";
cout<<" ║ ║\n";
cout<<" ║ 0 退 出 ║\n";
cout<<" ╚═════════════════════════════════════╝\n";
cout<<"请选择(0-6):";
int option;cin>>option;
switch(option)
{
case 1:xinzeng2();break;
case 2:liulan2();break;
case 3:chaxun2();break;
case 4:xiugai2();break;
case 5:shanchu2();break;
case 6:quanshan2();break;
case 0:gongzi();break;
default:
cout<<"\n\t\t 输入错误"<<endl;
system("pause");
screen2();
}
}
void main()
{
caidan();
}


相关主题
文本预览
相关文档 最新文档