C语言链表在统计班级成绩的应用.docx

上传人:b****1 文档编号:15017961 上传时间:2023-06-29 格式:DOCX 页数:12 大小:18.77KB
下载 相关 举报
C语言链表在统计班级成绩的应用.docx_第1页
第1页 / 共12页
C语言链表在统计班级成绩的应用.docx_第2页
第2页 / 共12页
C语言链表在统计班级成绩的应用.docx_第3页
第3页 / 共12页
C语言链表在统计班级成绩的应用.docx_第4页
第4页 / 共12页
C语言链表在统计班级成绩的应用.docx_第5页
第5页 / 共12页
C语言链表在统计班级成绩的应用.docx_第6页
第6页 / 共12页
C语言链表在统计班级成绩的应用.docx_第7页
第7页 / 共12页
C语言链表在统计班级成绩的应用.docx_第8页
第8页 / 共12页
C语言链表在统计班级成绩的应用.docx_第9页
第9页 / 共12页
C语言链表在统计班级成绩的应用.docx_第10页
第10页 / 共12页
C语言链表在统计班级成绩的应用.docx_第11页
第11页 / 共12页
C语言链表在统计班级成绩的应用.docx_第12页
第12页 / 共12页
亲,该文档总共12页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

C语言链表在统计班级成绩的应用.docx

《C语言链表在统计班级成绩的应用.docx》由会员分享,可在线阅读,更多相关《C语言链表在统计班级成绩的应用.docx(12页珍藏版)》请在冰点文库上搜索。

C语言链表在统计班级成绩的应用.docx

C语言链表在统计班级成绩的应用

【问题描述】

学期考试结束,统计某班每个人的平均成绩,每门课的平均成绩,并按个人平均成绩从高到低的顺序输出成绩,输出不及格人。

输入、输出格式自定。

【实现提示】

考试课程有:

高等数学、物理、外语、C语言4门课程。

录入所有同学的成绩,对数据进行处理,输岀所要求的容,程序的功能主要包括以下几个方面:

1输入成绩

2修改记录

3删除记录

4输出成绩并按平均成绩排序,并标记平均分不及格的学生。

5界面提供上述功能选择。

代码#inelude

#include

#inelude

intmenu=O;

typedefstructCLASS{

charname[15];

intmaths;

intphysics;

intenglish;

intc_language;structCLASS*next;

}linkNode;

structAVERAGE{

charname[15];

floatper_average;structAVERAGE*aver_next;

};

typedefstructAVERAGE*Average;

typedeflinkNode*Class;

Averagecreate_average_list(Classinfo」ist_head);

Classadd_student_info(Classhead);

Classdelete_student_info(Classhead,char*stu_name);voidmodify_student_info(Classhead,char*stu_name);voidsort_average(Average);

voidprint_student_info(Classhead);

voidprint_average_score(Averagehead);

voidcaculate_class_average(Classinfo_list_head);

voidmain_menu(void);

intmain(void)

{

linkNode*link_list_head=NULL;

structAVERAGE*pAver_head=NULL;

char*student_name;

while

(1)

{

switch(menu){

case0:

{

main_menu();

}break;

case1:

{

link_list_head=add_student_info(link_list_head);

menu=0;

}break;

case2:

{

if(link_list_head!

=NULL)

{

printf("Ifyouwanttomodifystudent's

information,pleaseinputthename:

");

scanf("%s",student_name);

}

modify_student_info(link_list_head,student_name);

menu=0;

}break;

case3:

{

if(link_list_head!

=NULL)

{

printf("Ifyouwanttodeletestudent's

information,pleaseinputthename:

");

scanf("%s",student_name);

link_list_head=delete_student_info(link_list_head,student_name);

menu=0;

}break;

case4:

{

print_student_info(link_list_head);

menu=0;

}break;

case5:

{

pAver_head=create_average」ist(link_list_head);if(pAver_head==NULL)

{

menu=0;

break;

}

sort_average(pAver_head);

print_average_score(pAver_head);caculate_class_average(link_list_head);menu=0;

}break;

default:

{

menu=0;

}break;

}

Averagecreate_average_list(Classinfo_list_head)

{

Averageaver_list_head,aNode,newNode;

ClasscNode;

cNode=info_list_head->next;

if(info_list_head==NULL)

{

printf("Thelinklistofstudent'sinformationisnotexist!

\n");returnNULL;

}

aNode=aver_list_head=(Average)malloc(sizeof(structAVERAGE));aNode->aver_next=NULL;

while(cNode!

=NULL)

{

newNode=(Average)malloc(sizeof(structAVERAGE));

strcpy(newNode->name,cNode->name);

newNode->per_average=(float)(((cNode->maths)+(cNode->physics)+(cNode->english)+(cNode->c_language))/4.0);

aNode->aver_next=newNode;

newNode->aver_next=NULL;

aNode=newNode;cNode=cNode->next;

}

returnaver_list_head;

Classadd_student_info(Classhead){

linkNode*pTail=NULL,*pNew=NULL;intcnt;

intlen;

if(head==NULL)

{

pTail=head=(Class)malloc(sizeof(structCLASS));pTail->next=NULL;

}

else{

pTail=(Class)malloc(sizeof(structCLASS));pTail=head;

}

printf("pleaseinputstudent'snumberofpeople:

");scanf("%d",&len);

while(pTail!

=NULL)

{

if(pTail->next==NULL)

{

for(cnt=O;cnt

{

pNew=(linkNode*)malloc(sizeof(structCLASS));

printf("pleaseinputstudent'snameandescoreincorrectorderby:

\n");

printf("namemathphysicalEnglishC_language\n");

scanf("%s%d%d%d%d",pNew->name,&pNew->maths,

&pNew->physics,&pNew->english,&pNew->c_language);pNew->next=NULL;

pTail->next=pNew;

pTail=pNew;

}

printf("addstudent'sinformationsuccessfully!

\n");

returnhead;

}

pTail=pTail->next;

}

Classdelete_student_info(Classhead,char*stu_name)

{

ClasspNode=NULL,temp=NULL;

pNode=head->next;

if(head==NULL)

{

printf("Thelinklistofstudent'sinformationisnotexist!

\n");returnNULL;

}

else

{

while(pNode!

=NULL)

{

if(strcmp(pNode->name,stu_name)==0)

{

if(pNode==head->next)

if(pNode->next==NULL)

{

information

head->next=pNode->next;

printf("deletestudent's

returnNULL;

}

head->next=pNode->next;

printf("deletestudent'sinformationsuccessfully!

'n");returnhead;

elseif(pNode->next==NULL)

temp->next=NULL;

printf("deletestudent'sinformationsuccessfully!

'n");returnhead;

else

temp->next=pNode->next;

printf("deletestudent'sinformationsuccessfully!

'n");returnhead;

}

elseif(pNode->next==NULL)

{

byyourinputit

printf("Systemnotfoundstudent'sinformationvoidmodify_student_info(Classhead,char*stu_name)

{

ClasscNode;

cNode=head->next;

if(head==NULL)

{

printf("Thelinklistofstudent'sinformationisnotexist!

\n");return;

}

while(cNode!

=NULL)

{

if(strcmp(cNode->name,stu_name)==0)

{

printf("pleaseinputyouneedtomodifystudent'sinformationincorrectorderby:

\n”);

printf("mathphysicalEnglishC_language\n");

scanf("%d%d%d%d",&cNode->maths,

&cNode->physics,&cNode->english,&cNode->c_language);

printf("modifystudent'sinformationsuccessfully!

\n");break;

}

elseif(cNode->next==NULL)

{

printf("Systemnotfoundstudent'sinformationbyyourinputit

just\n”);

}cNode=cNode->next;

}

voidsort_average(Averageaver_list_head){

AverageaNode1,aNode2;

charname_temp[10];

floataver_temp;

intcnt=0,num=0;

aNode仁aver_list_head->aver_next;

if(aver_list_head==NULL)

{

printf("Thelinklistofscoreaverageisnotexist!

\n");return;

}

while(aNode1!

=NULL)

{

aNode2=aNode1;

while(aNode2!

=NULL)

{

aNode2=aNode2->aver_next;

cnt++;

}

aNode2=aNode1;

for(num=0;num

{

aNode2=aNode2->aver_next;if((aNode1->per_average)<(aNode2->per_average))

{

strcpy(name_temp,aNode1->name);aver_temp=aNode1->per_average;strcpy(aNode1->name,aNode2->name);

aNode1->per_average=aNode2->per_average;strcpy(aNode2->name,name_temp);

aNode2->per_average=aver_temp;

}

cnt=0;

aNode1=aNode1->aver_next;voidcaculate_class_average(Classinfo_list_head)

{

ClasscNode;

intmaths_sum=O,physics_sum=O,english_sum=O,c_language_sum=O;

floattotal_people;

cNode=info_list_head->next;

if(info_list_head==NULL)

{

printf("Thelinklistofstudent'sinformationisnotexist!

\n");return;

}

while(cNode!

=NULL)

{

maths_sum=maths_sum+cNode->maths;

physics_sum=physics_sum+cNode->physics;

english_sum=english_sum+cNode->english;

c_language_sum=c_language_sum+cNode->c_language;

cNode=cNode->next;

total_people++;

}

printf("maths_average=%.2fphysics_average=%.2fenglish_average=%.2f

c_language_average=%.2f\n",

(float)(maths_sum/total_people),(float)(physics_sum/total_people),(float)(english_sum/total_

people),

(float)(c_language_sum/total_people));

voidprint_student_info(Classhead)

{

linkNode*pNode=head->next;

if(head==NULL)

{

printf("Thelinklistofstudent'sinformationisnotexist!

\n");return;

}while(pNode!

=NULL)

{

printf("%s%d%d%d%d\n",pNode->name,pNode->maths,pNode->physics,pNode->english,pNode->c_language);

pNode=pNode->next;

}

voidprint_average_score(Averagehead)

{

AveragepNode=head->aver_next;

if(head==NULL)

{

printf("Thelinklistofstudent'sinformationisnotexist!

\n");

return;

}

while(pNode!

=NULL)

{

printf("%s%.2f',pNode->name,pNode->per_average);

if((pNode->per_average)<60.0)

printf("fail\n");

elseprintf("\n");

pNode=pNode->aver_next;

voidmain_menu(void)

{

\n");

\n");

printf(printf(

printf("Mainmenudirection:

\n”);

printf("0mainmenuinterface\n");

printf("1enterstudent'sinformation\n");

printf("2modifystudent'sinformation\n");

printf("3deletestudent'sinformation\n");

printf("4printstudent'sscoreinformation\n");

printf("5printeveryone'saveragescoreandclass'saveragescore\n");

printf("*******************************************************************************

printf("*******************************************************************************

printf("pleaseinputyourchoice:

");

scanf("%d",&menu);printf("\n");

多年的财务工作实践给了我巨大的舞台来提高自已观察问题、分析问题、处理问题的能力,使我的业务水平和工作能力得到了长足的进步,但我也清醒地认识到,自己的工

作中还存在许多不足之处,今后,我将更加注意学习,努力克服工作中遇到的困难,进一步提高职业道德修养,提高业务学识和组织管理水平,为全县交通事业的发展作出新的贡献。

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 自然科学

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2