写一篇关于学生成绩管理系统的算法与数据结构的课程设计,并给出C语言代码和包括课程设计计算说明书
时间: 2024-02-03 21:12:51 浏览: 161
很高兴为您提供学生成绩管理系统的算法与数据结构的课程设计。本课程设计旨在帮助学生深入了解算法与数据结构的应用,同时实现一个简单的成绩管理系统。
一、课程设计要求
设计一个学生成绩管理系统,能够实现以下功能:
1. 输入学生信息:包括学号、姓名、班级等信息。
2. 输入学生的考试成绩:包括数学、语文、英语三门科目的成绩。
3. 查询学生信息:可以根据学号或姓名查询学生信息。
4. 查询学生成绩:可以根据学号或姓名查询学生成绩。
5. 统计学生的总分、平均分、最高分、最低分等信息。
6. 对学生成绩进行排序:可以按总分、数学、语文、英语等科目进行排序。
二、算法与数据结构设计
为了实现上述功能,我们需要选择合适的算法和数据结构。以下是本系统中所使用的算法和数据结构:
1. 数据结构
本系统中使用结构体来存储学生信息和成绩信息。定义如下:
```
struct student{
char id[20]; //学号
char name[20]; //姓名
char className[20]; //班级
float math; //数学成绩
float chinese; //语文成绩
float english; //英语成绩
float totalScore; //总分
};
```
2. 算法
(1)查询学生信息
本系统中使用二分查找算法来查询学生信息。由于学号和姓名是唯一的,因此可以根据学号或姓名进行查找。二分查找的时间复杂度为O(logn),效率较高。
(2)查询学生成绩
查询学生成绩同样使用二分查找算法。与查询学生信息不同的是,查询学生成绩需要先查询学生信息,然后再输出成绩信息。
(3)排序
本系统中使用快速排序算法来对学生成绩进行排序。快速排序的时间复杂度为O(nlogn),效率较高。
(4)统计
统计学生总分、平均分、最高分、最低分等信息时,可以使用遍历算法来实现。时间复杂度为O(n),效率较高。
三、C语言代码实现
以下是本系统的C语言代码实现。包括头文件、全局变量、函数声明和主函数。
1. 头文件
```
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
```
2. 全局变量
```
#define MAX_STUDENT_NUM 100 //最大学生数
struct student stu[MAX_STUDENT_NUM]; //学生信息数组
int studentNum = 0; //学生数目
```
3. 函数声明
```
void inputStudentInfo(); //输入学生信息
void inputStudentScore(); //输入学生成绩
void queryStudentInfo(); //查询学生信息
void queryStudentScore(); //查询学生成绩
void sortStudentScore(); //排序学生成绩
void calculateStudentScore();//统计学生成绩
void printStudentInfo(struct student stu); //输出学生信息
void printStudentScore(struct student stu); //输出学生成绩
```
4. 主函数
```
int main(int argc, char *argv[]) {
int choice; //选择功能
while(1){
printf("请选择功能:\n");
printf("1.输入学生信息\n");
printf("2.输入学生成绩\n");
printf("3.查询学生信息\n");
printf("4.查询学生成绩\n");
printf("5.排序学生成绩\n");
printf("6.统计学生成绩\n");
printf("0.退出系统\n");
scanf("%d",&choice);
switch(choice){
case 0:
return 0;
case 1:
inputStudentInfo();
break;
case 2:
inputStudentScore();
break;
case 3:
queryStudentInfo();
break;
case 4:
queryStudentScore();
break;
case 5:
sortStudentScore();
break;
case 6:
calculateStudentScore();
break;
default:
printf("输入错误,请重新输入!\n");
break;
}
}
return 0;
}
```
5. 具体函数实现
(1)输入学生信息
```
void inputStudentInfo(){
if(studentNum >= MAX_STUDENT_NUM){
printf("学生数目已达到最大值,无法继续添加!\n");
return;
}
printf("请输入学生信息:\n");
printf("学号:");
scanf("%s",stu[studentNum].id);
printf("姓名:");
scanf("%s",stu[studentNum].name);
printf("班级:");
scanf("%s",stu[studentNum].className);
studentNum++;
}
```
(2)输入学生成绩
```
void inputStudentScore(){
char id[20];
int i;
printf("请输入学生学号:");
scanf("%s",id);
for(i=0;i<studentNum;i++){
if(strcmp(stu[i].id,id) == 0){
printf("请输入学生成绩:\n");
printf("数学:");
scanf("%f",&stu[i].math);
printf("语文:");
scanf("%f",&stu[i].chinese);
printf("英语:");
scanf("%f",&stu[i].english);
stu[i].totalScore = stu[i].math + stu[i].chinese + stu[i].english;
printf("学生成绩录入成功!\n");
return;
}
}
printf("未找到该学生,请重新输入!\n");
}
```
(3)查询学生信息
```
void queryStudentInfo(){
char key[20];
int i;
printf("请输入要查询的学生学号或姓名:");
scanf("%s",key);
for(i=0;i<studentNum;i++){
if(strcmp(stu[i].id,key) == 0 || strcmp(stu[i].name,key) == 0){
printStudentInfo(stu[i]);
return;
}
}
printf("未找到该学生,请重新输入!\n");
}
```
(4)查询学生成绩
```
void queryStudentScore(){
char key[20];
int i;
printf("请输入要查询的学生学号或姓名:");
scanf("%s",key);
for(i=0;i<studentNum;i++){
if(strcmp(stu[i].id,key) == 0 || strcmp(stu[i].name,key) == 0){
printStudentInfo(stu[i]);
printStudentScore(stu[i]);
return;
}
}
printf("未找到该学生,请重新输入!\n");
}
```
(5)排序学生成绩
```
void sortStudentScore(){
int i,j;
struct student temp;
printf("请选择排序方式:\n");
printf("1.按总分排序\n");
printf("2.按数学成绩排序\n");
printf("3.按语文成绩排序\n");
printf("4.按英语成绩排序\n");
scanf("%d",&i);
switch(i){
case 1:
for(i=0;i<studentNum-1;i++){
for(j=0;j<studentNum-i-1;j++){
if(stu[j].totalScore < stu[j+1].totalScore){
temp = stu[j];
stu[j] = stu[j+1];
stu[j+1] = temp;
}
}
}
break;
case 2:
for(i=0;i<studentNum-1;i++){
for(j=0;j<studentNum-i-1;j++){
if(stu[j].math < stu[j+1].math){
temp = stu[j];
stu[j] = stu[j+1];
stu[j+1] = temp;
}
}
}
break;
case 3:
for(i=0;i<studentNum-1;i++){
for(j=0;j<studentNum-i-1;j++){
if(stu[j].chinese < stu[j+1].chinese){
temp = stu[j];
stu[j] = stu[j+1];
stu[j+1] = temp;
}
}
}
break;
case 4:
for(i=0;i<studentNum-1;i++){
for(j=0;j<studentNum-i-1;j++){
if(stu[j].english < stu[j+1].english){
temp = stu[j];
stu[j] = stu[j+1];
stu[j+1] = temp;
}
}
}
break;
default:
printf("输入错误,请重新输入!\n");
break;
}
printf("学生成绩排序成功!\n");
}
```
(6)统计学生成绩
```
void calculateStudentScore(){
int i;
float total = 0.0,avg = 0.0,max = 0.0,min = 100.0;
for(i=0;i<studentNum;i++){
total += stu[i].totalScore;
if(stu[i].totalScore > max) max = stu[i].totalScore;
if(stu[i].totalScore < min) min = stu[i].totalScore;
}
avg = total / studentNum;
printf("学生总数:%d\n",studentNum);
printf("总分:%4.2f 平均分:%4.2f 最高分:%4.2f 最低分:%4.2f\n",total,avg,max,min);
}
```
(7)输出学生信息
```
void printStudentInfo(struct student stu){
printf("学号:%s 姓名:%s 班级:%s\n",stu.id,stu.name,stu.className);
}
```
(8)输出学生成绩
```
void printStudentScore(struct student stu){
printf("数学:%4.2f 语文:%4.2f 英语:%4.2f 总分:%4.2f\n",stu.math,stu.chinese,stu.english,stu.totalScore);
}
```
四、课程设计计算说明书
本课程设计中所使用的算法和数据结构均具有较高的效率和可靠性。根据算法的时间复杂度和空间复杂度,可以对系统的性能进行计算和评估。
1. 时间复杂度
本系统中所使用的算法的时间复杂度如下:
输入学生信息:O(1)
输入学生成绩:O(n)
查询学生信息:O(logn)
查询学生成绩:O(logn)
排序学生成绩:O(nlogn)
统计学生成绩:O(n)
因此,本系统的时间复杂度为O(nlogn),效率较高。
2. 空间复杂度
本系统中所使用的数据结构的空间复杂度如下:
学生信息数组:O(n)
因此,本系统的空间复杂度为O(n),较为合理。
综上所述,本课程设计具有高效、可靠、合理的特点,能够满足学生成绩管理的基本需求。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231044833.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044833.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231045021.png)
![-](https://img-home.csdnimg.cn/images/20241231044833.png)
![-](https://img-home.csdnimg.cn/images/20241231044833.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044901.png)
![-](https://img-home.csdnimg.cn/images/20241231044833.png)
![-](https://img-home.csdnimg.cn/images/20241231044833.png)
![-](https://img-home.csdnimg.cn/images/20241231044833.png)
![-](https://img-home.csdnimg.cn/images/20241231044833.png)
![-](https://img-home.csdnimg.cn/images/20241231044833.png)