|
|
|
@ -0,0 +1,206 @@
|
|
|
|
|
#include<stdio.h>
|
|
|
|
|
#include<stdlib.h>
|
|
|
|
|
#include<string.h>
|
|
|
|
|
#define LEN 20 /* 职工号和姓名等最大字符数,实际请更改 */
|
|
|
|
|
#define N 200 /* 最大职工人数*/
|
|
|
|
|
struct info /* 定义职工信息结构体 */
|
|
|
|
|
{
|
|
|
|
|
char jobnum[LEN+1]; /* 职工号 */
|
|
|
|
|
char name[LEN+1]; /* 姓名 */
|
|
|
|
|
char sex[3]; /* 性别 */
|
|
|
|
|
int age; /* 年龄 */
|
|
|
|
|
char edu[LEN+1]; /* 学历 */
|
|
|
|
|
int sal; /* 工资 */
|
|
|
|
|
char add[30]; /* 家庭地址 */
|
|
|
|
|
char tel[LEN+1]; /* 电话号码 */
|
|
|
|
|
}sta[N];
|
|
|
|
|
int k=1,n; /* 定义全局变量 */
|
|
|
|
|
void readfile(); /* 函数声明 */
|
|
|
|
|
void seek();
|
|
|
|
|
void modify();
|
|
|
|
|
void del();
|
|
|
|
|
void display();
|
|
|
|
|
void save();
|
|
|
|
|
void menu();
|
|
|
|
|
int main()
|
|
|
|
|
{ while(k)
|
|
|
|
|
menu();
|
|
|
|
|
system("pause");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
void readfile() /* 录入信息 */
|
|
|
|
|
{
|
|
|
|
|
FILE *fp;
|
|
|
|
|
int i=0;
|
|
|
|
|
if ((fp=fopen("staff.txt","r"))==NULL)
|
|
|
|
|
{ printf("Open file error! Press any key to exit!");
|
|
|
|
|
system("pause");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
while(fscanf(fp,"%s %s %s %d %s %d %s %s",sta[i].jobnum,sta[i].name,sta[i].sex,&sta[i].age,sta[i].edu,&sta[i].sal,sta[i].add,sta[i].tel)==8)
|
|
|
|
|
{ i++;
|
|
|
|
|
i=i;
|
|
|
|
|
}
|
|
|
|
|
fclose(fp);
|
|
|
|
|
n=i;
|
|
|
|
|
printf("录入完毕!\n");
|
|
|
|
|
}
|
|
|
|
|
void seek()
|
|
|
|
|
{int i,item,flag; /* item-选项编号,flag-判定标记 */
|
|
|
|
|
char s1[21]; /* 定义输入字符空间 */
|
|
|
|
|
printf("------------------\n");
|
|
|
|
|
printf("1.按职工号查询\n");
|
|
|
|
|
printf("2.按学历查询\n");
|
|
|
|
|
printf("3.退出本菜单\n");
|
|
|
|
|
printf("------------------\n");
|
|
|
|
|
while(1)
|
|
|
|
|
{ printf("请选择子菜单编号:");
|
|
|
|
|
scanf("%d",&item);
|
|
|
|
|
flag=0;
|
|
|
|
|
switch(item)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
|
|
|
|
printf("请输入要查询的职工的职工号:\n");
|
|
|
|
|
scanf("%s",s1);
|
|
|
|
|
printf("职工号\t姓名\t性别\t年龄\t学历\t工资\t地址\t\t电话\n");
|
|
|
|
|
for(i=0;i<n;i++)
|
|
|
|
|
if(strcmp(sta[i].jobnum,s1)==0)
|
|
|
|
|
{ flag=1;
|
|
|
|
|
printf("%s\t%s\t%s\t%d\t%s\t%d\t%s\t%s\n",sta[i].jobnum,sta[i].name,sta[i].sex,sta[i].age,sta[i].edu,sta[i].sal,sta[i].add,sta[i].tel);
|
|
|
|
|
}
|
|
|
|
|
if(flag==0)
|
|
|
|
|
printf("该职工号不存在!\n"); break;
|
|
|
|
|
case 2:
|
|
|
|
|
printf("请输入要查询的职工的学历:\n");
|
|
|
|
|
scanf("%s",s1);
|
|
|
|
|
printf("职工号\t姓名\t性别\t年龄\t学历\t工资\t地址\t\t电话\n");
|
|
|
|
|
for(i=0;i<n;i++)
|
|
|
|
|
if(strcmp(sta[i].edu,s1)==0)
|
|
|
|
|
{ flag=1;
|
|
|
|
|
printf("%s\t%s\t%s\t%d\t%s\t%d\t%s\t%s\n",sta[i].jobnum,sta[i].name,sta[i].sex,sta[i].age,sta[i].edu,sta[i].sal,sta[i].add,sta[i].tel);
|
|
|
|
|
}
|
|
|
|
|
if(flag==0)
|
|
|
|
|
printf("不存在该学历职工!\n"); break;
|
|
|
|
|
case 3:return;
|
|
|
|
|
default:printf("请在1-3之间选择\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void modify() /*修改信息*/
|
|
|
|
|
{int i,item,num;
|
|
|
|
|
char sex1[3],s1[LEN+1],s2[LEN+1];
|
|
|
|
|
printf("请输入要要修改的职工的职工号:\n");
|
|
|
|
|
scanf("%s",s1);
|
|
|
|
|
for(i=0;i<n;i++)
|
|
|
|
|
if(strcmp(sta[i].jobnum,s1)==0)
|
|
|
|
|
num=i;
|
|
|
|
|
printf("------------------\n");
|
|
|
|
|
printf("1.修改姓名\n");
|
|
|
|
|
printf("2.修改性别\n");
|
|
|
|
|
printf("3.修改年龄\n");
|
|
|
|
|
printf("4.修改学历\n");
|
|
|
|
|
printf("5.修改工资\n");
|
|
|
|
|
printf("6.修改地址\n");
|
|
|
|
|
printf("7.修改电话\n");
|
|
|
|
|
printf("8.退出本菜单\n");
|
|
|
|
|
printf("------------------\n");
|
|
|
|
|
while(1)
|
|
|
|
|
{ printf("请选择子菜单编号:");
|
|
|
|
|
scanf("%d",&item);
|
|
|
|
|
switch(item)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
|
|
|
|
printf("请输入新的姓名:\n");
|
|
|
|
|
scanf("%s",s2);
|
|
|
|
|
strcpy(sta[num].name,s2); break;
|
|
|
|
|
case 2:
|
|
|
|
|
printf("请输入新的性别:\n");
|
|
|
|
|
scanf("%s",sex1);
|
|
|
|
|
strcpy(sta[num].sex,sex1); break;
|
|
|
|
|
case 3:
|
|
|
|
|
printf("请输入新的年龄:\n");
|
|
|
|
|
scanf("%d",&sta[num].age);break;
|
|
|
|
|
case 4:
|
|
|
|
|
printf("请输入新的学历:\n");
|
|
|
|
|
scanf("%s",s2);
|
|
|
|
|
strcpy(sta[num].edu,s2); break;
|
|
|
|
|
case 5:
|
|
|
|
|
printf("请输入新的工资:\n");
|
|
|
|
|
scanf("%d",&sta[num].sal); break;
|
|
|
|
|
case 6:
|
|
|
|
|
printf("请输入新的地址:\n");
|
|
|
|
|
scanf("%s",s2);
|
|
|
|
|
strcpy(sta[num].add,s2); break;
|
|
|
|
|
case 7:
|
|
|
|
|
printf("请输入新的电话号码:\n");
|
|
|
|
|
scanf("%s",s2);
|
|
|
|
|
strcpy(sta[num].tel,s2); break;
|
|
|
|
|
case 8:return;
|
|
|
|
|
default:printf("请在1-8之间选择\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void del() /* 删除信息 */
|
|
|
|
|
{ int i,j,flag=0;
|
|
|
|
|
char s1[LEN+1];
|
|
|
|
|
printf("请输入要删除职工的职工号:\n");
|
|
|
|
|
scanf("%s",s1);
|
|
|
|
|
for(i=0;i<n;i++)
|
|
|
|
|
if(strcmp(sta[i].jobnum,s1)==0)
|
|
|
|
|
{ flag=1;
|
|
|
|
|
for(j=i;j<n-1;j++)
|
|
|
|
|
sta[j]=sta[j+1];
|
|
|
|
|
}
|
|
|
|
|
if(flag==0)
|
|
|
|
|
printf("该职工号不存在!\n");
|
|
|
|
|
if(flag==1)
|
|
|
|
|
{ printf("删除成功\n");
|
|
|
|
|
n--;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void display()
|
|
|
|
|
{ int i;
|
|
|
|
|
printf("职工号\t姓名\t性别\t年龄\t学历\t工资\t地址\t\t电话\n");
|
|
|
|
|
for(i=0;i<n;i++)
|
|
|
|
|
{
|
|
|
|
|
printf("%s\t%s\t%s\t%d\t%s\t%d\t%s\t%s\n",sta[i].jobnum,sta[i].name,sta[i].sex,sta[i].age,sta[i].edu,sta[i].sal,sta[i].add,sta[i].tel);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void save() /* 保存信息 */
|
|
|
|
|
{ int i,flag=0;
|
|
|
|
|
FILE *fp;
|
|
|
|
|
fp=fopen("staff.txt","w");
|
|
|
|
|
for(i=0;i<n;i++)
|
|
|
|
|
{ fprintf(fp,"%s %s %s %d %s %d %s %s\n",sta[i].jobnum,sta[i].name,sta[i].sex,sta[i].age,sta[i].edu,sta[i].sal,sta[i].add,sta[i].tel);
|
|
|
|
|
}
|
|
|
|
|
fclose(fp);
|
|
|
|
|
printf("保存成功!");
|
|
|
|
|
}
|
|
|
|
|
void menu() /* 主菜单界面 */
|
|
|
|
|
{ int num;
|
|
|
|
|
printf(" \n\n职工信息管理系统\n\n");
|
|
|
|
|
printf("*****系统功能菜单*****\n");
|
|
|
|
|
printf("----------------------\n");
|
|
|
|
|
printf("1.读入职工信息\n");
|
|
|
|
|
printf("2.查询职工信息\n");
|
|
|
|
|
printf("3.修改职工信息\n");
|
|
|
|
|
printf("4.按职工号删除信息\n");
|
|
|
|
|
printf("5.显示当前信息\n");
|
|
|
|
|
printf("6.保存当前职工信息\n");
|
|
|
|
|
printf("7.退出系统\n");
|
|
|
|
|
printf("----------------------\n");
|
|
|
|
|
printf("请选择菜单编号:");
|
|
|
|
|
scanf("%d",&num);
|
|
|
|
|
switch(num)
|
|
|
|
|
{
|
|
|
|
|
case 1:readfile();break;
|
|
|
|
|
case 2:seek();break;
|
|
|
|
|
case 3:modify();break;
|
|
|
|
|
case 4:del();break;
|
|
|
|
|
case 5:display();break;
|
|
|
|
|
case 6:save();break;
|
|
|
|
|
case 7:k=0;break;
|
|
|
|
|
default:printf("请在1-7之间选择\n");
|
|
|
|
|
}
|
|
|
|
|
}
|