|
|
@ -44,19 +44,19 @@ void main() /*
|
|
|
|
printf("\t\t\t0.退出\n\n"); /*退出*/
|
|
|
|
printf("\t\t\t0.退出\n\n"); /*退出*/
|
|
|
|
printf("\t\t\t请输入你的选择:");
|
|
|
|
printf("\t\t\t请输入你的选择:");
|
|
|
|
scanf("%d",&b);
|
|
|
|
scanf("%d",&b);
|
|
|
|
switch(b)
|
|
|
|
switch(b)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
case 1:type();break; /*调用录入学生信息函数*/
|
|
|
|
case 1:type();break; /*调用录入学生信息函数*/
|
|
|
|
case 2:look();break; /*调用查看函数*/
|
|
|
|
case 2:look();break; /*调用查看函数*/
|
|
|
|
case 3:search_name();break; /*调用姓名查看学生信息函数*/
|
|
|
|
case 3:search_name();break; /*调用姓名查看学生信息函数*/
|
|
|
|
case 4:search_number();break; /*调用学号查看学生信息函数*/
|
|
|
|
case 4:search_number();break; /*调用学号查看学生信息函数*/
|
|
|
|
case 5:order();break; /*调用学号排序学生信息函数*/
|
|
|
|
case 5:order();break; /*调用学号排序学生信息函数*/
|
|
|
|
case 6:del();break;/*调用删除函数*/
|
|
|
|
case 6:del();break;/*调用删除函数*/
|
|
|
|
case 7:save();break;/*调用保存函数*/
|
|
|
|
case 7:save();break;/*调用保存函数*/
|
|
|
|
case 8:see();break;/*调用打开文件函数*/
|
|
|
|
case 8:see();break;/*调用打开文件函数*/
|
|
|
|
case 0:flag=1;break;/*退出SWITCH语句*/
|
|
|
|
case 0:flag=1;break;/*退出SWITCH语句*/
|
|
|
|
default :printf("错误!");
|
|
|
|
default :printf("错误!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(flag)
|
|
|
|
if(flag)
|
|
|
|
break; /*如果选择0就退出循环*/
|
|
|
|
break; /*如果选择0就退出循环*/
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -64,6 +64,7 @@ void main() /*
|
|
|
|
void type() /*定义录入学生信息函数*/
|
|
|
|
void type() /*定义录入学生信息函数*/
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int i; /*定义局部变量*/
|
|
|
|
int i; /*定义局部变量*/
|
|
|
|
|
|
|
|
n=openl(); /*调用openl函数*/
|
|
|
|
printf("\t\t输出你想输入的学生信息个数:");
|
|
|
|
printf("\t\t输出你想输入的学生信息个数:");
|
|
|
|
scanf("%d",&n);
|
|
|
|
scanf("%d",&n);
|
|
|
|
for(i=0;i<n;i++)
|
|
|
|
for(i=0;i<n;i++)
|
|
|
@ -99,7 +100,7 @@ void save() /*
|
|
|
|
printf("不能打开文件!\n");
|
|
|
|
printf("不能打开文件!\n");
|
|
|
|
return; /*终止程序*/
|
|
|
|
return; /*终止程序*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(i=0;i
|
|
|
|
for(i=0;!feof(fp);i++)
|
|
|
|
if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)
|
|
|
|
if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)
|
|
|
|
printf("文件写入错误\n");
|
|
|
|
printf("文件写入错误\n");
|
|
|
|
fclose(fp); /*关闭文件*/
|
|
|
|
fclose(fp); /*关闭文件*/
|
|
|
@ -124,10 +125,11 @@ void search_name() /*
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int i;
|
|
|
|
char name[20]; /*声明字符数组*/
|
|
|
|
char name[20]; /*声明字符数组*/
|
|
|
|
|
|
|
|
n=openl();
|
|
|
|
printf("\t\t\t请输入学生姓名:\n");
|
|
|
|
printf("\t\t\t请输入学生姓名:\n");
|
|
|
|
scanf("%s",name);
|
|
|
|
scanf("%s",name);
|
|
|
|
printf("\t学号\t姓名\t性别\t年龄\t地址\t电话\tE-mail\t年\t月\t日\n");
|
|
|
|
printf("\t学号\t姓名\t性别\t年龄\t地址\t电话\tE-mail\t年\t月\t日\n");
|
|
|
|
for(i=0;i
|
|
|
|
for(i=0;i<n;i++)
|
|
|
|
if(strcmp(stu[i].name,name)==0) /*将输入的姓名与结构体中的姓名进行比较*/
|
|
|
|
if(strcmp(stu[i].name,name)==0) /*将输入的姓名与结构体中的姓名进行比较*/
|
|
|
|
{
|
|
|
|
{
|
|
|
|
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",stu[i].num,stu[i].name,
|
|
|
|
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",stu[i].num,stu[i].name,
|
|
|
@ -140,10 +142,11 @@ void search_number() /*
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int i;
|
|
|
|
char number[15]; /*声明字符数组*/
|
|
|
|
char number[15]; /*声明字符数组*/
|
|
|
|
|
|
|
|
n=openl();
|
|
|
|
printf("\t\t\t请输入学号:\n");
|
|
|
|
printf("\t\t\t请输入学号:\n");
|
|
|
|
scanf("%s",number);
|
|
|
|
scanf("%s",number);
|
|
|
|
printf("\t学号\t姓名\t性别\t年龄\t地址\t电话\tE-mail\t年\t月\t日\n");
|
|
|
|
printf("\t学号\t姓名\t性别\t年龄\t地址\t电话\tE-mail\t年\t月\t日\n");
|
|
|
|
for(i=0;i
|
|
|
|
for(i=0;i<n;i++)
|
|
|
|
if(strcmp(stu[i].num,number)==0) /*将输入的学号与结构体中的学号进行比较*/
|
|
|
|
if(strcmp(stu[i].num,number)==0) /*将输入的学号与结构体中的学号进行比较*/
|
|
|
|
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",stu[i].num,stu[i].name,
|
|
|
|
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",stu[i].num,stu[i].name,
|
|
|
|
stu[i].sex,stu[i].age,stu[i].ad,stu[i].tel,stu[i].E,stu[i].year,stu[i].month,stu[i].day);
|
|
|
|
stu[i].sex,stu[i].age,stu[i].ad,stu[i].tel,stu[i].E,stu[i].year,stu[i].month,stu[i].day);
|
|
|
@ -155,22 +158,22 @@ void order() /*
|
|
|
|
int i,j;
|
|
|
|
int i,j;
|
|
|
|
char a;
|
|
|
|
char a;
|
|
|
|
struct student temp; /*声明结构体变量*/
|
|
|
|
struct student temp; /*声明结构体变量*/
|
|
|
|
|
|
|
|
n=openl();
|
|
|
|
printf("\t学号\t姓名\t性别\t年龄\t地址\t电话\tE-mail\t年\t月\t日\n");
|
|
|
|
printf("\t学号\t姓名\t性别\t年龄\t地址\t电话\tE-mail\t年\t月\t日\n");
|
|
|
|
for(i=0;i
|
|
|
|
for(i=0;i<n;i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
for(j=i+1;j
|
|
|
|
for(j=i+1;j<n-1;j++)
|
|
|
|
if(stu[i].sum
|
|
|
|
if(stu[i].num>stu[j].num)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
temp=stu[i];
|
|
|
|
temp=stu[i];
|
|
|
|
stu[i]= stu[j];
|
|
|
|
stu[i]= stu[j];
|
|
|
|
stu[j]=temp;
|
|
|
|
stu[j]=temp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("%10s\t%s\t%2s\t%d\t%d\t%d\t%3.1f\t\t%6.1f\n",stu[i].num,stu[i].name,
|
|
|
|
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",stu[i].num,stu[i].name,
|
|
|
|
stu[i].sex,stu[i].english,stu[i].math,stu[i].chinese,stu[i].aver,stu[i].sum);
|
|
|
|
stu[i].sex,stu[i].age,stu[i].ad,stu[i].tel,stu[i].E,stu[i].year,stu[i].month,stu[i].day);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
getch();
|
|
|
|
getch();
|
|
|
|
printf("是否保存?(y or n)");
|
|
|
|
printf("是否保存?(y or n)");
|
|
|
|
getchar();
|
|
|
|
|
|
|
|
scanf("%c",&a);
|
|
|
|
scanf("%c",&a);
|
|
|
|
if(a=='y') /*是否保存排序后的文件*/
|
|
|
|
if(a=='y') /*是否保存排序后的文件*/
|
|
|
|
save();
|
|
|
|
save();
|
|
|
@ -183,10 +186,11 @@ void del() /*
|
|
|
|
int i;
|
|
|
|
int i;
|
|
|
|
char a;
|
|
|
|
char a;
|
|
|
|
char name[20];
|
|
|
|
char name[20];
|
|
|
|
|
|
|
|
n=openl();
|
|
|
|
printf("\t\t\t输入学生名字:\n");
|
|
|
|
printf("\t\t\t输入学生名字:\n");
|
|
|
|
scanf("%s",name);
|
|
|
|
scanf("%s",name);
|
|
|
|
printf("\t学号\t姓名\t性别\t年龄\t地址\t电话\tE-mail\t年\t月\t日\n");
|
|
|
|
printf("\t学号\t姓名\t性别\t年龄\t地址\t电话\tE-mail\t年\t月\t日\n");
|
|
|
|
for(i=0;i
|
|
|
|
for(i=0;i<n;i++)
|
|
|
|
if(strcmp(stu[i].name,name)==0)
|
|
|
|
if(strcmp(stu[i].name,name)==0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",stu[i].num,stu[i].name,
|
|
|
|
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",stu[i].num,stu[i].name,
|
|
|
@ -197,14 +201,14 @@ void del() /*
|
|
|
|
scanf("%c",&a);
|
|
|
|
scanf("%c",&a);
|
|
|
|
if(a=='y') /*是否删除该信息*/
|
|
|
|
if(a=='y') /*是否删除该信息*/
|
|
|
|
{
|
|
|
|
{
|
|
|
|
for(;i
|
|
|
|
for(i=0;i<n;i++)
|
|
|
|
stu[i]=stu[i+1];
|
|
|
|
stu[i]=stu[i+1];
|
|
|
|
n=n-1;
|
|
|
|
n=n-1;
|
|
|
|
printf("你已经删除信息");
|
|
|
|
printf("你已经删除信息");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
printf("退出")
|
|
|
|
printf("退出");
|
|
|
|
getch();
|
|
|
|
getchar();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
save();
|
|
|
|
save();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -218,7 +222,7 @@ int openl() /*
|
|
|
|
exit(0);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(i=0;!feof(fp);i++)
|
|
|
|
for(i=0;!feof(fp);i++)
|
|
|
|
fread(&stu[i],sizeof(struct student),1,fp);
|
|
|
|
fread(&stu[i],sizeof(struct student),1,fp);
|
|
|
|
fclose(fp);
|
|
|
|
fclose(fp);
|
|
|
|
return(i-1);
|
|
|
|
return(i-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -230,74 +234,11 @@ void see() /*
|
|
|
|
printf("按任意键查看!\n");
|
|
|
|
printf("按任意键查看!\n");
|
|
|
|
getch();
|
|
|
|
getch();
|
|
|
|
printf("\t学号\t姓名\t性别\t年龄\t地址\t电话\tE-mail\t年\t月\t日\n");
|
|
|
|
printf("\t学号\t姓名\t性别\t年龄\t地址\t电话\tE-mail\t年\t月\t日\n");
|
|
|
|
for(i=0;i
|
|
|
|
|
|
|
|
if(strcmp(stu[i].name,name)==0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",stu[i].num,stu[i].name,stu[i].sex,stu[i].age,stu[i].ad,stu[i].tel,stu[i].E,stu[i].year,stu[i].month,stu[i].day);
|
|
|
|
|
|
|
|
getch();
|
|
|
|
|
|
|
|
printf("真的删除?(y or n)");
|
|
|
|
|
|
|
|
getchar();
|
|
|
|
|
|
|
|
scanf("%c",&a);
|
|
|
|
|
|
|
|
if(a=='y') /*是否删除该信息*/
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
for(;i
|
|
|
|
|
|
|
|
stu[i]=stu[i+1];
|
|
|
|
|
|
|
|
n=n-1;
|
|
|
|
|
|
|
|
printf("你已经删除信息");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
printf("退出");
|
|
|
|
|
|
|
|
getch();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
save();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int openl() /*定义打开文件函数*/
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
FILE *fp;
|
|
|
|
|
|
|
|
if((fp=fopen("student.txt","rb"))==NULL)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printf("Cannot open file.\n");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(i=0;!feof(fp);i++)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fread(&stu[i],sizeof(struct student),1,fp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return(i-1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void see() /*打开并查看文件*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
n=openl();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printf("文件打开成功!\n");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printf("按任意键查看!\n");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getch();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printf("\t学号\t姓名\t性别\t年龄\t地址\t电话\tE-mail\t年\t月\t日\n");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(i=0;i<n;i++)
|
|
|
|
for(i=0;i<n;i++)
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",stu[i].num,stu[i].name,
|
|
|
|
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",stu[i].num,stu[i].name,
|
|
|
|
stu[i].sex,stu[i].age,stu[i].ad,stu[i].tel,stu[i].E,stu[i].year,stu[i].month,stu[i].day);
|
|
|
|
|
|
|
|
|
|
|
|
stu[i].sex,stu[i].age,stu[i].ad,stu[i].tel,stu[i].E,stu[i].year,stu[i].month,stu[i].day);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("\n\n\n\t\t\t按任意键返回菜单");
|
|
|
|
printf("\n\n\n\t\t\t按任意键返回菜单");
|
|
|
|
getchar();
|
|
|
|
getchar();
|
|
|
|
|
|
|
|
}
|