C语言链表在统计班级成绩的应用.doc
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 语言 统计 班级 成绩 应用
- 资源描述:
-
【问题描述】 学期考试结束,统计某班每个人的平均成绩,每门课的平均成绩,并按个人平均成绩从高到低的顺序输出成绩,输出不及格人名单。输入、输出格式自定。 【实现提示】 考试课程有:高等数学、物理、外语、C语言4门课程。 录入所有同学的成绩,对数据进行处理,输出所要求的内容,程序的功能主要包括以下几个方面: ① 输入成绩 ② 修改记录 ③ 删除记录 ④ 输出成绩并按平均成绩排序,并标记平均分不及格的学生。 ⑤ 界面提供上述功能选择。 代码#include <stdio.h> #include <stdlib.h> #include <string.h> int menu=0; typedef struct CLASS{ char name[15]; int maths; int physics; int english; int c_language; struct CLASS* next; }linkNode; struct AVERAGE{ char name[15]; float per_average; struct AVERAGE* aver_next; }; typedef struct AVERAGE* Average; typedef linkNode* Class; Average create_average_list(Class info_list_head); Class add_student_info(Class head); Class delete_student_info(Class head,char *stu_name); void modify_student_info(Class head,char *stu_name); void sort_average(Average); void print_student_info(Class head); void print_average_score(Average head); void caculate_class_average(Class info_list_head); void main_menu(void); int main(void) { linkNode * link_list_head=NULL; struct AVERAGE *pAver_head=NULL; char *student_name; while(1) { switch(menu){ case 0:{ main_menu(); }break; case 1:{ link_list_head = add_student_info(link_list_head); menu =0; }break; case 2:{ if(link_list_head!=NULL) { printf("If you want to modify student's information,please input the name: "); scanf("%s",student_name); } modify_student_info(link_list_head,student_name); menu =0; }break; case 3:{ if(link_list_head!=NULL) { printf("If you want to delete student's information,please input the name: "); scanf("%s",student_name); } link_list_head=delete_student_info(link_list_head,student_name); menu =0; }break; case 4:{ print_student_info(link_list_head); menu =0; }break; case 5:{ pAver_head=create_average_list(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; } } } Average create_average_list(Class info_list_head) { Average aver_list_head,aNode,newNode; Class cNode; cNode=info_list_head->next; if(info_list_head==NULL) { printf("The link list of student's information is not exist!\n"); return NULL; } aNode=aver_list_head=(Average)malloc(sizeof(struct AVERAGE)); aNode->aver_next=NULL; while(cNode!=NULL) { newNode=(Average)malloc(sizeof(struct AVERAGE)); 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; } return aver_list_head; } Class add_student_info(Class head) { linkNode *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; } printf("please input student's number of people: "); scanf("%d",&len); while( pTail !=NULL) { if(pTail->next==NULL) { for(cnt=0;cnt<len;cnt++) { pNew = (linkNode *)malloc(sizeof(struct CLASS)); printf("please input student's name ande score in correct order by :\n"); printf("name math physical English C_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("add student's information successfully!\n"); return head; } pTail =pTail ->next; } } Class delete_student_info(Class head,char *stu_name) { Class pNode=NULL,temp=NULL; pNode = head->next; if( head==NULL) { printf("The link list of student's information is not exist!\n"); return NULL; } else { while(pNode!=NULL) { if(strcmp(pNode->name,stu_name)==0) { if(pNode==head->next) { if(pNode->next==NULL) { head->next=pNode->next; printf("delete student's information successfully!\n"); return NULL; } head->next=pNode->next; printf("delete student's information successfully!\n"); return head; } else if(pNode->next==NULL) { temp->next=NULL; printf("delete student's information successfully!\n"); return head; } else { temp->next=pNode->next; printf("delete student's information successfully!\n"); return head; } } else if(pNode->next==NULL) { printf("System not found student's information by your input it just\n"); return head; } temp=pNode; pNode= pNode->next; } } } void modify_student_info(Class head,char *stu_name) { Class cNode; cNode=head->next; if(head==NULL) { printf("The link list of student's information is not exist!\n"); return; } while(cNode!=NULL) { if(strcmp(cNode->name,stu_name)==0) { printf("please input you need to modify student's information in correct order by :\n"); printf("math physical English C_language\n"); scanf("%d %d %d %d",& cNode->maths, & cNode->physics,&cNode->english,&cNode->c_language); printf("modify student's information successfully!\n"); break; } else if(cNode->next==NULL) { printf("System not found student's information by your input it just\n"); } cNode=cNode->next; } } void sort_average(Average aver_list_head) { Average aNode1,aNode2; char name_temp[10]; float aver_temp; int cnt=0,num=0; aNode1=aver_list_head->aver_next; if(aver_list_head==NULL) { printf("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;num<cnt;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; } } void caculate_class_average(Class info_list_head) { Class cNode; int maths_sum=0,physics_sum=0,english_sum=0,c_language_sum=0; float total_people; cNode=info_list_head->next; if(info_list_head==NULL) { printf("The link list of student's information is not exist!\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=%.2f physics_average=%.2f english_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)); } void print_student_info(Class head) { linkNode *pNode = head->next; if(head==NULL) { printf("The link list of student's information is not exist!\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; } } void print_average_score(Average head) { Average pNode = head->aver_next; if(head==NULL) { printf("The link list of student's information is not exist!\n"); return; } while(pNode!=NULL) { printf("%s %.2f",pNode->name,pNode->per_average); if((pNode->per_average)<60.0) printf(" fail \n"); else printf("\n"); pNode = pNode->aver_next; } } void main_menu(void) { printf("******************************************************************************** \n"); printf("******************************************************************************** \n"); printf("Main menu direction: \n"); printf("0 main menu interface\n"); printf("1 enter student's information\n"); printf("2 modify student's information\n"); printf("3 delete student's information\n"); printf("4 print student's score information\n"); printf("5 print everyone's average score and class's average score\n"); printf("********************************************************************************\n"); printf("********************************************************************************\n"); printf( "please input your choice:"); scanf("%d",&menu); printf( "\n"); }展开阅读全文

咨信网声明:本文档由用户上传并分享,仅供学习交流、研究之用,未经授权,严禁复制、发行、汇编、翻译或网络传播等,侵权必究。
咨信网小贴示:
1、浏览或下载可查看了解,请点击【咨信网告知】。
2、下载文件中如有侵权或不适当内容,将立即纠正。
3、如果因为网速或其他原因下载失败请重新下载,重复下载[60天内]不扣币。
4、开具发票登录电脑端申请,请点击【索取发票】。
咨信网客服组:【微信客服】
1、浏览或下载可查看了解,请点击【咨信网告知】。
2、下载文件中如有侵权或不适当内容,将立即纠正。
3、如果因为网速或其他原因下载失败请重新下载,重复下载[60天内]不扣币。
4、开具发票登录电脑端申请,请点击【索取发票】。
咨信网客服组:【微信客服】


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
















自信AI助手














微信客服
客服QQ
发送邮件
意见反馈



链接地址:https://www.zixin.com.cn/doc/10820130.html