c语言课程设计学生成绩管理系统作业
时间: 2023-10-04 14:07:37 浏览: 136
C语言课程设计大作业学生成绩管理系统源代码.zip
5星 · 资源好评率100%
好的,那么你需要一个学生成绩管理系统,下面是一个简单的设计思路:
1. 首先需要创建一个学生信息结构体,包括学生姓名、学号、班级等信息。
2. 创建一个成绩信息结构体,包括各科成绩、总成绩等信息。
3. 使用动态数组或链表来存储学生信息和成绩信息。
4. 实现添加、删除、修改、查询学生信息和成绩信息的功能。
5. 实现成绩计算功能,包括平均分、总分、排名等。
6. 可以将学生信息和成绩信息存储到文件中,以便下次启动程序时可以读取之前保存的数据。
下面是一个简单的代码示例,供参考:
```
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_NAME_LEN 20
#define MAX_CLASS_LEN 10
#define MAX_STUDENT_NUM 100
// 学生信息结构体
typedef struct {
char name[MAX_NAME_LEN];
char id[MAX_CLASS_LEN];
char class[MAX_CLASS_LEN];
} StudentInfo;
// 成绩信息结构体
typedef struct {
double score1;
double score2;
double score3;
double total_score;
int rank;
} ScoreInfo;
// 学生及成绩信息结构体
typedef struct {
StudentInfo student;
ScoreInfo score;
} StudentScoreInfo;
// 全局变量,用于存储所有学生及成绩信息
StudentScoreInfo g_students[MAX_STUDENT_NUM];
int g_student_num = 0;
// 添加学生信息
void add_student() {
printf("Please input student info:\n");
printf("Name: ");
scanf("%s", g_students[g_student_num].student.name);
printf("ID: ");
scanf("%s", g_students[g_student_num].student.id);
printf("Class: ");
scanf("%s", g_students[g_student_num].student.class);
printf("Score1: ");
scanf("%lf", &g_students[g_student_num].score.score1);
printf("Score2: ");
scanf("%lf", &g_students[g_student_num].score.score2);
printf("Score3: ");
scanf("%lf", &g_students[g_student_num].score.score3);
g_students[g_student_num].score.total_score = g_students[g_student_num].score.score1 + g_students[g_student_num].score.score2 + g_students[g_student_num].score.score3;
g_student_num++;
printf("Add student success!\n");
}
// 删除学生信息
void delete_student() {
char id[MAX_CLASS_LEN];
printf("Please input id of student you want to delete:\n");
scanf("%s", id);
for (int i = 0; i < g_student_num; i++) {
if (strcmp(id, g_students[i].student.id) == 0) {
for (int j = i + 1; j < g_student_num; j++) {
g_students[j - 1] = g_students[j];
}
g_student_num--;
printf("Delete student success!\n");
return;
}
}
printf("Student not found!\n");
}
// 修改学生信息
void modify_student() {
char id[MAX_CLASS_LEN];
printf("Please input id of student you want to modify:\n");
scanf("%s", id);
for (int i = 0; i < g_student_num; i++) {
if (strcmp(id, g_students[i].student.id) == 0) {
printf("Please input new student info:\n");
printf("Name: ");
scanf("%s", g_students[i].student.name);
printf("ID: ");
scanf("%s", g_students[i].student.id);
printf("Class: ");
scanf("%s", g_students[i].student.class);
printf("Score1: ");
scanf("%lf", &g_students[i].score.score1);
printf("Score2: ");
scanf("%lf", &g_students[i].score.score2);
printf("Score3: ");
scanf("%lf", &g_students[i].score.score3);
g_students[i].score.total_score = g_students[i].score.score1 + g_students[i].score.score2 + g_students[i].score.score3;
printf("Modify student success!\n");
return;
}
}
printf("Student not found!\n");
}
// 查询学生信息
void query_student() {
char id[MAX_CLASS_LEN];
printf("Please input id of student you want to query:\n");
scanf("%s", id);
for (int i = 0; i < g_student_num; i++) {
if (strcmp(id, g_students[i].student.id) == 0) {
printf("Name: %s\n", g_students[i].student.name);
printf("ID: %s\n", g_students[i].student.id);
printf("Class: %s\n", g_students[i].student.class);
printf("Score1: %.2lf\n", g_students[i].score.score1);
printf("Score2: %.2lf\n", g_students[i].score.score2);
printf("Score3: %.2lf\n", g_students[i].score.score3);
printf("Total score: %.2lf\n", g_students[i].score.total_score);
printf("Rank: %d\n", g_students[i].score.rank);
return;
}
}
printf("Student not found!\n");
}
// 计算成绩
void calculate_score() {
// 计算总分
for (int i = 0; i < g_student_num; i++) {
g_students[i].score.total_score = g_students[i].score.score1 + g_students[i].score.score2 + g_students[i].score.score3;
}
// 计算排名
for (int i = 0; i < g_student_num; i++) {
g_students[i].score.rank = 1;
for (int j = 0; j < g_student_num; j++) {
if (g_students[j].score.total_score > g_students[i].score.total_score) {
g_students[i].score.rank++;
}
}
}
printf("Calculate score success!\n");
}
// 显示菜单
void show_menu() {
printf("Please select an operation:\n");
printf("1. Add student\n");
printf("2. Delete student\n");
printf("3. Modify student\n");
printf("4. Query student\n");
printf("5. Calculate score\n");
printf("6. Exit\n");
}
int main() {
int choice = 0;
while (1) {
show_menu();
scanf("%d", &choice);
switch (choice) {
case 1:
add_student();
break;
case 2:
delete_student();
break;
case 3:
modify_student();
break;
case 4:
query_student();
break;
case 5:
calculate_score();
break;
case 6:
exit(0);
default:
printf("Invalid choice!\n");
break;
}
}
return 0;
}
```
这只是一个简单的设计,你可以根据实际需求来增加或修改功能。同时,也可以根据具体情况来选择使用动态数组还是链表来存储数据。
阅读全文