char order_menu()
{
system("cls");
char ch;
printf("\n\n\n\n");
printf("\t\t ————————————————————————\n");
printf("\t\t| 学生个人信息查询 |\n");
printf("\t\t|———————————————————————|\n");
printf("\t\t| 1.按学号排序 |\n");
printf("\t\t| |\n");
printf("\t\t| 2.按成绩排序 |\n");
printf("\t\t| |\n");
printf("\t\t| 3.浏览排序表 |\n");
printf("\t\t| |\n");
printf("\t\t| 4.退 出排序 |\n");
printf("\t\t ————————————————————————\n");
printf("\t\t 请您正确选择:");
ch=getchar();
fflush(stdin);
return ch;
}
int order()//排序主函数
{
char ch;
while(1)
{
ch=order_menu();
switch(ch)
{
case '1':
order_num();
break;
case '2':
order_grade();
break;
case '3':
order_view();
break;
case '4':
return 0;
default:
break;
}
}
return 0;
}
int order_num()//生成按学号排序文件
{
stu_list s_list,s_temp;
link p;
int i=0;
init_list(s_list);
init_list(s_temp);
system("cls");
if(open_file(s_list,"data/student.dat")<0)
{
free_list(s_list);
free_list(s_temp);
return -1;
}
while(s_list.head->next)
{
p=get_minnum(s_list);
p->pagenum=i/8+1;
i++;
insert_s(s_temp,p);
}
free(s_list.head);
if(save_stu(s_temp,"data/order_num.dat")<0)
return -1;
system("cls");
showresult(s_temp);
free_list(s_temp);
printf("\t 按任意键继续...");
getch();
return 0;
}
int order_grade()//生成按成绩排序文件
{
stu_list s_list,s_temp;
link p;
int i=0;
init_list(s_list);
init_list(s_temp);
system("cls");
if(open_file(s_list,"data/student.dat")<0)
{
free_list(s_list);
free_list(s_temp);
return -1;
}
while(s_list.head->next)
{
p=get_minnum(s_list);
insert_s(s_temp,p);
}
free(s_list.head);
if(save_stu(s_temp,"data/temp.dat")<0)
{
free_list(s_temp);
return -1;
}
free_list(s_temp);
init_list(s_list);
init_list(s_temp);
open_file(s_list,"data/temp.dat");
while(s_list.head->next)
{
p=get_maxgrade(s_list);
p->pagenum=i/8+1;
i++;
insert_s(s_temp,p);
}
free(s_list.head);
save_stu(s_temp,"data/order_grade.dat");
system("cls");
showresult(s_temp);
free_list(s_temp);
unlink("data/temp.dat");//删除临时文件
printf("\t 按任意键继续...");
getch();
return 0;
}
int order_view()//浏览排序文件
{
int in;
char ch;
stu_list s_list;
while(1)
{
init_list(s_list);
system("cls");
printf("\n\n\n");
printf("\t\t输入选择(0浏览成绩排序文件,1浏览序号排序文件):");
while(scanf("%d",&in)!=1)
{
while((ch=getchar())!='\n')
putchar(ch);
}
fflush(stdin);
switch(in)
{
case 0:
{
system("cls");
if(open_file(s_list,"data/order_grade.dat")<0)
{
free_list(s_list);
return -1;
}
system("cls");
showresult(s_list);
free_list(s_list);
printf("\t 按任意键继续...");
getch();
return 0;
}
case 1:
{
system("cls");
if(open_file(s_list,"data/order_num.dat")<0)
{
free_list(s_list);
return -1;
}
system("cls");
showresult(s_list);
free_list(s_list);
printf("\t 按任意键继续...");
getch();
return 0;
}
default:
break;
}
}
return 0;
}
int main()
{
char ch;
char *FileName="data/student.dat";
if(init()<0)
return -1;
if(login()==-1)
{
printf("\t\t ");
return 0;
}
while(1)
{
ch=main_menu();
switch(ch)
{
case '1':
add_stu(FileName);
o_str("按任意键继续...");
getch();
break;
case '2':
update_stu(FileName);
break;
case '3':
sort_stu(FileName);
break;
case '4':
read_all(FileName);
break;
case '5':
delete_stu(FileName);
break;
case '6':
order();
break;
case '7':
printf("\t\t ");
return 0;
default :
break;
}
}
}
只有想不到,没有做不到