1、C语言链表在统计班级成绩的应用【问题描述】学期考试结束,统计某班每个人的平均成绩,每门课的平均成绩,并按个人平均成绩从高到低 的顺序输出成绩,输出不及格人。输入、输出格式自定。【实现提示】考试课程有:高等数学、物理、外语、 C语言4门课程。录入所有同学的成绩,对数据进行处理,输岀所要求的容,程序的功能主要包括以下几个方面:1输入成绩2修改记录3删除记录4输出成绩并按平均成绩排序,并标记平均分不及格的学生。5界面提供上述功能选择。代码 #in elude #i nclude #in elude int menu=O;typedef struct CLASSchar n ame15;int mat
2、hs;int physics;int en glish;int c_la nguage; struct CLASS* next;li nkNode;struct AVERAGEchar n ame15;float per_average; struct AVERAGE* aver_ next;typedef struct AVERAGE* Average;typedef lin kNode* Class;Average create_average_list(Class infoist_head);Class add_stude nt_in fo(Class head);Class delet
3、e_stude nt_in fo(Class head,char *stu_ name); void modify_stude nt_in fo(Class head,char *stu _n ame); void sort_average(Average);void prin t_stude nt_in fo(Class head);void prin t_average_score(Average head);void caculate_class_average(Class in fo_list_head);void main_menu (void);int main( void)lin
4、 kNode * lin k_list_head=NULL;struct AVERAGE *pAver_head=NULL;char *stude nt_n ame;while(1)switch(me nu)case 0:main_me nu();break;case 1:lin k_list_head = add_stude nt_in fo(l in k_list_head);menu =0;break;case 2:if(li nk_list_head!=NULL)prin tf(If you want to modify stude ntsin formati on, please i
5、n put the n ame:);sca nf(%s,stude nt_n ame);modify_stude nt_in fo(l in k_list_head,stude nt_n ame);menu =0;break;case 3:if(li nk_list_head!=NULL)prin tf(If you want to delete stude ntsin formati on, please in put the n ame:);sca nf(%s,stude nt_n ame);lin k_list_head=delete_stude nt_i nfo(li nk_list_
6、head,stude nt_n ame);menu =0;break;case 4:prin t_stude nt_in fo(l in k_list_head);menu =0;break;case 5:pAver_head=create_averageist(li nk_list_head); if(pAver_head=NULL)menu =0;break;sort_average(pAver_head);prin t_average_score(pAver_head); caculate_class_average(l in k_list_head); menu =0;break;de
7、fault:menu =0;break;Average create_average_list(Class in fo_list_head)Average aver_list_head,aNode ,n ewNode;Class cNode;cNode=in fo_list_head-n ext;if(i nfo_list_head=NULL)printf(The link list of students information is not exist!n); return NULL;aNode=aver_list_head=(Average)malloc(sizeof(struct AV
8、ERAGE); aNode-aver_ next=NULL;while(cNode!=NULL)newNode=(Average)malloc(sizeof(struct AVERAGE);strcpy (n ewNode-n ame,cNode-n ame);n ewNode-per_average=(float)(cNode-maths)+(cNode-physics)+ (cNode-e nglish)+(cNode-c_la nguage)/4.0);aNode-aver_ next=n ewNode;n ewNode-aver_ next=NULL;aNode = n ewNode;
9、 cNode=cNode-n ext;return aver_list_head;Class add_stude nt_in fo(Class head) lin kNode *pTail =NULL,*pNew=NULL; int cnt;int len;if(head=NULL)pTail =head = (Class)malloc(sizeof(struct CLASS); pTail- next=NULL;else pTail = (Class)malloc(sizeof(struct CLASS); pTail =head;prin tf(please in put stude nt
10、s nu mber of people:); scan f(%d, &len);while( pTail !=NULL)if(pTail- next=NULL)for(cn t=O;c nt name,& pNew-maths,& pNew-physics,& pNew-e nglish,& pNew -c_la nguage); pNew- next=NULL;pTail-n ext=pNew;pTail = pNew;prin tf(add stude nts in formatio n successfully!n);retur n head;pTail =pTail -n ext;Cl
11、ass delete_stude nt_in fo(Class head,char *stu_ name)Class pNode=NULL,temp=NULL;pNode = head-n ext;if( head=NULL)printf(The link list of students information is not exist!n); return NULL;elsewhile(pNode!=NULL)if(strcmp(pNode-n ame,stu_ name)=0)if(pNode=head-n ext)if(pNode- next=NULL)in formatio nhea
12、d-n ext=pNode-n ext;prin tf(delete stude ntsreturn NULL;head-n ext=pNode-n ext;prin tf(delete stude nts in formati on successfully! n); retur n head;else if(pNode- next=NULL)temp-n ext=NULL;prin tf(delete stude nts in formati on successfully! n); retur n head;elsetemp-n ext=pNode-n ext;prin tf(delet
13、e stude nts in formati on successfully! n); retur n head;else if(pNode- next=NULL)by your in put itprin tf(System not found stude nts in formati on void modify_stude nt_in fo(Class head,char *stu_ name)Class cNode;cNode=head-n ext;if(head=NULL)prin tf(The link list of stude nts in formatio n is not
14、exist!n); return;while(cNode!=NULL)if(strcmp(cNode-n ame,stu_ name)=0)prin tf(please in put you n eed to modify stude nts in formati on in correct order by :n ”);prin tf(math physical En glish C_la nguagen);sca nf(%d %d %d %d,& cNode-maths,& cNode-physics,& cNode-e nglish, &cNode-c_la nguage);prin t
15、f(modify stude nts in formati on successfully!n); break;else if(cNode- next=NULL)prin tf(System not found stude nts in formati on by your in put itjustn ”); cNode=cNode-n ext;void sort_average(Average aver_list_head) Average aNode1,aNode2;char n ame_temp10;float aver_temp;int cnt=0,num=0;aNode仁aver_
16、list_head-aver_ next;if(aver_list_head=NULL)prin tf(The link list of score average is not exist!n); return;while(aNode1!=NULL)aNode2=aNode1;while(aNode2!=NULL)aNode2=aNode2-aver_ next;cnt+;aNode2=aNode1;for(num=0;numaver_ next; if(aNode1-per_average)per_average )strcpy (n ame_temp ,aNode1- n ame); a
17、ver_temp = aNode1-per_average; strcpy(aNode1- n ame ,aNode2-n ame);aNode1-per_average = aNode2-per_average; strcpy(aNode2-n ame , n ame_temp);aNode2-per_average = aver_temp;cnt=0;aNode1=aNode1-aver_ next; void caculate_class_average(Class in fo_list_head)Class cNode;int maths_sum=O,physics_sum=O,e n
18、glish_sum=O,c_la nguage_sum=O;float total_people;cNode=in fo_list_head-n ext;if(i nfo_list_head=NULL)prin tf(The link list of stude nts in formatio n is not exist!n); return;while(cNode!=NULL)maths_sum=maths_sum+cNode-maths;physics_sum=physics_sum+cNode-physics;en glish_sum=e nglish_sum+cNode-e ngli
19、sh;c_la nguage_sum=c_la nguage_sum+cNode-c_la nguage;cNode=cNode-n ext;total_people+;prin tf(maths_average=%.2f physics_average=%.2f en glish_average=%.2fc_la nguage_average=%.2f n,(float)(maths_sum/total_people),(float)(physics_sum/total_people),(float)( en glish_sum/total_people),(float)(c_la ngua
20、ge_sum/total_people);void prin t_stude nt_in fo(Class head)lin kNode *pNode = head-n ext;if(head=NULL)printf(The link list of students information is not exist!n); return; while(pNode!=NULL)prin tf(%s %d %d %d %dn,pNode-n ame,pNode-maths,pNode-physics, pNode-e nglish,pNode-c_la nguage);pNode = pNode
21、-n ext;void prin t_average_score(Average head)Average pNode = head-aver_ next;if(head=NULL)printf(The link list of students information is not exist!n);return;while(pNode!=NULL)prin tf(%s %.2f,pNode-n ame,pNode-per_average);if(pNode-per_average)aver_ next;void main_me nu (void)n);n);printf( printf(p
22、rin tf(Ma in menu direct ion: n ”);prin tf(0 mai n menu in terfacen);prin tf(1 en ter stude nts in formati onn);prin tf(2 modify stude nts in formati onn);prin tf(3 delete stude nts in formati onn);prin tf(4 print stude nts score in formati onn);prin tf(5 print every on es average score and classs average scoren);printf( *printf( *prin tf( please in put your choice:);scan f(%d, &menu); prin tf( n);多年的财务工作实践给了我巨大的舞台来提高自已观察问题、分析问题、处理问题的能力,使我的业务水平和工作能力得到了长足的进步,但我也清醒地认识到,自己的工作中还存在许多不足之处,今后,我将更加注意学习,努力克服工作中遇到的困难,进一步提高职业道德修养,提高业务学识和组织管理水平,为全县交通事业的发展作出新的贡献。
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2