这是个工资管理系统,这个程序是班上大佬大一上学期的期末大作业,功能十分完善,截两张图感受一下!
我就觉得这个系统做的真的是很完美,没什么好改的,但是在我测试的过程中发现了一个问题!
该系统在使用者申请账号时没有查询功能,在我输入文件中已经存进去的账号时,依旧能输入密码,没有提到该账号已注册,同时,注册账号的流程过于简单,这样的话系统的管理者申请过于简单,导致随便就可以修改系统中的相关信息,这算是这个完美系统中的一点点小缺憾了,如图:
于是我对于该系统进行了一个小小的修改,修改前的代码如下:
//新建账号
void addUser(void)
{
FILE *fp;
int i;
char userinput[30];
printf("\t\t\t请输入账号:\n\n\t\t\t ");
scanf("%s",userinput);
strcpy(user_account[userlength].AcName,userinput);
printf("\t\t\t请输入密码:\n\n\t\t\t ");
scanf("%s", user_account[userlength].password);
userlength++; //用户数据数+1
saveUser();
savenum();
printf("\t\t\t\t账号申请成功!!\n\n\t\t\t");
system("PAUSE");
}
修改后代码如下:
//新建账号
void addUser(void)
{
FILE *fp;
int i;
char userinput[30];
printf("\t\t\t请输入账号:\n\n\t\t\t ");
scanf("%s",userinput);
for(i=0;i<userlength;i++){
if(strcmp(user_account[i].AcName,userinput)==0){
printf("\t\t\t该账号已被注册,请重新申请\n\n\t\t\t ");
system("PAUSE");
return ;
}
}
strcpy(user_account[userlength].AcName,userinput);
printf("\t\t\t请输入密码:\n\n\t\t\t ");
scanf("%s", user_account[userlength].password);
printf("\t\t\t请再输入一次密码:\n\n\t\t\t ");
scanf("%s",userinput);
if(strcmp(user_account[userlength].password,userinput)!=0){
printf("\t\t\t两次密码不一致,请再次输入确认密码\n\n\t\t\t");
scanf("%s",userinput);
if(strcmp(user_account[userlength].password,userinput)!= 0){
printf("\t\t\t两次密码仍然不一致,请重新申请\n\n\t\t\t");
getchar();
system("PAUSE");
system("cls");
addUser(); //用户重新申请
}
}
userlength++; //用户数据数+1
saveUser();
savenum();
printf("\t\t\t\t账号申请成功!!\n\n\t\t\t");
system("PAUSE");
}
修改后的程序运行结果:
修改后的程序可以识别之前存入文件中的账号密码,并对此做出反应,同时在输入密码时添加再次输入密码的操作,目的是使用户确认密码,因为我们在日常生活中经常会遇到输入了一遍密码,但是由于输入太快导致有些字符输入与心中所想有些出入,登录的时候发现一直输入“正确”密码,但是一直报错,添加再次输入密码功能就能极大避免这种情况的发生。
以下是代码源码(修改后):
还有几个文件,但是由于文件中包含班级同学信息,就不贴啦!
点击查看代码
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<time.h> //验证码要用
#include <windows.h> //为了调用system函数
#include<algorithm> //主要为了调用sort函数
using namespace std;
//自建员工信息结构体数据库
struct staff
{
int id;
char name[20];
char sex[20];
char belong[20];
int basic_pay;
int reward_pay;
int add_pay; //补贴金额
char add_project[20]; //补贴项目
int deductions_pay;//扣款金额
char deductions_project[20];//扣款项目
int all_pay;
struct staff *next;
};
struct staff *head;//头
struct staff *tail;//尾
//校徽
struct paint
{
char str_p[200];
struct paint *next;
};
//账号密码
struct asccount{
char AcName[30];
char password[12];
}user_account[100];
//函数声明
void printsystem();
int create(); //加入
void remove_LB(); //删除
int edit_LB(); //单一修改
int edit_LB2(); //批量修改
int search_LB(); //精确查找
//排序组件
void SortByFirst_Letter();//按名字首字母排序
void SortByTotal_Wages_descending();//按基本工资降序排序
void SortByTotal_Wages_ascending();//按基本工资升序排序
void SortByID();//按工号排序
int cmp1(staff a,staff b);//排序判断1
int cmp2(staff a,staff b);//排序判断2
int cmp3(staff a,staff b);//排序判断3
int cmp4(staff a,staff b);//排序判断4
int PrintSort(); //排序引导
int Sort(); //排序
int showall_LB(); //查询全部
void hide(void);//隐藏光标
void savedata_LB(); //存储信息,磁盘
void savenum(); //存储个数,磁盘
void loadnum();//信息加载到内存
void loaddata_LB(); //个数加载到内存
void statistics(); //统计,我还没写
void thesamesum_LB();
void partsum_LB();
int judge(); //判断缓存文件是否为空
//密码系统
void Check_User_legitimacy(void);//检验账号的合法性*
void addUser(void);//新建账号*
void FindPassword(void);//找回密码*
void EditPassword(void);//修改密码*
void loadUser(void);//将账号读入内存*
void saveUser(void);//将账号存入磁盘*
void printuser(void);//输出账号菜单*
int login(void);//账号登录*
//排序小插件
void Sort_Save(struct staff *data); //将排序好的数组传递给链表
//全局变量
int length=0;//全局变量:数据数量
int userlength=0;//全局变量:账号数量
int access=0;//全局变量:账号是否能登陆的flag
//小彩蛋
void process(); //彩蛋
void worker(); //打印工作人员
void painter();//海大校徽
//新建账号
void addUser(void)
{
FILE *fp;
int i;
char userinput[30];
printf("\t\t\t请输入账号:\n\n\t\t\t ");
scanf("%s",userinput);
for(i=0;i<userlength;i++){
if(strcmp(user_account[i].AcName,userinput)==0){
printf("\t\t\t该账号已被注册,请重新申请\n\n\t\t\t ");
system("PAUSE");
return ;
}
}
strcpy(user_account[userlength].AcName,userinput);
printf("\t\t\t请输入密码:\n\n\t\t\t ");
scanf("%s", user_account[userlength].password);
printf("\t\t\t请再输入一次密码:\n\n\t\t\t ");
scanf("%s",userinput);
if(strcmp(user_account[userlength].password,userinput)!=0){
printf("\t\t\t两次密码不一致,请再次输入确认密码\n\n\t\t\t");
scanf("%s",userinput);
if(strcmp(user_account[userlength].password,userinput)!= 0){
printf("\t\t\t两次密码仍然不一致,请重新申请\n\n\t\t\t");
getchar();
system("PAUSE");
system("cls");
addUser(); //用户重新申请
}
}
userlength++; //用户数据数+1
saveUser();
savenum();
printf("\t\t\t\t账号申请成功!!\n\n\t\t\t");
system("PAUSE");
}
//检验账号的合法性
void Check_User_legitimacy(void)
{
int i,flag=0,stochastic,user_stochastic;
char AcName[30],password[30],temp[30];
printf("\t\t\t\t请输入登录账号:\n\n\t\t\t\t ");
scanf("%s",AcName);
for(i=0;i<userlength;i++){
if(strcmp(user_account[i].AcName,AcName)==0){
strcpy(temp,AcName);
flag=1; //第一重flag:检验账号是否已经注册
break;
}
}
if(flag==0){
printf("\n\t\t\t\t此账号还未注册\n\n\t\t\t ");
system("PAUSE");
system("cls");
return;
}
printf("\n\t\t\t\t请输入密码:\n\n\t\t\t\t ");
scanf("%s",password);
if(strcmp(user_account[i].password,password)==0)
{
flag=2; //第二重flag,检验输入的密码是否正确
}
if(flag==1){
printf("\t\t\t\t密码错误\n\n\t\t\t ");
system("PAUSE");
system("cls");
return ;
}
else if(flag==2){ //验证码检测
printf("\n\t\t\t\t请输入验证码:\n");
srand((unsigned)time(NULL));
stochastic=rand(); //生成验证码
printf("\n\t\t\t\t%d\n\t\t\t\t",stochastic);
scanf("%d",&user_stochastic);
}
if(user_stochastic!=stochastic){ //比对验证码
printf("\n\t\t\t验证码错误\n");
system("PAUSE");
system("cls");
return ;
}
access=1; //登录通过
}
//找回密码
void FindPassword(void)
{
int i;
char AcName[30];
printf("\t\t\t请输入要找回的账号:\n\t\t\t\t");
scanf("%s",AcName);
for(i=0;i<userlength;i++)
if(strcmp(user_account[i].AcName,AcName)==0){
printf("\t\t\t你的账号密码:\n\t\t\t\t%s\n",user_account[i].password);
system("PAUSE");
return ;
}
printf("\t\t\t\t查无此账号!!!\n\n\t\t\t"); //如果遍历后没找到账号
system("PAUSE");
}
//修改密码
void EditPassword(void)
{
int i;
int stochastic=0,user_stochastic=0;
char AcName[30];
char password[30];
printf("\t\t\t 请输入要修改密码的账号:\n\t\t\t ");
scanf("%s",AcName);
for(i=0;i<userlength;i++)
if(strcmp(user_account[i].AcName,AcName)==0){
printf("\n\t\t\t 请输入原密码:\n\t\t\t ");
scanf("%s",password);
if(strcmp(user_account[i].password,password)!=0){
printf("\n\t\t\t\t密码错误\n\n\t\t\t ");
system("PAUSE");
system("cls");
return ;
}
printf("\n\t\t\t 请输入新密码:\n\t\t\t ");
scanf("%s",password);
if(strcmp(user_account[i].password,password) == 0){
printf("\n\t\t\t新密码与原密码重复,请选择一个新的密码n\n\t\t\t "); //检验修改是否合法
system("PAUSE");
system("cls");
return ;
}
strcpy(user_account[i].password,password); //记下新密码
printf("\n\t\t\t 请输入验证码:\n");
srand((unsigned)time(NULL)); //验证码生成
stochastic=rand();
printf("\n\t\t\t\t%d\n\t\t\t\t",stochastic);
scanf("%d",&user_stochastic);
if(user_stochastic!=stochastic){
printf("\n\t\t\t验证码错误\n");
system("PAUSE");
system("cls");
return ;
}
printf("\n\t\t\t\t修改密码成功\n");
saveUser();
system("PAUSE");
system("cls");
return ;
}
printf("\n\t\t\t\t查无此账号\n\n\t\t\t");
system("PAUSE");
}
//将账号读入内存
void loadUser(void)
{
int i;
freopen("账号.txt", "r", stdin);
for(i=0;i<userlength;i++){
scanf("%s",user_account[i].AcName);
scanf("%s",user_account[i].password);
}
freopen("CON", "r", stdin);
}
//将账号存入磁盘
void saveUser(void)
{
int i;
FILE *fp;
fp=fopen("账号.txt", "w");
for(i=0;i<userlength;i++){
fprintf(fp,"%s\n",user_account[i].AcName);
fprintf(fp,"%s\n",user_account[i].password);
}
fclose(fp);
}
//输出账号菜单
void printuser(void)
{
printf("\t\t\t_________________________\n");
printf("\t\t\t| 登录 请按 1 |\n");
printf("\t\t\t| 注册新账号 请按 2 |\n");
printf("\t\t\t| 找回密码 请按 3 |\n");
printf("\t\t\t| 修改密码 请按 4 |\n");
printf("\t\t\t| 退出程序 请按 5 |\n");
printf("\t\t\t________________________ \n");
}
//账号登录
int login(void)
{
int userinput;
while(1){
printuser();
loadUser();
loadnum();
scanf("%d",&userinput);
switch(userinput){
case 1:
Check_User_legitimacy(); break;
case 2:
addUser(); savenum(); system("cls"); break;
case 3:
FindPassword(); system("cls"); break;
case 4:
EditPassword(); break;
case 5:
system("cls");
printf("\n");
return 0;
default:
system("cls");
system("cls");
break;
}
if(access==1)
return 1;
}
}
void painter() //打印海大的校徽
{
struct paint *head_p=NULL;
head_p=(struct paint*)malloc(sizeof(struct paint));
int i;
struct paint *p1,*p2;
freopen("海大校徽.txt", "r", stdin);
p1=p2=head_p;
for(i=0;i<46;i++)
{
scanf("%s",p1->str_p);
if(i!=46)
{
p1=(struct paint*)malloc(sizeof(struct paint));
p2->next=p1;
p2=p1;
}
}
p2->next=NULL;
freopen("CON", "r", stdin);
for(p1=p2=head_p;p1!=NULL;p1=p1->next)
{
printf("%s\n",p1->str_p);
}
printf("请输入回车继续:");
getchar();
system("cls");
}
void add_LB() //添加链表
{
struct staff *p1,*p2;
FILE *fp;
fp = fopen("缓存区.txt","a");
if(head!=NULL)
{
if(judge()==0)
{
printf("新增员工工号:");
scanf("%d",&head->id);
fprintf(fp, "%d\n",head->id);
printf("新增员工姓名:");
scanf("%s",head->name);
fprintf(fp, "%s\n",head->name);
printf("新增员工性别:");
scanf("%s",head->sex);
fprintf(fp, "%s\n",head->sex);
printf("新增员工所属部门:");
scanf("%s",head->belong);
fprintf(fp, "%s\n",head->belong);
printf("新增员工基本工资:");
scanf("%d",&head->basic_pay);
fprintf(fp, "%d\n",head->basic_pay);
printf("新增员工奖励工资:");
scanf("%d",&head->reward_pay);
fprintf(fp, "%d\n",head->reward_pay);
printf("新增员工补贴项目:");
scanf("%s",head->add_project);
fprintf(fp, "%s\n",head->add_project);
printf("新增员工补贴金额:");
scanf("%d",&head->add_pay);
fprintf(fp, "%d\n",head->add_pay);
printf("新增员工扣款项目:");
scanf("%s",head->deductions_project);
fprintf(fp, "%s\n",head->deductions_project);
printf("新增员工扣款金额:");
scanf("%d",&head->deductions_pay);
fprintf(fp, "%d\n",head->deductions_pay);
head->all_pay=head->add_pay+head->basic_pay+head->reward_pay-head->deductions_pay;
fprintf(fp, "%d\n",head->all_pay);
length++;
}
else if(judge()==1)
{
p1=(struct staff*)malloc(sizeof(struct staff));
p2=tail;
printf("新增员工工号:");
scanf("%d",&p1->id);
fprintf(fp, "%d\n",p1->id);
printf("新增员工姓名:");
scanf("%s",p1->name);
fprintf(fp, "%s\n",p1->name);
printf("新增员工性别:");
scanf("%s",p1->sex);
fprintf(fp, "%s\n",p1->sex);
printf("新增员工所属部门:");
scanf("%s",p1->belong);
fprintf(fp, "%s\n",p1->belong);
printf("新增员工基本工资:");
scanf("%d",&p1->basic_pay);
fprintf(fp, "%d\n",p1->basic_pay);
printf("新增员工奖励工资:");
scanf("%d",&p1->reward_pay);
fprintf(fp, "%d\n",p1->reward_pay);
printf("新增员工补贴项目:");
scanf("%s",p1->add_project);
fprintf(fp, "%s\n",p1->add_project);
printf("新增员工补贴金额:");
scanf("%d",&p1->add_pay);
fprintf(fp, "%d\n",p1->add_pay);
printf("新增员工扣款项目:");
scanf("%s",p1->deductions_project);
fprintf(fp, "%s\n",p1->deductions_project);
printf("新增员工扣款金额:");
scanf("%d",&p1->deductions_pay);
fprintf(fp, "%d\n",p1->deductions_pay);
p1->all_pay=p1->add_pay+p1->basic_pay+p1->reward_pay-p1->deductions_pay;
fprintf(fp, "%d\n",p1->all_pay);
p2->next=p1;
p2=p1;
p2->next=NULL;
tail=p2;
length++;
}
}
else
{
tail=head=(struct staff*)malloc(sizeof(struct staff));
tail->next=NULL;
p1=head;
p2=tail;
printf("新增员工工号:");
scanf("%d",&p1->id);
fprintf(fp, "%d\n",p1->id);
printf("新增员工姓名:");
scanf("%s",p1->name);
fprintf(fp, "%s\n",p1->name);
printf("新增员工性别:");
scanf("%s",p1->sex);
fprintf(fp, "%s\n",p1->sex);
printf("新增员工所属部门:");
scanf("%s",p1->belong);
fprintf(fp, "%s\n",p1->belong);
printf("新增员工基本工资:");
scanf("%d",&p1->basic_pay);
fprintf(fp, "%d\n",p1->basic_pay);
printf("新增员工奖励工资:");
scanf("%d",&p1->reward_pay);
fprintf(fp, "%d\n",p1->reward_pay);
printf("新增员工补贴项目:");
scanf("%s",p1->add_project);
fprintf(fp, "%s\n",p1->add_project);
printf("新增员工补贴金额:");
scanf("%d",&p1->add_pay);
fprintf(fp, "%d\n",p1->add_pay);
printf("新增员工扣款项目:");
scanf("%s",p1->deductions_project);
fprintf(fp, "%s\n",p1->deductions_project);
printf("新增员工扣款金额:");
scanf("%d",&p1->deductions_pay);
fprintf(fp, "%d\n",p1->deductions_pay);
p1->all_pay=p1->add_pay+p1->basic_pay+p1->reward_pay-p1->deductions_pay;
fprintf(fp, "%d\n",p1->all_pay);
p2->next=p1;
p2=p1;
p2->next=NULL;
tail=p2;
length++;
}
fclose(fp);
savedata_LB();
savenum();
system("PAUSE");
system("cls");
}
void savedata_LB()
{
int i;
struct staff *p1,*p2;
FILE *fp;
fp = fopen("缓存区.txt", "w");
p1=p2=head;
for(;p1!=NULL;)
{
fprintf(fp, "%d\n",p1->id);
fprintf(fp, "%s\n",p1->name);
fprintf(fp, "%s\n",p1->sex);
fprintf(fp, "%s\n",p1->belong);
fprintf(fp, "%d\n",p1->basic_pay);
fprintf(fp, "%d\n",p1->reward_pay);
fprintf(fp, "%s\n",p1->add_project);
fprintf(fp, "%d\n",p1->add_pay);
fprintf(fp, "%s\n",p1->deductions_project);
fprintf(fp, "%d\n",p1->deductions_pay);
fprintf(fp, "%d\n",p1->add_pay+p1->basic_pay+p1->reward_pay-p1->deductions_pay);
p1=p1->next;
p2->next=p1;
p2=p1;
}
p1=p2=NULL;
fclose(fp);
}
void savenum(void)
{
FILE *fp;
fp = fopen("数据个数.txt", "w");
fprintf(fp, "%d\n", length);
fprintf(fp, "%d\n", userlength);
fclose(fp);
}
void loadnum(void)
{
FILE *fp;
fp = fopen("数据个数.txt", "r");
fscanf(fp, "%d", &length);
fscanf(fp, "%d", &userlength);
fclose(fp);
}
int judge()
{
FILE *fp;
char ch;
fp=fopen("缓存区.txt","r");
ch=fgetc(fp);
if(ch==EOF)
return 0;
else
return 1;
}
void loaddata_LB()
{
if(judge()==0)
{
printf("Tips:未检索到预设的文本文件!\n");
printf("请及时添加工资信息:)\n") ;
length=0;
savenum();
}
else
{
int i;
struct staff *p1,*p2;
freopen("缓存区.txt", "r", stdin);
p1=p2=head;
for(i=0;i<length;i++)
{
scanf("%d",&p1->id);
scanf("%s",p1->name);
scanf("%s",p1->sex);
scanf("%s",p1->belong);
scanf("%d",&p1->basic_pay);
scanf("%d",&p1->reward_pay);
scanf("%s",p1->add_project);
scanf("%d",&p1->add_pay);
scanf("%s",p1->deductions_project);
scanf("%d",&p1->deductions_pay);
scanf("%d",&p1->all_pay);
if(i!=length-1)
{
p1=(struct staff*)malloc(sizeof(struct staff));
p2->next=p1;
p2=p1;
}
}
tail=p2;
p2->next=NULL;
freopen("CON", "r", stdin);
}
}
void remove_LB()
{
int num;
struct staff *p1,*p2;
printf("\n请输入删除员工工号:");
scanf("%d", &num);
for(p2=p1=head;p1!=NULL;) //p1和p2从头开始走
{
if(p1->id!=num) //如果不是,往下一个节点走
{
p2=p1;
p1=p1->next;
p2->next=p1;
}
else if(p1->id==num) //如果找到了
{
if(p1==head) //处理“删除第一个”的情况
{
head=p2->next;
p1=p2=head;
length--;
printf("\n删除成功!\n");
printf("摁下回车|查询删除后的结果\n");
system("PAUSE");
showall_LB();
break;
}
if(p1==tail)
{
tail=p2;
p2->next=NULL;
length--;
printf("\n删除成功!\n");
printf("摁下回车|查询删除后的结果\n");
system("PAUSE");
showall_LB();
break;
}
p1=p1->next; //p1直接往下走
p2->next=p1; //p2直接跳过中间这个,链接p1,实现删除
length--;
printf("\n删除成功!\n");
printf("摁下回车|查询删除后的结果\n");
system("PAUSE");
showall_LB();
break;
}
}
if(p1==NULL)
{
printf("\n查无此人!\n");
getchar();
getchar();
}
savedata_LB();
savenum();
printf("\n\n请摁下回车键继续");
system("cls");
}
void put_edit()
{
system("cls");
printf("**********************************\n");
printf("**** 1.姓名 2.性别 *****\n");
printf("**** 3.所属部门 4.基本工资 *****\n");
printf("**** 5.奖励工资 6.补贴项目 *****\n");
printf("**** 7.补贴金额 8.扣款工资 *****\n");
printf("**** 9.扣款金额 10.退出 *****\n");
printf("**********************************\n");
printf("***** 请输入需要修改的内容: *****\n");
}
int edit_LB2()
{
struct staff *p1;
int num;
printf("\n请输入需要修改的员工工号:");
scanf("%d", &num);
printf("\n");
for(p1=head;p1!=NULL;) //p1和p2从头开始走
{
if(p1->id!=num) //如果不是,往下一个节点走
{
p1=p1->next;
}
else if(p1->id==num)
{
printf("修改姓名:");
scanf("%s", p1->name);
printf("\n");
printf("修改性别:");
scanf("%s", p1->sex);
printf("\n");
printf("修改所属部门:");
scanf("%s", p1->belong);
printf("\n");
printf("修改基本工资:");
scanf("%d", &p1->basic_pay);
printf("\n");
printf("修改奖励工资:");
scanf("%d", &p1->reward_pay);
printf("\n");
printf("修改补贴项目:");
scanf("%s", p1->add_project);
printf("\n");
printf("修改补贴金额:");
scanf("%d", &p1->add_pay);
printf("\n");
printf("修改扣款项目:");
scanf("%s", p1->deductions_project);
printf("\n");
printf("修改扣款金额:");
scanf("%d", &p1->deductions_pay);
printf("\n");
p1->all_pay=p1->add_pay+p1->basic_pay+p1->reward_pay-p1->deductions_pay;
printf("修改成功!\n");
printf("摁下回车|查询修改后的结果\n");
system("PAUSE");
showall_LB();
break;
}
}
if(p1==NULL)
printf("\n查无此人!\n");
savedata_LB();
savenum();
printf("请摁下回车键继续");
getchar();
system("cls");
return 0;
}
int edit_LB()
{
int option;
printf("\n请输入你想要修改的方式:\n");
printf("1.批量修改\t2.选择单项修改\t3.取消修改|返回\n");
scanf("%d",&option);
if(option==1)
{
edit_LB2();
}
else if(option==2)
{
struct staff *p1;
int num;
int choose;
printf("\n请输入需要修改的员工工号:");
scanf("%d", &num);
printf("\n");
for(p1=head;p1!=NULL;) //p1和p2从头开始走
{
if(p1->id!=num) //如果不是,往下一个节点走
{
p1=p1->next;
}
else if(p1->id==num)
{
put_edit();
scanf("%d",&choose);
if(choose==10)
{
system("cls");
return 0;
}
if(choose<1||choose>9)
{
for(choose=0;choose<1||choose>9;)
{
printf("请输入正确的标号!\n");
scanf("%d",&choose);
}
}
switch(choose)
{
case 1:
printf("修改姓名:");
scanf("%s", p1->name);
printf("\n");
break;
case 2:
printf("修改性别:");
scanf("%s", p1->sex);
printf("\n");
break;
case 3:
printf("修改所属部门:");
scanf("%s", p1->belong);
printf("\n");
break;
case 4:
printf("修改基本工资:");
scanf("%d", &p1->basic_pay);
printf("\n");
break;
case 5:
printf("修改奖励工资:");
scanf("%d", &p1->reward_pay);
printf("\n");
break;
case 6:
printf("修改补贴项目:");
scanf("%s", p1->add_project);
printf("\n");
break;
case 7:
printf("修改补贴工资:");
scanf("%d", &p1->add_pay);
printf("\n");
break;
case 8:
printf("修改扣款项目:");
scanf("%s", p1->deductions_project);
printf("\n");
break;
case 9:
printf("修改扣款工资:");
scanf("%d", &p1->deductions_pay);
printf("\n");
break;
}
p1->all_pay=p1->add_pay+p1->basic_pay+p1->reward_pay-p1->deductions_pay;
printf("修改成功!\n");
printf("摁下回车|查询修改后的结果\n");
system("PAUSE");
showall_LB();
break;
}
}
if(p1==NULL)
{
printf("\n查无此人!\n");
getchar();
}
savedata_LB();
savenum();
printf("请摁下回车键继续");
getchar();
system("cls");
}
if(option!=1&&option!=2)
system("cls");
return 0;
}
//彩蛋
void process()
{
int order;
printf("---------------------------------------------\n");
printf("1.打印海大校徽 2.打印制作人员\n");
printf("---------------------------------------------\n");
printf("请选择彩蛋:");
scanf("%d",&order);
printf("\n");
switch(order){
case 1: painter(); break;
case 2: worker(); break;
}
}
void worker()
{
printf("2152130 计算一班 洪彬铭\n");
printf("2152114 计算一班 容数\n");
printf("2152105 计算一班 马英臻\n");
system("PAUSE");
system("cls");
return ;
}
int search_LB()
{
int i = length;
int num;
struct staff *p1,*p2;
const char* str[11] = {"工号", "姓名", "性别", "部门", "基本工资", "奖励工资", "补贴项目","补贴金额","扣款项目","扣款金额","总工资"};
printf("\n请输入需要查询员工工号:");
scanf("%d", &num);
printf("\n\n");
int n;
for(n=0;n<11;n++){
printf("%-12s" , str[n]);
}
printf("\n\n");
for(p1=head;p1!=NULL;) //p1和p2从头开始走
{
if(p1->id!=num) //如果不是,往下一个节点走
{
p1=p1->next;
}
else if(p1->id==num) //如果找到了
{
printf(" %-10d", p1->id);
printf(" %-10s", p1->name);
printf(" %-10s", p1->sex);
printf("%-10s", p1->belong);
printf(" %-10d", p1->basic_pay);
printf(" %-10d", p1->reward_pay);
printf(" %-10s", p1->add_project);
printf(" %-10d", p1->add_pay);
printf(" %-10s", p1->deductions_project);
printf(" %-10d", p1->deductions_pay);
printf(" %-10d", p1->all_pay);
printf("\n\n");
printf("\n查询成功!\n\n");
break;
}
}
if(p1==NULL)
printf("\n查无此人!\n");
getchar();
getchar();
system("cls");
}
//按姓名首字母排序判断
int cmp1(staff a, staff b)//结构体变量作函数参数
{
if(strcmp(a.name, b.name)<0)
return 1;
else
return 0;
}
//按总工资升序排序判断
int cmp2(staff a,staff b)//结构体变量作函数参数
{
return a.all_pay<b.all_pay;
}
//按总工资降序排序判断
int cmp3(staff a,staff b)//结构体变量作函数参数
{
return a.all_pay>b.all_pay;
}
//按工号排序
int cmp4(staff a,staff b)
{
return a.id<b.id;
}
void Sort_Save(struct staff *data) //将排序好的中间数据的内容导入链表中~
{
int i;
struct staff *p1;
for(p1=head,i=0;i<length;i++)
{
p1->id=data[i].id;
strcpy(p1->name,data[i].name);
strcpy(p1->sex,data[i].sex);
strcpy(p1->belong,data[i].belong);
p1->basic_pay=data[i].basic_pay;
p1->reward_pay=data[i].reward_pay;
strcpy(p1->add_project,data[i].add_project);
p1->add_pay=data[i].add_pay;
strcpy(p1->deductions_project,data[i].deductions_project);
p1->deductions_pay=data[i].deductions_pay;
p1->all_pay=data[i].all_pay;
p1=p1->next;
}
}
//首名字首字母排序
void SortByFirst_Letter()
{
int i;
struct staff data[length+1]={};
struct staff *p1;
for(p1=head,i=0;i<length;i++)
{
data[i]=*p1;
p1=p1->next;
}
sort(data, data+length,cmp1);//c++预置的sort函数,格式为(要排序数组的首地址,末地址,排序方式)
Sort_Save(data);
savedata_LB();//还没写存储
printf("\n\t\t\t\t排序完成!!\n\n\t\t\t ");
showall_LB();
system("PAUSE");
}
//按工号排序
void SortByID()
{
int i;
struct staff data[length+1]={};
struct staff *p1;
for(p1=head,i=0;i<length;i++)
{
data[i]=*p1;
p1=p1->next;
}
sort(data, data+length,cmp4);//c++预置的sort函数,格式为(要排序数组的首地址,末地址,排序方式)
Sort_Save(data);
savedata_LB();//还没写存储 //写完啦
printf("\n\t\t\t\t排序完成!!\n\n\t\t\t ");
showall_LB();
system("PAUSE");
}
//按基本工资升序排序
void SortByTotal_Wages_ascending()
{
int i;
struct staff data[length+1]={};
struct staff *p1;
for(p1=head,i=0;i<length;i++)
{
data[i]=*p1;
p1=p1->next;
}
sort(data, data+length, cmp2);//c++预置的sort函数,格式为(要排序数组的首地址,末地址,排序方式)
Sort_Save(data);
savedata_LB();//还没写存储 //写完啦
printf("\n\t\t\t\t排序完成!!\n\n\t\t\t ");
showall_LB();
system("PAUSE");
}
//按基本工资降序排序
void SortByTotal_Wages_descending()
{
int i;
struct staff data[length+1]={};
struct staff *p1;
for(p1=head,i=0;i<length;i++)
{
data[i]=*p1;
p1=p1->next;
}
sort(data, data+length, cmp3);//c++预置的sort函数,格式为(要排序数组的首地址,末地址,排序方式)
Sort_Save(data);
savedata_LB();//还没写存储 //写完啦
printf("\n\t\t\t\t排序完成!!\n\n\t\t\t ");
showall_LB();
system("PAUSE");
}
int PrintSort()
{
printf("\t ************************************************************\n");
printf("\t * *\n");
printf("\t * 您可以进行以下操作: *\n");
printf("\t * *\n");
printf("\t * 按员工姓名首字母排序 请按 1 *\n");
printf("\t * *\n");
printf("\t * 按工号排序 请按 2 *\n");
printf("\t * *\n");
printf("\t * 按总工资升序排序 请按 3 *\n");
printf("\t * *\n");
printf("\t * 按总工资降序排序 请按 4 *\n");
printf("\t * *\n");
printf("\t * 返回上一级菜单 请按 5 *\n");
printf("\t * *\n");
printf("\t ************************************************************\n\n");
}
//排序
int Sort()
{
system("cls");
int input,number;
while(1){
system("cls");
PrintSort();
input=scanf("%d",&number);
if(!input){
//inwrong(); //我想后期写一个排错函数
continue;
}
switch(number){
case 1:
SortByFirst_Letter(); break;
case 2:
SortByID(); break;
case 3:
SortByTotal_Wages_ascending(); break;
case 4:
SortByTotal_Wages_descending(); break;
case 5:
system("cls"); return 0;
default:
system("cls"); break;
}
}
getchar();
getchar();
system("cls");
return 0;
}
//查询全部数据
int showall_LB()
{
if(judge()==0)
{
printf("\n\tW A R N I N G\n数据库内容为空,请先添加信息\n\n");
printf("请输入回车继续\n");
getchar();
getchar();
system("cls");
return 0;
}
struct staff *p1;
int i;
const char* str[11] = {"工号", "姓名", "性别", "部门", "基本工资", "奖励工资", "补贴项目","补贴金额","扣款项目","扣款金额","总工资"};
i=length-1;
printf("\n");
printf("查询成功!\n\n");
int n;
for(n=0; n<11; n++){
printf("%-12s" , str[n]); //打印
}
printf("\n\n");
for(p1=head;p1!=NULL;p1=p1->next)
{
printf(" %-10d", p1->id);
printf(" %-10s", p1->name);
printf(" %-10s", p1->sex);
printf("%-10s", p1->belong);
printf(" %-10d", p1->basic_pay);
printf(" %-10d", p1->reward_pay);
printf(" %-10s", p1->add_project);
printf(" %-10d", p1->add_pay);
printf(" %-10s", p1->deductions_project);
printf(" %-10d", p1->deductions_pay);
printf(" %-10d", p1->all_pay);
printf("\n\n");
}
savenum();
system("PAUSE");
system("cls");
return 0;
}
//隐藏光标
void hide()
{
CONSOLE_CURSOR_INFO cursor_info = {1, 0};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
void statistics()
{
enum option {leave,thesame,part}; //在菜单上用枚举可读性更好一点,建议主菜单使用 //好,之后再改——rs
int input;
do
{
system("cls");
printf("********************************\n");
printf("***** 0.退出统计功能 *********\n");
printf("***** 1.相同工资范围人数 *****\n");
printf("***** 2.各部门工资总数 *****\n");
printf("********************************\n");
printf("*****请输入需实现功能代号: *****\n");
scanf("%d",&input);
switch(input)
{
case thesame: thesamesum_LB();
break;
case part: partsum_LB();
break;
case leave:printf("退出统计功能(摁下回车键返回)");
break;
dafault:printf("选择错误,请输入正确代号!\n");
break;
}
}while(input);
getchar();
getchar();
system("cls");
}
void thesamesum_LB()
{
struct staff *p1,*p2;
int min,max,i,sum=0;
printf("请输入需要查找的工资范围(输入格式为:“最小值-最大值”): \n");
scanf("%d-%d",&min,&max);
for(p2=p1=head;p1!=NULL;) //最好先用#define定义数量,在数量发生变化时便于修改 //这里用不了,length一直在变动的——rs
{
if(p1->all_pay>=min&&p1->all_pay<=max)
sum++;
p1=p1->next;
p2->next=p1;
p2=p1;
}
printf("工资在%d-%d范围里的人数有%d个。\n",min,max,sum);
printf("请摁下回车键继续");
getchar();
getchar();
system("cls");
}
void partsum_LB()
{
struct staff *p1,*p2;
int i,sum=0;
char a[81];
printf("请输入要查找的工作部门:\n");
scanf("%s",a);
for(p2=p1=head;p1!=NULL;)
{
if(strcmp(a,p1->belong)==0)
sum=sum+p1->all_pay;
p1=p1->next;
p2->next=p1;
p2=p1;
}
printf("\n该部门工资总和为%d\n\n",sum);
printf("请摁下回车键继续");
getchar();
getchar();
system("cls");
}
//主菜单
void printsystem()
{
printf("\t\t\t____________________________\n");
printf("\t\t\t|********主菜单************|\n");
printf("\t\t\t| 1.输入员工信息 |\n");
printf("\t\t\t| 2.删除员工信息 |\n");
printf("\t\t\t| 3.修改员工信息 |\n");
printf("\t\t\t| 4.排序员工信息 |\n");
printf("\t\t\t| 5.查询员工信息 |\n");
printf("\t\t\t| 6.统计员工信息 |\n");
printf("\t\t\t| 7.显示所有员工信息 |\n");
printf("\t\t\t| 8.彩蛋 |\n");
printf("\t\t\t| 9.退出系统 |\n");
printf("\t\t\t****************************\n");
printf("\t\t\t____________________________\n");
printf("\t\t\t ---请输入菜单项:---\n\t\t\t\t");
}
//主菜单系统
int main(void)
{
tail=head=(struct staff*)malloc(sizeof(struct staff));
tail->next=NULL;
int input;
loadnum();
loaddata_LB();
login();
printf("\t\t\t\t登录成功!欢迎使用员工工资管理系统!\n");
system("PAUSE");
system("cls");
while(1){
printsystem();//打印主菜单
scanf("%d",&input);
if(input==9){
system("cls"); //清屏退出
return 0;
}
switch(input){
case 1: /*create();*/add_LB();break;
case 2: remove_LB();break;
case 3: edit_LB();break;
case 4: Sort();break;
case 5: search_LB(); break;
case 6: statistics();break;
case 7: showall_LB();break;
case 8: process();break;
default: printf("\n选择错误!请输入菜单中含有的数字项!\n摁下回车键继续>"); getchar(); getchar(); system("cls");
}
}
return 0;
}