学生成绩管理系统--帮忙看一下这段代码中怎么编写browse()函数模块
/* HELLO.C -- Hello, world */#include "stdio.h"
#include "conio.h"
typedef struct student
{char num[11];
char name[20];
int score[3];
float ave;
struct student *next;
}STU,*PSTU;
STU head;
PSTU Phead,Ptail;
void Init(void)
{
head.next=NULL;
Phead = &head;
Ptail = Phead;
}
void Menu(void);
void Save(void)
{
FILE *fp;
PSTU tmp;
tmp=Phead->next;
fp = fopen("e:\\data.txt","w");
while(tmp!=NULL){
fprintf(fp,"%s %s %d %d %d %f\n",tmp->num,tmp->name,tmp->score[0],tmp->score[1],tmp->score[2],tmp->ave);
tmp=tmp->next;
}
fclose(fp);
}
void InputNum(char *num)
{
char no[1000];
int err=0,i;
while(1)
{
clrscr();
printf("Please Input Number\n");
scanf("%s",no);
if(strlen(no)>10){err=1;printf("Err");}
for(i=0;i<strlen(no);i++){
if(no[i]<'0' || no[i]>'9') {err=1;printf("Err");}
}
if(err==1){err=0;continue;}
else break;
}
strcpy(num,no);
}
void InputName(char *name)
{
printf("InputName\n");
scanf("%s",name);
}
void InputScore(int *score)
{
int i;
printf("InputScore\n");
for(i=0;i<3;i++)
scanf("%d",&score[i]);
}
int PrintMenu(void)
{
int n,w1;
do
{
clrscr(); /*清屏*/
puts("\t\t*********************MENU*********************\n\n");
puts("\t\t\t\t1.Enter new data");
puts("\t\t\t\t2.Addition data");
puts("\t\t\t\t3.Modify data");
puts("\t\t\t\t4.Delete data");
puts("\t\t\t\t5.Browse all");
puts("\t\t\t\t6.Search by name");
puts("\t\t\t\t7.Insert data");
puts("\t\t\t\t8.Order by average");
puts("\t\t\t\t9.Exit");
puts("\n\n\t\t**********************************************\n");
printf("Choice your number(1-9): [ ]\b\b");
scanf("%d",&n);
if(n>=1&&n<=9) /*对选择的数字作判断*/
{return n;}
}while(1);
}
void InputInfo(void)
{
int sel;
PSTU tmp;
char num[11]="1234",name[20]="LiJun";
int score[3]={56,44,88};
clrscr();
printf("Enter new data\n");
InputNum(num);
InputName(name);
InputScore(score);
tmp = (PSTU)malloc(sizeof(STU));
strcpy(tmp->num,num);
strcpy(tmp->name,name);
tmp->score[0]= score[0];
tmp->score[1]= score[1];
tmp->score[2]= score[2];
tmp->ave=(score[0]+score[1]+score[2])/3.0;
Ptail->next= tmp;
tmp->next=NULL;
Ptail=tmp;
Save();
printf("num=%s name=%s score1=%d score2=%d score3=%d ave=%f\n",Ptail->num,Ptail->name,Ptail->score[0],Ptail->score[1],Ptail->score[2],Ptail->ave);
printf("1.Back To Menu 2.ReInput\n");
scanf("%d",&sel);
if(sel==1)Menu();
else if(sel==2)InputInfo();
}
void Browse(void)
{
STU *p;
printf("Browse\n");
p=&head;
printf("\n*****************************STUDENT*****************************\n");
printf("\n---------------------------------------------------------\n");
printf("|Num | Name | Score1 | Score2 | Score3 | ave |\n");
while(p->next!=NULL)
{
printf("|%3s | %3s | %3d | %3d | %3d | %3f |\n",p->num,p->name,p->score[1],p->score[2],p->score[3],p->ave);
p=p->next;
}
printf("-----------------------------------------------------------\n");
printf("*******************************END*********************************\n");
}
void Add(void)
{
printf("Add\n");
}
void Modify(void)
{
printf("Modify\n");
}
void Del(void)
{
printf("Del\n");
}
void Search(void)
{
printf("Search\n");
}
void Exit(void)
{
exit(0);
}
void Menu(void)
{
int sel;
sel=PrintMenu();
switch(sel){
case 1:
InputInfo( );
break;
case 2:
Add( );
break;
case 3:
Modify( );
break;
case 4:
Del( );
break;
case 5:
Browse();
break;
case 6:
Search( );
break;
case 9:
Exit( );
break;
default:
break;
}
}
main()
{
Init();
Menu();
getch();
}