C语言实验报告 学生成绩管理系统结构体数组编程 题目及答案_第1页
C语言实验报告 学生成绩管理系统结构体数组编程 题目及答案_第2页
C语言实验报告 学生成绩管理系统结构体数组编程 题目及答案_第3页
C语言实验报告 学生成绩管理系统结构体数组编程 题目及答案_第4页
C语言实验报告 学生成绩管理系统结构体数组编程 题目及答案_第5页
已阅读5页,还剩8页未读, 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

实验报告七六学时课程C语言程序设计实验项目综合应用实验成绩专业班级学号批阅日期姓名实验日期2022年5月指导教师杨绪华一【实验目的】以C语言程序设计语言为基础,完成具有一定难度的综合程序设计。通过编写、调试、运行程序,进一步掌握C语言程序设计的基本方法和编程技巧,巩固所学知识,提高分析问题和解决问题的能力。二【实验内容】某班有最多不超过30人(具体人数由键盘输入)参加期末考试,最多不超过6门(具体门数由键盘输入)。定义结构体类型描述学生信息,每个学生信息包括:学号、姓名、多门课的成绩、总成绩和平均成绩。用结构体数组作为函数参数,编程实现如下菜单驱动的学生成绩管理系统。录入每个学生的学号、姓名和各科考试成绩。计算每门课程的总分和平均分。计算每个学生的总分和平均分。按每个学生的总分由高到低排出名次表。按学号由小到大排出成绩表。按姓名的字典顺序排出成绩表。按学号查询学生排名极其考试成绩。按姓名查询学生排名极其考试成绩。按优秀(90~100)、良好(80~90)、中等(70~80)、及格(60~70)、不及格(0~59)5个类别,对每门课程分别统计每个类别的人数以及所占的百分比。输出每个学生的学号、姓名、各科考试成绩以及每门课程的总分和平均分。要求程序运行后先显示如下菜单,并提示用户输入选项:InputrecordCaculatetotalandaveragescoreofeverycourseCaculatetotalandaveragescoreofeverystudentSortindescendingorderbytotalscoreofeverystudentSortinascendingorderbynumberSortindictionaryorderbynameSearchbynumberSearchbynameStatisticanalysisforeverycourseListrecordExitPleaseinputyourchoice:三【题目分析】该题主要考查数组、指针、结构体、函数调用相关操作,以及C语言算法的掌握,所以完成该题要求具有较强的程序设计能力,如何调试程序也非常关键,通过这个程序可以学到以前调试短程序没有的经验。系统中的每一功能几乎都对应一个子程序。四【实验结果】#include<stdio.h>#defineN10intnum;typedefstructstu//定义一个结构体{ intNo; charname[20]; intscore[3]; intsum;}stud;voidinput(stud*stu,intn)//输入n个学生信息{ inti,j; for(i=0;i<n;i++) { (stu+i)->sum=0; printf("学号:"); scanf("%d",&(stu+i)->No); getchar(); printf("姓名:"); gets((stu+i)->name); printf("3门成绩:"); for(j=0;j<3;j++) { scanf("%d",&(stu+i)->score[j]);(stu+i)->sum+=(stu+i)->score[j]; } }}voidinsert(stud*stu,studnew_stu)//添加一个学生信息{ stu[num]=new_stu;}intlocate(stud*stu,intn,intNo)//查找一个学生信息{ inti; for(i=0;i<n;i++) if((stu+i)->No==No)break; if(i==n)return-1; elsereturni;}intdelet(stud*stu,intn,intdel_No)//删除一个学生{ inti; for(i=0;i<n;i++) if((stu+i)->No==del_No)break; if(i==n)return0; else for(;i<n-1;i++)*(stu+i)=*(stu+i+1); return1;}voidcount(stud*stu,intn)//求每个学生总分{ inti,j; for(i=0;i<n;i++) { stu[i].sum=0; for(j=0;j<3;j++)stu[i].sum=stu[i].sum+stu[i].score[j]; }}voidsort(stud*stu,intn)//对每个学生总分排序{ inti,j; studt; for(i=0;i<n-1;i++) { for(j=i+1;j<n;j++) if(stu[i].sum<stu[j].sum) {t=stu[i];stu[i]=stu[j];stu[j]=t;} }}voidoutput(stud*stu,intn)//输出学生的成绩{ inti; printf("学号\t姓名\t成绩一\t成绩二\t成绩三\t总分\n"); for(i=0;i<n;i++) printf("%d\t%s\t%d\t%d\t%d\t%d\n",(stu+i)->No,(stu+i)->name,(stu+i)->score[0],(stu+i)->score[1],(stu+i)->score[2],(stu+i)->sum);}main(){ studstu[N],new_stu; intchoice,m,n; intscore[N],No,del_No; inti,j,k,new_sco,del_sco,loc_sco; printf("\n"); while(1) { printf("**************************************\n"); printf("*1---数据输入*\n"); printf("*2---记录添加*\n"); printf("*3---学号查询*\n"); printf("*4---记录删除*\n"); printf("*5---数据统计*\n"); printf("*6---成绩排序*\n"); printf("*7---数据输出*\n"); printf("*0---退出*\n"); printf("**************************************\n"); printf("请输入你的选择(0---7):"); scanf("%d",&choice); switch(choice) { case1:printf("数据输入\n");printf("请输入学生数(1-10):");scanf("%d",&num);input(stu,num);//调用输入函数break; case2:printf("记录添加\n");printf("请输入记录信息:");printf("学号:");scanf("%d",&new_stu.No);getchar();printf("姓名:");gets(new_);printf("3门成绩:");for(i=0;i<3;i++)scanf("%d",&new_stu.score[i]);insert(stu,new_stu);//插入学生记录num++;break; case3:printf("学号查询\n");printf("请输入查询学号:");scanf("%d",&No);m=locate(stu,num,No); if(m==-1)printf("NOFIND!\n");else {printf("该生信息:\n"); printf("%d\t%s\t%d\t%d\t%d\n",stu[m].No,stu[m].name,stu[m].score[0],stu[m].score[1],stu[m].score[2]);}break; case4:printf("记录删除\n");printf("请输入删除的学号:");scanf("%d",&del_No);m=delet(stu,num,del_No); if(m==0)printf("NOFIND!\n"); else {printf("删除成功!\n");num--;}break;case5:printf("已经统计出总分和平均分,请按数字7键输出显示\n");count(stu,num);break; case6:printf("已经对三门课程成绩排序,请按数字7键输出显示\n");sort(stu,num);break; case7:printf("数据输出\n");output(stu,num);break;case0:exit(1);break;default:printf("输入错误,请重新输入\n"); } }}法2:#include"stdio.h"intmain(){//1.定义一个结构体类型(也是一种数据类型)//2.定义结构体变量、结构体数组、结构体指针、结构体函数structstudent//定义一个结构体类型{charid[15];charname[20];floatscore[8];};structstudentstd[30],std1,std2,temp;floats[6]={0},averag[6];charsearchID[15];charsearchName[20];intchoice;printf("欢迎使用学生成绩管理系统\n");printf("1:录入学生的成绩\n");printf("2:计算每门课程的总分和平均分\n");printf("3:计算每个学生的总分和平均分\n");printf("4:按学生总成绩由高到低排序\n");printf("5:按学号由小到大排出成绩表\n");printf("6:按姓名的字典顺序排出成绩表\n");printf("7:按学号查询学生排名极其考试成绩\n");printf("8:按姓名查询学生排名极其考试成绩\n");printf("9:按等级统计人数及所占百分比\n");printf("10:输出学生的所有信息及每门课程的总分及平均分\n");printf("..........请选择.......\n");scanf("%d",&choice);switch(choice){case1:printf("请录入学生的成绩\n");for(i=0;i<30;i++){gets(std[i].id);gets(std[i].name);for(j=0;j<6;j++)std[i].score[j];}break;case2:printf("计算每门课程的总分和平均分\n");for(j=0;j<6;j++){for(i=o;i<30;i++)s[j]=s[j]+std[i].score[j];average[j]=s[j]/30;}break;case3:printf("计算每个学生的总分和平均分\n");for(i=0;i<30;i++){std[i].score[6]=0;for(j=0;j<6;j++)std[i].score[6]=std[i].score[6]+std[i].score[j];std[i].score[7]=std[i].score[6]/6;}break;case4:printf("按学生总成绩由高到低排序\n");for(i=1;i<30;i++)//外层循环控制趟数for(j=0;j<30-i-1;j++)//内层循环控制数if(std[j].score[6]<std[j+1].score[6]){strcpy(temp.id,std[j].id);strcpy(std[j].id,std[j].id);strcpy(std[j].id,temp.id);strcpy(,std[j].name);strcpy(std[j].name,std[j].name);strcpy(std[j].name,);for(k=0;k<8;k++)//控制比较学生所有成绩的交换{temp.score[k]=std1.score[k];std1.score[k]=std2.score[k];std2.score[k]=temp.score[k];}}break;case5:printf("按学号由小到大排出成绩表\n");for(i=1;i<30;i++)//外层循环控制趟数for(j=0;j<30-i-1;j++)//内层循环控制数//>0:s>t==0:s==t;<0:s<tif(strcmp(std[j].id,std[j+].id)<0){strcpy(temp.id,std[j].id);strcpy(std[j].id,std[j].id);strcpy(std[j].id,temp.id);strcpy(,std[j].name);strcpy(std[j].name,std[j].name);strcpy(std[j].name,);for(k=0;k<8;k++)//控制比较学生所有成绩的交换{temp.score[k]=std1.score[k];std1.score[k]=std2.score[k];std2.score[k]=temp.score[k];}}break;case6:printf("按姓名的字典顺序排出成绩表\n");break;case7:printf("按学号查询学生排名及其考试成绩\n");gets(searchID);for(i=0;i<30;i++)if(strcmp(std[i].id,searchID)==0){puts(std[i].id);puts(std[i].name);for(j=0;j<8;j++)printf("%f\t",std[i].score[j]);break;}printf("该学生的排名是%d",i);break;case8:printf("按姓名查询学生排名及其考试成绩\n");gets(searchName);for(i=0;i<30;i++)if(strcmp(std[i].id,searchName)==0){puts(std[i].id);puts(std[i].name);for(j=0;j<8;j++)printf("%f\t",std[i].score[j]);break;}printf("该学生的排名是%d",i);break;break;case9:printf("按等级统计人数及所占百分比\n");for(j=0;j<6;j++){for(i=0;i<30;i++)switch(int(std[0].score[0])/10){case10:case9:counter9++;break;case8:counter8++;break;case7:counter7++;break;case6:counter6++;break;default:counter++;break;}intBFB[10];BFB[9]=counter9/30;BFB[8]=counter8/30;BFB[7]=counter7/30;....}break;case10:printf("输出学生的所有信息及每门课程的总分及平均分\n");for(i=0;i<30;i++){puts(std[i].id);puts(std[i].name);for(j=0;j<8;j++)printf("%f\t",std[i].score[j]);}break;default:printf("请重新选择.......\n");}return0;}法3:#include"stdio.h"intmain(){structstudent{charid[10];charname[20];floatscore[8];};intchoice;structstudentstu[30];//重点:数组stu[0].idstructstudenttemp;std[0].idstd[1].id//字符数组std[0].namestd[1].namestrcpy(temp.id,std[0].id);strcpy(std[0].id,std[1].id);strcpy(std[1].id,temp.id);strcpy(,std[0].name);strcpy(std[0].name,std[1].name);strcpy(std[1].name,);for(k=0;k<8;k++){temp.score[k]=std[0].score[k]std[j].score[k]=std[1].score[k];std[j+1].score[k]=temp.score[k]}std[0].score[0]std[1].score[0]std[0].score[1]std[1].score[1]std[0].score[2]std[1].score[2]std[0].score[3]std[1].score[3]...std[0].score[7]std[1].score[7]printf("欢迎使用学生成绩管理系统\n");printf("-------------------------\n");printf("1:录入学生的相关信息\n");printf("2:计算每门课程的总分和平均分\n");printf("3:计算每个学生的总分和平均分\n");printf("4:按每个学生的总分由高到低排出名次表\n");printf("5:按学号由小到大排出成绩表\n");printf("6:按姓名的字典顺序排出成绩表\n");printf("7:按学号查询学生排名及其考试成绩\n");printf("8:按姓名查询学生排名及其考试成绩\n");printf("9:统计类别的人数以及所占的百分比\n");printf("10:输出学生的相关信息\n");printf("请选择...................");scanf("%d",&choice);//choice:int/char/枚举型switch(choice){case1:for(i=0;i<30;i++)//信息的录入{gets(std[i].id);gets(std[i].name);for(j=0;j<6;j++)std[i].score[j];}break;case2:for(j=0;j<6;j++)//统计每门课程的总成绩和平均分{for(i=0;i<30;i++)s[j]=s[j]+std[i].score[j];averageSum[j]=s[j]/30;}break;case3:for(i=0;i<30;i++){for(j=0;j<6;j++)std[i].score[6]=std[i].score[6]+std[i].score[j];std[i].score[7]=std[i].score[6]/6;}break;case4:for(i=1;i<30;i++)for(j=0;j<30-i-1;j++)if(std[j].score[6]<std[j+1].score[6]){strcpy(temp.id,std[j].id);strcpy(std[j].id,std[j+1].id);strcpy(std[j+1].id,temp.id);strcpy(,std[j].name);strcpy(std[j].name,std[j+1].name);strcpy(std[j+1].name,);for(k=0;k<8;k++){temp.score[k]=std[j].score[k]std[j].score[k]=std[j+1].score[k];std[j+1].score[k]=temp.score[k]}}break;case5:for(i=1;i<30;i++)for(j=0;j<30-i-1;j++)if(std[j].id>std[j+1].id){strcpy(temp.id,std[j].id);strcpy(std[j].id,std[j+1].id);strcpy(std[j+1].id,temp.id);strcpy(,std[j].name);strcpy(std[j].name,std[j+1].name);strcpy(std[j+1].name,);for(k=0;k<8;k++){temp.score[k]=std[j].score[k]std[j].score[k]=std[j+1].score[k];std[j+1].score[k]=temp.score[k]}}break;case6:for(i=1;i<30;i++)for(j=0;j<30-i-1;j++)if(std[j].name>std[j+1].name){strcpy(temp.id,std[j].id);strcpy(std[j].id,std[j+1].id);strcpy(std[j+1].id,temp.id);strcpy(,std[j].name);strcpy(std[j].name,std[j+1].name);strcpy(std[j+1].name,);for(k=0;k<8;k++){temp.score[k]=std[j].score[k]std[j].score[k]=std[j+1].score[k];std[j+1].score[k]=temp.score[k]}}break;case7:charsearchID[10];gets(searchID);for(i=0;i<30;i++)if(strcmp(searchID,std[i].id)==0){puts(std[i].id);puts(std[i].name);for(j=0;j<8;j++)printf("%f\t",std[i].score[j]);}

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论