学生统计系统C语言.docx
《学生统计系统C语言.docx》由会员分享,可在线阅读,更多相关《学生统计系统C语言.docx(11页珍藏版)》请在冰点文库上搜索。
![学生统计系统C语言.docx](https://file1.bingdoc.com/fileroot1/2023-5/20/1c88dd42-6b95-412c-8f88-604a810e117b/1c88dd42-6b95-412c-8f88-604a810e117b1.gif)
学生统计系统C语言
实验代码:
#include"stdio.h"
#include"stdlib.h"
#include"string.h"
#defineN5
structs
{
charname[20];
charxuehao[10];
intage;
charsex[2];
intmath;
intxinxi;
intEnglish;
charzy[4];
intgrade;
intsum;
structs*next;
};
voidshuru(structs*head);
voidshuchu(structs*head);
voidpx(structs*head);
voidcx(structs*head);
voidadd(structs*head);
voiddel(structs*head);
main()
{
charch;
intflag=1;
structs*head=NULL,*tail=NULL;
head=(structs*)malloc(sizeof(structs));
head->next=NULL;
tail=head;
printf("这是一个统计学生成绩的程序\n");
printf("****************************************\n");
printf("A->输入学生的信息:
\n");
printf("B->输出学生信息:
\n");
printf("C->对学生按照总成绩排序:
\n");
printf("D->查找学生信息:
\n");
printf("E->增加学生信息:
\n");
printf("F->删除学生信息:
\n");
printf("R->结束\n");
printf("****************************************\n");
printf("请输入你要进行的操作(请先进行成绩的输入按A):
\n");
for(flag=1;;flag++)
{
scanf("%c",&ch);
switch(ch)
{
case'A':
shuru(head);("信息录入完毕\n");printf("\n");printf("请输入其他操作:
\n");break;
case'B':
shuchu(head);printf("\n");printf("请输入其他操作:
\n");break;
case'C':
px(head);printf("\n");printf("请输入其他操作:
\n");break;
case'D':
cx(head);printf("\n");printf("请输入其他操作:
\n");break;
case'E':
add(head);printf("\n");printf("请输入其他操作:
\n");break;
case'F':
del(head);printf("\n");printf("请输入其他操作:
\n");break;
case'R':
flag=-1;printf("\n");printf("结束本程序,谢谢使用!
");break;
default:
flag=0;
}
if(flag==-1)
break;
else
continue;
}
}
voidshuru(structs*head)
{
structs*tail=NULL,*p=NULL;
inti,t;
chars[20];
printf("请输入该班级的年级:
");
scanf("%d",&t);
printf("请输入该班级的专业:
");
scanf("%s",s);
head->next=NULL;
tail=head;
printf("请逐个输入学生的信息:
\n");
for(i=0;i{
p=(structs*)malloc(sizeof(structs));
printf("请输入第%d个学生的信息:
\n",i+1);
printf("姓名:
");
scanf("%s",p->name);
printf("学号:
");
scanf("%s",p->xuehao);
printf("年龄:
");
scanf("%d",&p->age);
printf("性别:
");
scanf("%s",p->sex);
printf("高数成绩:
");
scanf("%d",&p->math);
printf("C语言:
");
scanf("%d",&p->xinxi);
printf("英语:
");
scanf("%d",&p->English);
strcpy(p->zy,s);
p->grade=t;
p->sum=p->English+p->math+p->xinxi;
p->next=NULL;
tail->next=p;
tail=p;
}
}
voidshuchu(structs*head)
{structs*p;
printf("该班级的学生信息如下:
\n\n");
printf("姓名\t学号\t年龄\t性别\t年级\t专业\t高数\tC语言\t英语\t总分\n");
for(p=head->next;p!
=NULL;p=p->next)
{
printf("%s\t%s\t%d\t%s\t%d\t%s\t%d\t%d\t%d\t%d\n",p->name,p->xuehao,p->age,p->sex,p->grade,p->zy,p->math,p->xinxi,p->English,p->sum);
}
}
voidpx(structs*head)
{
inti,j;
structs*p,*q,*m,*s;
for(i=0;i{
p=head;
q=p->next;
m=q->next;
for(j=0;j{
if((q->sum)<(m->sum))
{
p->next=q->next;
q->next=m->next;
m->next=q;
s=q;q=m;m=s;
}
p=p->next;q=q->next;m=m->next;
}
}
printf("按照总成绩排名顺序是:
\n\n");
printf("姓名\t学号\t总分\n");
for(p=head->next;p!
=NULL;p=p->next)
{
printf("%s\t%s\t%d\n",p->name,p->xuehao,p->sum);
}
}
voidcx(structs*head)
{
chara[10],b[20];
charch;
inti,flag=1;
structs*p=head;
printf("按学号查找->a按姓名查找按->b\n");
for(flag=1;;flag++)
{
scanf("%c",&ch);
switch(ch)
{
case'a':
{printf("请输入要查询学生的学号:
");
scanf("%s",a);
for(i=0;i{
p=p->next;
If(!
strcmp(p->xuehao,a))
{
printf("姓名\t学号\t年龄\t性别\t年级\t专业\t高数\tC语言\t英语\t总分\n");printf("%s\t%s\t%d\t%s\t%d\t%s\t%d\t%d\t%d\t%d\n",p->name,p->xuehao,p->age,p->sex,p->grade,p->zy,p->math,p->xinxi,p->English,p->sum);
break;
}
if(strcmp(p->xuehao,a)&&p->next==NULL)
printf("查询无果,请确定学号是否正确\n");
}
flag=-1;
break;
}
case'b':
{printf("请输入要查询学生的姓名:
");
scanf("%s",b);
for(i=0;i{
p=p->next;
if(!
strcmp(p->name,b))
{
printf("姓名\t学号\t年龄\t性别\t年级\t专业\t高数\tC语言\t英语\t总分\n");printf("%s\t%s\t%d\t%s\t%d\t%s\t%d\t%d\t%d\t%d\n",p->name,p->xuehao,p->age,p->sex,p->grade,p->zy,p->math,p->xinxi,p->English,p->sum);
break;
}
if(strcmp(p->name,a)&&p->next==NULL)
printf("查询无果,请确定学号是否正确\n");
}
flag=-1;
break;
}
}
if(flag==-1)
break;
}
}
voidadd(structs*head)
{
structs*p;
intt;
chars[20];
p=(structs*)malloc(sizeof(structs));
p->next=head->next;head->next=p;
printf("现在请输入要加入学生的数据:
\n");
printf("请输入该班级的年级:
");
scanf("%d",&t);
printf("请输入该班级的专业:
");
scanf("%s",s);
printf("姓名:
");
scanf("%s",p->name);
printf("学号:
");
scanf("%s",p->xuehao);
printf("年龄:
");
scanf("%d",&p->age);
printf("性别:
");
scanf("%s",p->sex);
printf("高数成绩:
");
scanf("%d",&p->math);
printf("C语言:
");
scanf("%d",&p->xinxi);
printf("英语:
");
scanf("%d",&p->English);
strcpy(p->zy,s);
p->grade=t;
p->sum=p->English+p->math+p->xinxi;
printf("\n");
px(head);
}
voiddel(structs*head)
{
inti,flag=1;
charb[10];
structs*p;
structs*m=NULL;
if(head->next==NULL)
printf("错误!
未存入学生的信息,请按照开始的提示进行录入信息!
\n");
else
{
printf("请输入要删除学生信息的学生的学号:
\n");
scanf("%s",b);
p=head;
for(i=0,flag=1;i{
m=p;
p=p->next;
if(!
strcmp(p->xuehao,b))
{
m->next=p->next;
free(p);
printf("已删除!
\n");
flag=-1;
}
if(flag==-1)
break;
}
}
}