永发信息网

C语言学生成绩管理系统

答案:2  悬赏:70  手机版
解决时间 2021-01-25 12:16
要用上结构体,链表,指针,并且只用C语言编程
学生信息中包含:学号、姓名、三门课的成绩和平均成绩
要求:1.从文件加载学生信息;
2.显示全部学生信息;
3.查询学生信息
4.新增学生信息;
5.删除学生信息;
6.修改学生信息;
7.对学生信息排序(可以选择逆序和正序和反序);
8.保存当前信息到文件;
9.备份
最佳答案
#include
#include
#include
#include
struct sc
{
int chinese;
int maths;
int english;
};

typedef struct node
{
int num;
char name[20];
struct sc score;
struct node *next;
}st;

int menu()//菜单
{
int choice;
do{
system("cls");
printf("\t1.input the messega about a student\n");

printf("\t2.insect a messega of a new student\n");

printf("\t3.look for the messega\n");

printf("\t4.dellect the messega\n");

printf("\t5.arranging base on the number of learning\n");

printf("\t6.output all the messega\n");

printf("\t7.arranging base on all scores\n");

printf("\t8.exit the system\n");

printf("\tplease input your choice:");

scanf("%d",&choice);
}while(choice>7&&choice<1);
return choice;
}

st *create()//创建链表
{
st *head,*p,*tail;
char c;
head=tail=NULL;
while(c!='n'&&c!='N')
{

p=(st *)malloc(sizeof(st));
p->next=NULL;
printf("\t\tplease input the number of learning:");
scanf("%d",&p->num);

printf("\t\tplease input the name:");
scanf("%s",p->name);

printf("\t\tplease input the score of chinese:");
scanf("%d",&p->score.chinese);

printf("\t\tplease input the score of maths:");
scanf("%d",&p->score.maths);

printf("\t\tplease input the score of english:");
scanf("%d",&p->score.english);
if(head==NULL)

head=tail=p;
else
{
tail->next=p;
tail=p;
}

printf("\t\tcontinue or stop(Y/N):");
scanf("%s",&c);
}
return head;
}

st *arrange(st *head)// 以学号排名
{
st *p,*q;
int t,i=1,j,chinese,maths,english;
char name[20];
p=head;
if(head==NULL)
printf("\t\tNoting to arrange\n");
else
{
do
{
j=1;
while(p->next!=NULL)
{
q=p->next;
if(p->num>=q->num)
{
t=p->num;
p->num=q->num;
q->num=t;

strcpy(name,p->name);
strcpy(p->name,q->name);
strcpy(q->name,name);

chinese=p->score.chinese;
p->score.chinese=q->score.chinese;
q->score.chinese=chinese;

maths=p->score.maths;
p->score.maths=q->score.maths;
q->score.maths=maths;

english=p->score.english;
p->score.english=q->score.english;
q->score.english=english;

}
p=q;
j++;
}
p=head;
i++;
}while(i!=j);
}
return head;
}

st *arrangeall(st *head)//以总分排名
{
st *p,*q;
int t,i=1,j,chinese,maths,english;
char name[20];
p=head;
if(head==NULL)
printf("\t\tNoting to arrange\n");
else
{
do
{
j=1;
while(p->next!=NULL)
{
q=p->next;
if(p->score.chinese+p->score.maths+p->score.englishscore.chinese+q->score.maths+q->score.english)
{
t=p->num;
p->num=q->num;
q->num=t;

strcpy(name,p->name);
strcpy(p->name,q->name);
strcpy(q->name,name);

chinese=p->score.chinese;
p->score.chinese=q->score.chinese;
q->score.chinese=chinese;

maths=p->score.maths;
p->score.maths=q->score.maths;
q->score.maths=maths;

english=p->score.english;
p->score.english=q->score.english;
q->score.english=english;

}
p=q;
j++;
}
p=head;
i++;
}while(i!=j);
}
return head;
}

st *insect(st *head,st *t)//插入学生的信息
{
st *p,*q;
p=head;
if(head==NULL)
printf("\tThe list is empty\n");
else
{

if(t->num==p->num)
{
head=t;
t->next=p;
}
else
{
while(p->next!=NULL)
{
q=p->next;
if(p->num<=t->num&&q->num>=t->num)
{
t->next=q;
p->next=t;
}
p=q;
}
p->next=t;
}
}
return head;
}

void output(st *head)//输出所以学生的信息
{
st *p;
int i=0;
float sum1=0,sum2=0,sum3=0;
p=head;
if(head==NULL)
{
printf("\tThere is nothing \n");
return;
}
else
{
printf("\tnumber name chinese maths english allscores\n");
while(p)
{
printf("\t %d ",p->num);
printf(" %s ",p->name);
printf(" %d ",p->score.chinese);
printf(" %d ",p->score.maths);
printf(" %d ",p->score.english);
printf("%6d",p->score.chinese+p->score.maths+p->score.english);
printf("\n");
p=p->next;
}

p=head;
while(p)// avrege scores
{
sum1+= p->score.chinese;
sum2+=p->score.maths;
sum3+=p->score.english;
p=p->next;
i++;
}
printf("\tarvege %.2f %.2f %.2f %.2f \n",sum1/i,sum2/i,sum3/i,(sum1+sum2+sum3)/i);

}
system("pause");
}

st *dellect(st *head,st *d)//删除学生的信息
{
st *p,*q;
char c;
p=head;
if(!(strcmp(p->name,d->name)))
{
head=p->next;
free(p);
}
else
{
while((strcmp(p->name,d->name))&&p->next!=NULL)
{
q=p;
p=q->next;
}
if(!(strcmp(p->name,d->name)))
{
printf("do you want to delete %S ?(Y/N):",p->name);
scanf("%s",&c);

if(c=='y'||c=='Y')
{
q->next=p->next;
free(p);
}
}
else
printf("\tThere isn't this name\n");
}

return head;
}

void find(st *head,st *s)//查找学生的信息
{
st *p,*q;
p=head;
if(head==NULL)
printf("\tThe list is empty\n");
else
{

while((strcmp(p->name,s->name))!=0&&p->next!=NULL)
{

q=p;
p=q->next;
}

if((strcmp(p->name,s->name))==0)

{
printf("\t %d ",p->num);
printf(" %s ",p->name);
printf(" chinese=%d ",p->score.chinese);
printf(" maths=%d ",p->score.maths);
printf(" english=%d ",p->score.english);
printf("all=%d",p->score.chinese+p->score.maths+p->score.english);
printf("\n");
}
else
printf("\tThe name is missing\n");
}
system("pause");
}

void main()//主函数
{
st *head,*t,*s,*d;
int choice;

for(;;)
{
choice=menu();
switch(choice)
{

case 1:
head=create();
break;

case 2:
t=(st *)malloc(sizeof(st));
t->next=NULL;
printf("\t\tplease input the number of learning:");
scanf("%d",&t->num);

printf("\t\tplease input the name:");
scanf("%s",t->name);

printf("\t\tplease input the score of chinese:");
scanf("%d",&t->score.chinese);

printf("\t\tplease input the score of maths:");
scanf("%d",&t->score.maths);

printf("\t\tplease input the score of english:");
scanf("%d",&t->score.english);

head=insect(head,t);
break;

case 4:

d=(st *)malloc(sizeof(st));
d->next=NULL;
printf("\twhice student do you want to dellect?please input the name:");
scanf("%s",d->name);
head=dellect(head,d);
break;

case 3:

s=(st *)malloc(sizeof(st));
s->next=NULL;
printf("\twhice student do you want to look for?please input the name:");
scanf("%s",s->name);
find(head,s);
break;

case 5:
head=arrange(head);//number
break;

case 6:
output(head);
break;
case 7:
head=arrangeall(head);//score
break;

case 8:
printf("\t\tThank you,goodbye\n");
exit(0);
}
}

}

兄弟参照一下,希望能帮到你。
全部回答
#include "stdio.h" #include "stdlib.h" #include "string.h" int shoudsave=0; struct student { char num[10]; char name[20]; char sex[4]; int cgrade; int mgrade; int egrade; int totle; int ave; char neartime[10]; }; typedef struct node { struct student data; struct node *next; }node,*link; void menu() { printf("********************************************************************************"); printf("\t1登记学生资料\t\t\t\t\t2删除学生资料\n"); printf("\t3查询学生资料\t\t\t\t\t4修改学生资料\n"); printf("\t5保存学生资料\t\t\t\t\t0退出系统\n"); printf("********************************************************************************\n"); } void printstart() { printf("-----------------------------------------------------------------------\n"); } void wrong() { printf("\n=====>提示:输入错误!\n"); } void nofind() { printf("\n=====>提示:没有找到该学生!\n"); } void printc() { printf(" 学号\t 姓名 性别 英语成绩 数学成绩 c语言成绩 总分 平均分\n"); } void printe(node *p) { printf("%-12s%s\t%s\t%d\t%d\t%d\t %d\t %d\n",p->data.num,p->data.name,p->data.sex,p->data.egrade,p->data.mgrade,p->data.cgrade,p->data.totle,p->data.ave); } node* locate(link l,char findmess[],char nameornum[]) { node *r; if(strcmp(nameornum,"num")==0) { r=l->next; while(r!=null) { if(strcmp(r->data.num,findmess)==0) return r; r=r->next; } } else if(strcmp(nameornum,"name")==0) { r=l->next; while(r!=null) { if(strcmp(r->data.name,findmess)==0) return r; r=r->next; } } return 0; } void add(link l) { node *p,*r,*s; char num[10]; r=l; s=l->next; while(r->next!=null) r=r->next; while(1) { printf("请你输入学号(以'0'返回上一级菜单:)"); scanf("%s",num); if(strcmp(num,"0")==0) break; while(s) { if(strcmp(s->data.num,num)==0) { printf("=====>提示:学号为'%s'的学生已经存在,若要修改请你选择'4 修改'!\n",num); printstart(); printc(); printe(s); printstart(); printf("\n"); return; } s=s->next; } p=(node *)malloc(sizeof(node)); strcpy(p->data.num,num); printf("请你输入姓名:"); scanf("%s",p->data.name); getchar(); printf("请你输入性别:"); scanf("%s",p->data.sex); getchar(); printf("请你输入c语言成绩:"); scanf("%d",&p->data.cgrade); getchar(); printf("请你输入数学成绩:"); scanf("%d",&p->data.mgrade); getchar(); printf("请你输入英语成绩:"); scanf("%d",&p->data.egrade); getchar(); p->data.totle=p->data.egrade+p->data.cgrade+p->data.mgrade; p->data.ave=p->data.totle / 3; p->next=null; r->next=p; r=p; shoudsave=1; } } void qur(link l) { int sel; char findmess[20]; node *p; if(!l->next) { printf("\n=====>提示:没有资料可以查询!\n"); return; } printf("\n=====>1按学号查找\n=====>2按姓名查找\n"); scanf("%d",&sel); if(sel==1) { printf("请你输入要查找的学号:"); scanf("%s",findmess); p=locate(l,findmess,"num"); if(p) { printf("\t\t\t\t查找结果\n"); printstart(); printc(); printe(p); printstart(); } else nofind(); } else if(sel==2) { printf("请你输入要查找的姓名:"); scanf("%s",findmess); p=locate(l,findmess,"name"); if(p) { printf("\t\t\t\t查找结果\n"); printstart(); printc(); printe(p); printstart(); } else nofind(); } else wrong(); } void del(link l) { int sel; node *p,*r; char findmess[20]; if(!l->next) { printf("\n=====>提示:没有资料可以删除!\n"); return; } printf("\n=====>1按学号删除\n=====>2按姓名删除\n"); scanf("%d",&sel); if(sel==1) { printf("请你输入要删除的学号:"); scanf("%s",findmess); p=locate(l,findmess,"num"); if(p) { r=l; while(r->next!=p) r=r->next; r->next=p->next; free(p); printf("\n=====>提示:该学生已经成功删除!\n"); shoudsave=1; } else nofind(); } else if(sel==2) { printf("请你输入要删除的姓名:"); scanf("%s",findmess); p=locate(l,findmess,"name"); if(p) { r=l; while(r->next!=p) r=r->next; r->next=p->next; free(p); printf("\n=====>提示:该学生已经成功删除!\n"); shoudsave=1; } else nofind(); } else wrong(); } void modify(link l) { node *p; char findmess[20]; if(!l->next) { printf("\n=====>提示:没有资料可以修改!\n"); return; } printf("请你输入要修改的学生学号:"); scanf("%s",findmess); p=locate(l,findmess,"num"); if(p) { printf("请你输入新学号(原来是%s):",p->data.num); scanf("%s",p->data.num); printf("请你输入新姓名(原来是%s):",p->data.name); scanf("%s",p->data.name); getchar(); printf("请你输入新性别(原来是%s):",p->data.sex); scanf("%s",p->data.sex); printf("请你输入新的c语言成绩(原来是%d分):",p->data.cgrade); scanf("%d",&p->data.cgrade); getchar(); printf("请你输入新的数学成绩(原来是%d分):",p->data.mgrade); scanf("%d",&p->data.mgrade); getchar(); printf("请你输入新的英语成绩(原来是%d分):",p->data.egrade); scanf("%d",&p->data.egrade); p->data.totle=p->data.egrade+p->data.cgrade+p->data.mgrade; p->data.ave=p->data.totle/3; printf("\n=====>提示:资料修改成功!\n"); shoudsave=1; } else nofind(); } void disp(link l) { int count=0; node *p; p=l->next; if(!p) { printf("\n=====>提示:没有资料可以显示!\n"); return; } printf("\t\t\t\t显示结果\n"); printstart(); printc(); printf("\n"); while(p) { 花範羔既薏焕割唯公沥 printe(p); p=p->next; } printstart(); printf("\n"); } void tongji(link l) { node *pm,*pe,*pc,*pt,*pa; node *r=l->next; if(!r) { printf("\n=====>提示:没有资料可以统计!\n"); return ; } pm=pe=pc=pt=pa=r; while(r!=null) { if(r->data.cgrade>=pc->data.cgrade) pc=r; if(r->data.mgrade>=pm->data.mgrade) pm=r; if(r->data.egrade>=pe->data.egrade) pe=r; if(r->data.totle>=pt->data.totle) pt=r; if(r->data.ave>=pa->data.ave) pa=r; r=r->next; } printf("------------------------------统计结果--------------------------------\n"); printf("总分最高者:\t%s %d分\n",pt->data.name,pt->data.totle); printf("平均分最高者:\t%s %d分\n",pa->data.name,pa->data.ave); printf("英语最高者:\t%s %d分\n",pe->data.name,pe->data.egrade); printf("数学最高者:\t%s %d分\n",pm->data.name,pm->data.mgrade); printf("c语言最高者:\t%s %d分\n",pc->data.name,pc->data.cgrade); printstart(); } void sort(link l) { link ll; node *p,*rr,*s; ll=(link)malloc(sizeof(node)); ll->next=null; if(l->next==null) { printf("\n=====>提示:没有资料可以排序!\n"); return ; } p=l->next; while(p) { s=(node*)malloc(sizeof(node)); s->data=p->data; s->next=null; rr=ll; while(rr->next!=null && rr->next->data.totle>=p->data.totle) rr=rr->next; if(rr->next==null) rr->next=s; else { s->next=rr->next; rr->next=s; } p=p->next; } free(l); l->next=ll->next; printf("\n=====>提示:排序已经完成!\n"); } void save(link l) { file* fp; node *p; int flag=1,count=0; fp=fopen("c:\\student","wb"); if(fp==null) { printf("\n=====>提示:重新打开文件时发生错误!\n"); exit(1); } p=l->next; while(p) { if(fwrite(p,sizeof(node),1,fp)==1) { p=p->next; count++; } else { flag=0; break; } } if(flag) { printf("\n=====>提示:文件保存成功.(有%d条记录已经保存.)\n",count); shoudsave=0; } fclose(fp); } void main() { link l; file *fp; int sel; char ch; char jian; int count=0; node *p,*r; printf("\t\t\t\t学生成绩管理系统\n\t\t\t\t-------西京学院本科部机制0502 彭琛(41号)\n"); l=(node*)malloc(sizeof(node)); l->next=null; r=l; fp=fopen("c:\\student","rb"); if(fp==null) { printf("\n=====>提示:文件还不存在,是否创建?(y/n)\n"); scanf("%c",&jian); if(jian=='y'||jian=='y') fp=fopen("c:\\student","wb"); else exit(0); } printf("\n=====>提示:文件已经打开,正在导入记录......\n"); while(!feof(fp)) { p=(node*)malloc(sizeof(node)); if(fread(p,sizeof(node),1,fp)) { p->next=null; r->next=p; r=p; count++; } } fclose(fp); printf("\n=====>提示:记录导入完毕,共导入%d条记录.\n",count); while(1) { menu(); printf("请你选择操作:"); scanf("%d",&sel); if(sel==0) { if(shoudsave==1) { getchar(); printf("\n=====>提示:资料已经改动,是否将改动保存到文件中(y/n)?\n"); scanf("%c",&ch); if(ch=='y'||ch=='y') save(l); } printf("\n=====>提示:你已经退出系统,再见!\n"); break; } switch(sel) { case 1:add(l);break; case 2:del(l);break; case 3:qur(l);break; case 4:modify(l);break; case 5:save(l);break; case 9:printf("\t\t\t==========帮助信息==========\n");break; default: wrong();getchar();break; } } }
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
泰拉瑞亚寒冰魔杖好不好
2017年江苏省泰兴市公租房公示名单四月份申请
worldchic的衣服咋样?是哪里的牌子?
婚纱拖地1米,头纱适合选多长的?
辨气血证候是A.某一脏腑经络的气机阻滞,运行
全球邮政特快专递(黄沙河镇宣传文化站西南)地
60v电动车电池是60v20ah的 可以用24v20ah的锂
中国邮政速递物流公司桂林市分公司全州县经营
【厚积薄发的例子】有哪些名人是厚积薄发的?
求大量gl宠溺文,只要gl的。谢谢
come into effect有奏效的意思吗
千年1刀法门武设计数值
莱西山会什么时间开始
全球气候变暖可能带来的影响A. 大气中二氧化
请问这种灯在哪里买的? 有人卖的吗 我想要送
推荐资讯
地球人到底是三维生物还是二维生物?
小青龙头里会不会有白色像口香糖一样的东西
万豪度假酒店-洗手间地址在哪,我要去那里办
心折是什么意思
iphone7铃声 信息提示声能分开设置吗
下列除去杂质的方法中,正确的是BCA. 用氢氧
梦见我爸追打只鸡
德工五金地址在什么地方,我要处理点事
玉米体细胞中有10对染色体,玉米在减数分裂过
兰花瓷罐太平猴魁茶叶多少钱一罐
极地酒吧地址好找么,我有些事要过去
为什么超导体一定是抗磁性物质?
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?