数据结构课程设计报告书学校青岛科技大学学号姓名指导老师刘勇课程设计的名称:学生成绩管理1.问题描述:学生成绩管理是学校教务管理的重要组成部分,其处理信息量很大,该题目是对学生的成绩管理作一个简单的模拟,其中学生信息包括:学号、姓名与成绩。
成绩分为课程1成绩、课程2成绩、课程3成绩和总成绩。
要求设计一个简易的成绩管理系统,输入各门功课的成绩后能自动求出总成绩,并通过菜单选择操作方式完成下列功能:①登记学生成绩;②②查询学生成绩;③插入学生成绩;④④删除学生成绩;⑤按总成绩降序排序。
2.基本要求:该题目涉及到单链表的各种操作,包括单链表的建立、结点的查找、插入、删除等基本运算。
首先建立学生成绩单链表,链表中每个结点由4个域组成,分别为:学号、姓名、成绩、存放下一个结点地址的next域。
然后将要求完成的四项功能写成四个函数,登记学生成绩对应建立学生单链表的功能,后三个功能分别对应单链表的查询、插入与删除三大基本操作。
3.算法思想:Creat()函数算法思想:从0至n循环输入n个同学的三科成绩,并且计算总成绩。
Inquiry()函数算法思想:将学号与已输入的所有学号做比较,一旦相同则输出该学号信息,否则显示没有该学生信息。
Insert()函数算法思想:生成一个新节点,然后将其接到原有链表尾部。
Delete()函数算法思想:通过ID找到该节点,并删去该节点。
Sort(函数算法思想:利用排序算法对每一个节点作比较并更换其在链表中的位置顺序。
4.模块划分(1)LinkList Creat(LinkList T,int n)其功能是创造节点,录入成绩。
(2)void Inquiry(LinkList T)其功能是查询与已知ID一致的学生信息并展示出来。
(3)void Insert(LinkList T,int n)其功能是添加若干个学生的成绩信息。
(4)void Delete(LinkList T)其功能是删除若干个学生的成绩信息。
(5)void Sort(LNode*p)其功能是排序并展示若干个学生的成绩信息。
5.数据结构:数据类型LNode定义如下:typedef struct LNode{int ID;char name[20];int score1;int score2;int score3;int total;struct LNode*next;}LNode,*LinkList;6.源程序:源代码//main.c#include<stdio.h>#include<stdlib.h>typedef struct LNode{int ID;char name[20];int score1;int score2;int score3;int total;struct LNode*next;}LNode,*LinkList;LinkList Creat(LinkList T,int n); void Delete(LinkList T);void Inquiry(LinkList T);void Insert(LinkList T,int n); void Sort(LNode*p);void Insert(LinkList T,int n){int i;LNode*r=T,*p;while((r->next)!=NULL){r=r->next;}for(i=0;i<n;i++){p=(LNode*)malloc(sizeof(LNode));printf("Please enter the student's student ID:");scanf("%d",&p->ID);printf("Please enter the student's name:");scanf("%s",p->name);printf("Please enter the student's score1:");scanf("%d",&p->score1);printf("Please enter the student's score2:");scanf("%d",&p->score2);printf("Please enter the student's score3:");scanf("%d",&p->score3);p->total=p->score1+p->score2+p->score3;printf("The total score is%d\n",p->total);p->next=NULL;r->next=p;r=p;}printf("\nInsert is complete!");}void Inquiry(LinkList T){int id;printf("Please enter the student ID you want to inquire about:");scanf("%d",&id);LNode*p=T;p=p->next;while(p!=NULL){if(p->ID==id){printf("\nThe student scores information has been successfully inquired!\n");printf("ID:%d\nName:%s\nScore1:%d\nScore2:%d\nScore3:%d\n",p->ID,p->name,p->score1,p->score2,p->score3);break;}else{p=p->next;}}if(!p)printf("Sorry!Did not inquiry the student scores information!");}void Delete(LinkList T){int id,flag=1;printf("Please enter the student ID you want to delete about:");scanf("%d",&id);LNode*p=T;//LNode*q;while((p->next)!=NULL){if(p->next->ID==id){//q=p->next;p->next=p->next->next;//delete q;printf("\nThe student scores information has been successfully deleted!\n");flag=0;break;}else{p=p->next;}}if(flag)printf("Sorry!Did not delete the student scores information you want to delete!");}void Sort(LNode*p){LNode*r,*qian,*hou;qian=p->next;hou=qian->next;while(hou)if(qian->total>=hou->total){qian=hou;hou=hou->next;}//ifelse{r=p;while(r->next->total>hou->total)r=r->next;qian->next=hou->next;hou->next=r->next;r->next=hou;hou=qian->next;}//elsep=p->next;int i=1;while(p){printf("Num:%d\nID:%d\nName:%s\nScore1:%d\nScore2:%d\nScore3: %d\ntotal:%d\n\n",i,p->ID,p->name,p->score1,p->score2,p->score3,p->total);p=p->next;i++;}}LinkList Creat(LinkList T,int n){LNode*p,*r;int i;T=(LNode*)malloc(sizeof(LNode));T->next=NULL;r=T;for(i=0;i<n;i++){p=(LNode*)malloc(sizeof(LNode));printf("Please enter the student's student ID:");scanf("%d",&p->ID);printf("Please enter the student's name:");scanf("%s",p->name);printf("Please enter the student's score1:");scanf("%d",&p->score1);printf("Please enter the student's score2:");scanf("%d",&p->score2);printf("Please enter the student's score3:");scanf("%d",&p->score3);p->total=p->score1+p->score2+p->score3;printf("The total score is%d\n",p->total);p->next=NULL;r->next=p;r=p;}return T;}int main(){LNode*p;int n;while(1){system("cls");printf("Student Scores Management\n\n");printf("1-Enter the student's score\n");printf("2-Query the student's score\n");printf("3-Insert the student's score\n");printf("4-Delete the student's score\n");printf("5-Sort the student's score\n");printf("0-Exit system\n\n");printf("Please enter a number selection(0-5):");int choice;scanf("%d",&choice);system("cls");if(choice==0)exit(0);switch(choice){case1:printf("Please enter the number of students you want toenter your student's scores:");scanf("%d",&n);p=Creat(p,n);printf("\n\nPlease enter your choice(1):");printf("1-Esc");scanf("%d",&n);if(n)break;case2:printf("Please enter the number of students you want to query your student's scores:");scanf("%d",&n);int i=0;while(i<n){Inquiry(p);i++;}printf("\nPlease enter your choice(1):");printf("1-Esc");scanf("%d",&n);break;case3:printf("Please enter the number of students you want to insert your student's scores:");scanf("%d",&n);Insert(p,n);printf("\nPlease enter your choice(1):");printf("1-Esc");scanf("%d",&n);break;case4:printf("Please enter the number of students you want to delete your student's scores:");scanf("%d",&n);i=0;while(i<n){Delete(p);i++;}printf("\nPlease enter your choice(1):");printf("1-Esc");scanf("%d",&n);break;case5:Sort(p);printf("\nPlease enter your choice(1):");printf("1-Esc");scanf("%d",&n);break;default:break;}}return0;}7.测试情况:截图:程序输出为:Num:1ID:1Name:n1Score1:78Score2:89Score3:84total:251Num:2ID:3Name:n3Score1:68Score2:89Score3:90total:247课程设计的名称:停车场的管理1.问题描述:设停车场内只有一个可停放n辆汽车的狭长通道,且只有一个大门可供汽车进出。