#include
#include
#include
#include
typedef struct student{
char number[10];
char name[10];
int grade;
struct student *next;
}ADDR;
int menu_select();
ADDR *input(ADDR *);
void output(ADDR *);
void Avg(struct student *);
void highscore(struct student *);
#include "61.h"
void main()
{
ADDR *top;
top=(ADDR *)malloc(sizeof(ADDR));
if(top==NULL)
{
printf("memory fail!");
exit(-1);
}
top=NULL;
for( ; ; ){
switch(menu_select())
{
case 1:
input(top);
break;
case 2:
output(top);
break;
case 3:
Avg(top);
break;
case 4:
highscore(top);
default:
printf("输入错误!\n");
exit(0);
}
}
}
#include "61.h"
ADDR *input(ADDR *top)
{
ADDR *old;
ADDR *star;
int i=0;
star=(ADDR *)malloc(sizeof(ADDR));
old=(ADDR *)malloc(sizeof(ADDR));
if(star==NULL||old==NULL)
{
printf("memory fail!");
exit(-1);
}
else
{
{
printf("输入数据,输入0时结束. \n");
printf(" 学号 : ");
scanf("%s",star->number);
printf(" 姓名 : ");
scanf("%s",star->name);
printf(" 成绩 : ");
scanf("%d",&star->grade);
while(strcmp(star->number,"0")>0)
{
if(top==NULL)
top=star;
else
old->next=star;
old=star;
star=(ADDR *)malloc(sizeof(ADDR));
printf("继续输入数据,输入0时结束. \n");
printf(" 学号 : ");getchar();
gets(star->number);
printf(" 姓名 : ");
gets(star->name);
printf(" 成绩 : ");
scanf("%d",&star->grade);
star->next=NULL;
}
free(star);
return(top);
}
}
}
#include"61.h"
int menu_select()
{
char s[2];
int cn=0;
printf("\n");
printf("1. 输入数据 \n");
printf("2. 输出数据 \n");
printf("3. 平均成绩\n");
printf("4. 最高成绩\n");
printf("5. 退出运行\n") ;
printf("\n 左边数字对应功能选择, 请选1-5: ");
for ( ; ; )
{
gets(s);
cn=atoi (s);
if(cn<1|| cn>6)
printf("\n输入错误,重选1-5");
else break;
}
return cn;
}
#include "61.h"
void output(ADDR *top)
{
if(top=NULL)
{
printf("\n 现在没有记录 !\n");
return;
}
printf(" 学号\t姓名\t成绩\t\n");
while(top->next!=NULL)
{
printf("%s\t%s\t%d\n",top->number,top->name,top->grade);
top=top->next;
}
}