满意答案
cdtly
2013.03.24
采纳率:49% 等级:11
已帮助:12455人
#include
#include
#define NULL 0
typedef struct student
{
char clas[20];
char name[20];
char number[20];
int math;
int english;
int computer;
float sum;
float ave;
struct student *next;
}XSSJ;
void freerecord(XSSJ *p)
{
XSSJ *q;
while(p!=NULL)
{
q=p;
p=p->next;
free(q);
}
}
XSSJ *addrecord(XSSJ *p)
{
XSSJ head,*q;
head.next=p;
p=&head;
while(p->next!=NULL)
p=p->next;
while(1)
{
char text[80];
q=(XSSJ *)malloc(sizeof(XSSJ));
if(q==NULL)
return(head.next);
q->next=NULL;
printf("\n请输入学生的班级、姓名、学号和数学、英语、计算机成绩:");
gets(text);
if(text[0]=='\0')
break;
sscanf(text,"%s%s%s%d%d%d",&q->clas,&q->name,&q->number,&q->math,&q->english,&q->computer);
p->next=q;
p=q;
}
return(head.next);
}
XSSJ *createrecord(XSSJ *p)
{
freerecord(p);
return(addrecord(NULL));
}
XSSJ *deleterecord(XSSJ *p)
{
char number[10];
XSSJ *q,head;
printf("\n请输入你要删除的学生学号:\n");
gets(number);
for(head.next=p,q=&head;p!=NULL;p=p->next)
{
if(strcmp(p->number,number)!=0)
q=p;
else
{
q->next=p->next;
free(p);
printf("\n学号为%s的学生成绩已经删除。\n",number);
return(head.next);
}
}
printf("\n没有学号为%s的学生成绩。\n",number);
return(head.next);
}
void searchrecord(XSSJ *p)
{
char number[10];
printf("\n请输入你要查询的学生学号\n");
gets(number);
for(;p!=NULL;p=p->next)
{
if(strcmp(p->number,number)==0)
{
printf("\n班级%s\t姓名%s\t学号%s\t数学%d\t英语%d\t计算机%d\n",p->clas,p->name,p->number,p->math,p->english,p->computer);
}
}
printf("\n没有你要查询的成绩\n");
}
void displayrecord(XSSJ *p)
{
printf("\n班级\t姓名\t学号\t数学\t英语\t计算机\t\n");
for(;p!=NULL;p=p->next)
printf("\n%s\t%s\t%s\t%d\t%d\t%d\n",p->clas,p->name,p->number,p->math,p->english,p->computer);
printf("\n");
}
void displaymenu() //显示菜单
{
printf("\n\n______________菜单___________________\n");
printf("1:创建新纪录\t");
printf("2:添加新纪录\n");
printf("3:删除纪录 \t");
printf("4:查询纪录 \n");
printf("5:显示纪录 \t");
printf("0:退出系统 \n");
printf("\n请选择:");
}
int choiceitem(void)
{
int choice;
char line[80];
do
{
displaymenu();
gets(line);
choice=atoi(line);
}
while(choice<0||choice>6);
return(choice);
}
void main()
{
XSSJ *head=NULL;
int choice;
do
{
choice=choiceitem();
switch(choice)
{
case 1: head=createrecord(head);
break;
case 2: head=addrecord(head);
break;
case 3: head=deleterecord(head);
break;
case 4: searchrecord(head);
break;
case 5: displayrecord(head);
break;
}
}
while(choice!=0);
printf("\n\nEND!");
freerecord(head);
}
hhxy 11tx 06(这个是我的标 不是程序)
这个是我做的 没有名次排序的功能 我没有做出来呢 我也刚学这个 希望对你有帮助
00分享举报