C语言程序 哪位高手帮忙找下错(简单的职工管理系统)
#include<stdio.h>#include<stdlib.h>
#include<ctype.h>
#include<string.h>
typedef struct //定义职员的结构体,包括名字,性别,出生年月,工作年月,学历,职务,地址,电话
{
char name[20];//姓名
char 易做图; //性别
int birthday; //出生年月
int year; //工作年月
char degree; // 学历
char position; //职务
char address; // 地址
char phone; //电话
}employee;
struct employee emp[80]; //结构体数组变量
int menu_select() //菜单函数
{
char c;
do{
printf("职工管理系统\n"); //菜单选择
printf(" | 1. Input Records \n");
printf(" | 2. Display All Records |\n");
printf(" | 3. Sort |\n");
printf(" | 4. Insert a Record |\n");
printf(" | 5. Delete a Record |\n");
printf(" | 6. Query |\n");
printf(" | 7. Change |\n");
printf(" | 0. Quit |\n");
printf("Give your Choice(0-7):");
c=getchar(); //读入选择
}while(c<'0'||c>'7');
return(c-'0'); //返回选择
}
int Input(employee emp[],int n) //输入若干条记录
{
int i=0;
char sign;
do
{
printf("employee's name:\n"); //交互输入
scanf("%s",&employee[i].name);
printf("employee's 易做图:\n");
scanf("%s",&employee[i].易做图);
printf("employee's birthday:\n");
scanf("%d",&employee[i]. birthday);
printf("employee's year:\n");
scanf("%d",&employee[i].year);
printf("employee's degree:\n");
scanf("%s",&employee[i].degree);
printf("employee's position:\n");
scanf("%s",&employee[i].position);
printf("employee's address:\n");
scanf("%s",&employee[i].address);
printf("employee's phone:\n");
scanf("%s",&employee[i].phone);
printf("any more records?(Y/N)\n");
scanf("%c",&sign);//输入判断
i++;
} while(sign!='n'&&sign!='N'); //判断
return n+i;
}
Display(employee emp[],int n)//显示所有记录
{
int i;
printf("显示记录\n");
for(i=1;i<n+1;i++)//循环输入
printf("%s\t\t%s\t\t%d\t\t%d\t\t%s\t\t%s\t\t%s\t\t%s\n",emp[i-1].name,emp[i-1].易做图,emp[i-1].birthday,emp[i-1].year,emp[i-1].degree,emp[i-1].position,emp[i-1].address,emp[i-1].phone);
}
void Sort_by_name(employee emp[],int n) /*按学号排序*/
{
int i,j,k,s;
char t[10];
for(i=0;i<n-1;i++) /*冒泡法排序*/
for(j=0;j<n-1-i;j++)
if(strcmp(emp[j].name,emp[j+1].name)>0)
{
strcpy(t,emp[j+1].name); //复制姓名
strcpy(emp[j+1].name,emp[j].name);
strcpy(emp[j].name,t);
strcpy(t,emp[j+1].易做图); //复制性别
strcpy(emp[j+1].易做图,emp[j].易做图);
strcpy(emp[j].易做图,t);
s=emp[j+1]. birthday;//复制出生年月
emp[j+1].birthday=emp[j].birthday;
emp[j].birthday=s;
k=emp[j+1].year; //工作年月
emp[j+1].year=emp[j].year;
emp[j].year=k;
strcpy(t,emp[j+1].degree); //学历
strcpy(emp[j+1].degree,emp[j].degree);
strcpy(emp[j].degree,t);
strcpy(t,emp[j+1].position); //职务
strcpy(emp[j+1].position,emp[j].position);
strcpy(emp[j].position,t);
strcpy(t,emp[j+1].address); //住址
strcpy(emp[j+1].address,emp[j].address);
strcpy(emp[j].address,t);
strcpy(t,emp[j+1].phone); // 电话
strcpy(emp[j+1].phone,emp[j].phone);
strcpy(emp[j].phone,t);
}
}
int Insert_a_record(employee emp[],int n) /*插入一条记录*/
{
printf("employee's name:\n");
scanf("%s",&employee[i].name);
printf("employee's 易做图:\n");
scanf("%s",&employee[i].易做图);
printf("employee's birthday:\n");
scanf("%d",&employee[i]. birthday);
printf("employee's year:\n");
scanf("%d",&employee[i].year);
printf("employee's degree:\n");
scanf("%s",&employee[i].degree);
printf("employee's position:\n");
scanf("%s",&employee[i].position);
printf("employee's address:\n");
scanf("%s",&employee[i].address);
printf("employee's phone:\n");
scanf("%s",&employee[i].phone);
n++;
Sort_by_name(emp,n); /*调用排序函数*/
printf("成功插入记录\n"); /*返回成功信息*/
return(n);
}
int Delete_a_record(employee emp[],int n) /*按姓名查找,删除一条记录*/
{
char s[20];
int i=0,j;
printf("请输入姓名:\n"); /*交互式问寻*/
scanf("%s",s);
while(strcmp(emp[i].name,s)!=0&&i<n) i++; /*查找判断*/
if(i==n)
{
printf("未查找到\n"); /*返回失败信息*/
return(n);
}
for(j=i;j<n-1;j++) /*删除操作*/
{
strcpy(stud[j].num,stud[j+1].num);
strcpy(stud[j].name,stud[j+1].name);
stud[j].score=stud[j+1].score;
}
printf("删除成功!\n"); /*返回成功信息*/
return(n-1);
}
void Query_a_record(employee emp[],int n) /*查找并显示一个记录*/
{
char s;
int i=0;
printf("输入性别 男性:m 女性:w \n"); /*交互式输入*/
scanf("%s",s);
while(strcmp(emp[i].易做图,s)!=0&&i<n) i++; /*查找判断*/
if(i==n)
{
printf("未查找到记录!\n"); /*输入失败信息*/
return;
}
printf("%s\t\t%s\t\t%d\t\t%d\t\t%s\t\t%s\t\t%s\t\t%s\n",emp[i].name,emp[i].易做图,emp[i].birthday,emp[i].year,emp[i].degree,emp[i].position,emp[i].address,emp[i].phone);
}
void Change_a_record(employee emp[],int n) //查找记录并修改记录
{
char s[20], s, m;
int i=0;
printf("请输入姓名:\n"); /*交互式问寻*/
scanf("%s",s);
while(strcmp(emp[i].name,s)!=0&&i<n) i++; /*查找判断*/
if(i==n)
{
printf("未查找到\n"); /*返回失败信息*/
return(n);
}
printf("请输入要修改的信息 学历:d 职务:p 住址:a 电话:t\n");
scanf("%s",&s);
printf("请输入修改后的信息:\n");
scanf("%s",&m);
switch(s)
{
case d: strcpy(emp[i].degree,m); break;
case p: strcpy(emp[i].position,m); break;
case a: strcpy(emp[i].address,m); break;
case t: strcpy(emp[i].phone,m); break;
default: printf("输入错误!\n");
}
}
void main() /*主函数*/
{
int n=0;
for(;;)
{
switch(menu_select()) /*选择判断*/
{
case 1:
printf("Input Records\n"); /*输入若干条记录*/
n=Input(emp,n);
break;
case 2:
printf("Display All Records\n"); /*显示所有记录*/
Display(emp,n);
break;
case 3:
printf("Sort\n");
Sort_by_name(emp,n); /*按姓名排序*/
printf("Sort Suceessed!\n");
break;
case 4:
printf("Insert a Record\n");
n=Insert_a_record(emp,n); /*插入一条记录*/
break;
case 5:
printf("Delete a Record\n");
n=Delete_a_record(emp,n); /*按姓名查找,删除一条记录*/
break;
case 6:
printf("Query\n");
Query_a_record(emp,n); /*查找并显示一个记录*/
break;
case 7:
printf("Change\n");
Change_a_record(emp,n); /*新增功能,输出统计信息*/
break;
case 0:
printf("Have a Good Luck,Bye-bye!\n"); /*结束程序*/
exit(0);
}
}
}