成绩分析问题课程设计-_第1页
成绩分析问题课程设计-_第2页
成绩分析问题课程设计-_第3页
成绩分析问题课程设计-_第4页
成绩分析问题课程设计-_第5页
已阅读5页,还剩8页未读 继续免费阅读

下载本文档

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

文档简介

《数据结构c》课程设计报告课程设计概述本次数据结构课程设计共完成5个题目:成绩分析问题,哈夫曼编码器,迷宫问题,八皇后问题,农夫过河问题的求解。使用环境:C语言。编译环境:VisualStudio2022。课程设计题目实验内容:成绩分析问题。问题描述:设计并实现一个成绩分析系统,能够实现录入,保存一个班级学生多门课程的成绩,并对成绩进行分析等功能。需求分析:经过分析,本系统需完成的主要功能如下:通过键盘输入各学生的多门课程的成绩,建立相应的文件input.dat。对文件input.dat中的数据进行处理,要求具有如下功能:按各门课程成绩排序,并生成相应的文件输出。计算每个人的平均成绩,按平均成绩排序,并生成文件。求出各门课程的平均成绩,最高分,最低分,不及格人数,60~69分人数,70~79分人数,80~89分人数,90分以上人数。根据姓名或学号查询某人的各门课程成绩,重名也要能处理。概要设计:--=ADT=--{Student*SearchByName(Student*head,char*name)//根据姓名查询学生信息Student*SearchById(Student*head,char*id)//根据学号查询学生信息voidAdd(Student**head)//添加一个学生voidRead(Student**head)//读取文件中的学生信息voidSave(Student*head)//保存学生信息到文件voidSortAndOutput(Student*head)//按三门课程成绩排序并输出voidCalculateAverage(Student*head)//计算每人三门课程的平均成绩并输出voidSortByAverageScoreAndOutput(Student*head)//按三门课程平均成绩排序并输出voidStatistics(Student*head)//统计三门课程各自的平均成绩,最高分,最低分,不及格人数,60~69分人数,70~79分人数,80~89分人数,90分以上人数voidShowMenu()//显示菜单}存储结构:typedefstructstudent{

charid[20];//学号

charname[20];//姓名

floatmath_score;//数学成绩

floatenglish_score;//英语成绩

floatcomputer_score;//计算机成绩

floataverage;//平均成绩

structstudent*next;//指向下一个学生的指针}Student;设计思路:链表数据结构:使用链表来存储学生信息,每个节点表示一个学生。链表的好处是可以动态地添加和删除节点,灵活处理不同数量的学生信息。-学生结构体:定义一个学生结构体,包含以下字段:学号、姓名、数学成绩、英语成绩、计算机成绩、平均成绩和指向下一个学生节点的指针。这样可以方便地存储和访问每个学生的相关信息。-功能函数:实现各种功能函数,如添加学生、读取文件、保存文件、排序等。这些函数通过操作链表来完成相关操作。关键算法:-冒泡排序算法:用于将学生根据指定的排序规那么〔如成绩〕进行排序。冒泡排序算法的根本思想是比拟相邻的两个元素,如果它们的顺序错误就交换位置,继续比拟直到完成排序。在学生信息管理系统中,可以根据数学成绩、英语成绩或计算机成绩来排序学生信息。-遍历链表:通过使用循环遍历链表的每个节点,可以实现对链表中的数据进行访问、处理和输出等操作。遍历链表是获取每个学生信息、计算平均成绩以及输出结果的关键步骤。-文件读写:通过使用二进制文件读写方式,可以将学生信息保存到文件中,或从文件中读取学生信息。在学生信息管理系统中,可以将学生信息以二进制形式写入文件,并在需要时从文件中读取,并重新构建链表。使用链表作为数据结构,结合冒泡排序算法、链表遍历和文件读写等算法,可以实现学生信息的管理、排序和存储等功能详细设计:#include<stdio.h>#include<stdlib.h>#include<string.h>//定义学生结构体typedefstructstudent{

charid[20];//学号

charname[20];//姓名

floatmath_score;//数学成绩

floatenglish_score;//英语成绩

floatcomputer_score;//计算机成绩

floataverage;//平均成绩

structstudent*next;//指向下一个学生的指针}Student;//根据姓名查询学生信息Student*SearchByName(Student*head,char*name){

Student*p=head;

while(p!=NULL){

if(strcmp(p->name,name)==0){//找到该学生

returnp;

}

p=p->next;

}

returnNULL;//没有找到该学生}//根据学号查询学生信息Student*SearchById(Student*head,char*id){

Student*p=head;

while(p!=NULL){

if(strcmp(p->id,id)==0){//找到该学生

returnp;

}

p=p->next;

}

returnNULL;//没有找到该学生}//添加一个学生voidAdd(Student**head){

Student*p=(Student*)malloc(sizeof(Student));

printf("请输入学生的学号:");

scanf("%s",p->id);

printf("请输入学生的姓名:");

scanf("%s",p->name);

printf("请输入学生的数学成绩:");

scanf("%f",&p->math_score);

printf("请输入学生的英语成绩:");

scanf("%f",&p->english_score);

printf("请输入学生的计算机成绩:");

scanf("%f",&p->computer_score);

p->average=(p->math_score+p->english_score+p->computer_score)/3;//计算平均成绩

//插入到链表中

Student*temp=NULL;

Student*cur=*head;

while(cur&&p->average<cur->average){//按平均成绩排序插入

temp=cur;

cur=cur->next;

}

if(temp==NULL){

p->next=*head;

*head=p;

}else{

temp->next=p;

p->next=cur;

}

printf("添加成功\n");}//读取文件中的学生信息voidRead(Student**head){

FILE*fp=fopen("input.dat","rb");

if(fp==NULL){

printf("文件翻开失败\n");

return;

}

Student*p=(Student*)malloc(sizeof(Student));

fread(p,sizeof(Student),1,fp);

while(!feof(fp)){

//插入到链表后面

p->next=*head;

*head=p;

p=(Student*)malloc(sizeof(Student));

fread(p,sizeof(Student),1,fp);

}

printf("读取成功\n");

fclose(fp);}//保存学生信息到文件voidSave(Student*head){

FILE*fp=fopen("input.dat","wb");

if(fp==NULL){

printf("文件翻开失败\n");

return;

}

Student*p=head;

while(p!=NULL){

fwrite(p,sizeof(Student),1,fp);

p=p->next;

}

printf("保存成功\n");

fclose(fp);}//按三门课程成绩排序并输出voidSortAndOutput(Student*head){

Student*p=head;

intcount=0;

while(p!=NULL){

count++;

p=p->next;

}

Student**array=(Student**)malloc(sizeof(Student*)*count);//存储指针的数组

p=head;

for(inti=0;i<count;i++){

array[i]=p;

p=p->next;

}

for(inti=0;i<count-1;i++){//冒泡排序

for(intj=0;j<count-1-i;j++){

if(array[j]->math_score+array[j]->english_score+array[j]->computer_score<array[j+1]->math_score+array[j+1]->english_score+array[j+1]->computer_score){

Student*temp=array[j];

array[j]=array[j+1];

array[j+1]=temp;

}

}

}

FILE*fp=fopen("sorted_by_score.dat","w");

fprintf(fp,"%-20s%-20s%-20s%-20s%-20s%-20s\n","学号","姓名","数学成绩","英语成绩","计算机成绩","平均成绩");

for(inti=0;i<count;i++){

fprintf(fp,"%-20s%-20s%-20.1f%-20.1f%-20.1f%-20.1f\n",array[i]->id,array[i]->name,array[i]->math_score,array[i]->english_score,array[i]->computer_score,array[i]->average);

}

printf("排序成功并已保存到sorted_by_score.dat文件中\n");

fclose(fp);}//计算每人三门课程的平均成绩并输出voidCalculateAverage(Student*head){

FILE*fp=fopen("average_score.dat","w");

fprintf(fp,"%-20s%-20s%-20s%-20s%-20s%-20s\n","学号","姓名","数学成绩","英语成绩","计算机成绩","平均成绩");

Student*p=head;

while(p!=NULL){

fprintf(fp,"%-20s%-20s%-20.1f%-20.1f%-20.1f%-20.1f\n",p->id,p->name,p->math_score,p->english_score,p->computer_score,p->average);

p=p->next;

}

printf("每人三门课程的平均成绩已计算并保存到average_score.dat文件中\n");

fclose(fp);}//按三门课程平均成绩排序并输出voidSortByAverageScoreAndOutput(Student*head){

Student*p=head;

intcount=0;

while(p!=NULL){

count++;

p=p->next;

}

Student**array=(Student**)malloc(sizeof(Student*)*count);//存储指针的数组

p=head;

for(inti=0;i<count;i++){

array[i]=p;

p=p->next;

}

for(inti=0;i<count-1;i++){//冒泡排序

for(intj=0;j<count-1-i;j++){

if(array[j]->average<array[j+1]->average){

Student*temp=array[j];

array[j]=array[j+1];

array[j+1]=temp;

}

}

}

FILE*fp=fopen("sorted_by_average_score.dat","w");

fprintf(fp,"%-20s%-20s%-20s%-20s%-20s%-20s\n","学号","姓名","数学成绩","英语成绩","计算机成绩","平均成绩");

for(inti=0;i<count;i++){

fprintf(fp,"%-20s%-20s%-20.1f%-20.1f%-20.1f%-20.1f\n",array[i]->id,array[i]->name,array[i]->math_score,array[i]->english_score,array[i]->computer_score,array[i]->average);

}

printf("排序成功并已保存到sorted_by_average_score.dat文件中\n");

fclose(fp);}//统计三门课程各自的平均成绩,最高分,最低分,不及格人数,60~69分人数,70~79分人数,80~89分人数,90分以上人数voidStatistics(Student*head){

floatmath_total=0;

floatenglish_total=0;

floatcomputer_total=0;

intmath_count=0;

intenglish_count=0;

intcomputer_count=0;

intfail_count=0;

intsixty_nine_count=0;

intseventy_nine_count=0;

inteighty_nine_count=0;

intninety_count=0;

floatmath_max=0;

floatenglish_max=0;

floatcomputer_max=0;

floatmath_min=100;

floatenglish_min=100;

floatcomputer_min=100;

Student*p=head;

while(p!=NULL){

math_count++;

math_total+=p->math_score;

if(p->math_score>math_max)math_max=p->math_score;

if(p->math_score<math_min)math_min=p->math_score;

english_count++;

english_total+=p->english_score;

if(p->english_score>english_max)english_max=p->english_score;

if(p->english_score<english_min)english_min=p->english_score;

computer_count++;

computer_total+=p->computer_score;

if(p->computer_score>computer_max)computer_max=p->computer_score;

if(p->computer_score<computer_min)computer_min=p->computer_score;

if(p->math_score<60||p->english_score<60||p->computer_score<60){

fail_count++;

}elseif(p->math_score>=60&&p->math_score<=69&&p->english_score>=60&&p->english_score<=69&&p->computer_score>=60&&p->computer_score<=69){

sixty_nine_count++;

}elseif(p->math_score>=70&&p->math_score<=79&&p->english_score>=70&&p->english_score<=79&&p->computer_score>=70&&p->computer_score<=79){

seventy_nine_count++;

}elseif(p->math_score>=80&&p->math_score<=89&&p->english_score>=80&&p->english_score<=89&&p->computer_score>=80&&p->computer_score<=89){

eighty_nine_count++;

}elseif(p->math_score>=90&&p->english_score>=90&&p->computer_score>=90){

ninety_count++;

}

p=p->next;

}

printf("数学平均成绩:%f\n",math_total/math_count);

printf("数学最高分:%f\n",math_max);

printf("数学最低分:%f\n",math_min);

printf("英语平均成绩:%f\n",english_total/english_count);

printf("英语最高分:%f\n",english_max);

printf("英语最低分:%f\n",english_min);

printf("计算机平均成绩:%f\n",computer_total/computer_count);

printf("计算机最高分:%f\n",computer_max);

printf("计算机最低分:%f\n",computer_min);

printf("不及格人数:%d\n",fail_count);

printf("60~69分人数:%d\n",sixty_nine_count);

printf("70~79分人数:%d\n",seventy_nine_count);

printf("80~89分人数:%d\n",eighty_nine_count);

printf("90分以上人数:%d\n",ninety_count);}//显示菜单voidShowMenu(){

printf("\n\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("0.退出程序\n");

printf("\n\n");}intmain(){

intchoice=-1;

Student*head=NULL;//链表头指针

while(choice!=0){

ShowMenu();

scanf("%d",&choice);

switch(choice){

case1:

Add(&head);

break;

case2:

Read(&head);

break;

case3:

Save(head);

break;

case4:

SortAndOutput(head);

break;

case5:

CalculateAverage(head);

break;

case6:

SortByAverageScoreAndOutput(head);

break;

case7:

Statistics(head);

break;

case8:

{

charname[20];

printf("请输入学生的姓名:");

scanf("%s",name);

Student*p=SearchByName(head,name);

if(p!=NULL){

printf("%-20s%-20s%-20s%-20s%-20s\n","数学成绩","英语成绩","计算机成绩","平均成绩","总成绩");

printf("%-20.1f%-20.1f%-20.1f%-20.1f%-20.1f\n",p->math_score,p->english_score,p->computer_score,p->average,p->math_score+p->english_score+p->computer_score);

}else{

printf("没有找到该学生\n");

}

break;

}

case9:

{

温馨提示

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

评论

0/150

提交评论