用c语言设计一个学生成绩管理系统
时间: 2023-12-17 18:06:04 浏览: 92
以下是一个用C语言设计的学生成绩管理系统的示例:
```c
#include <stdio.h>
#include <stdlib.h>
struct Student {
int id; // 学号
char name[50]; // 姓名
int mathGrade; // 数学成绩
int engGrade; // 英语成绩
int total; // 总分
float average; // 平均分
int rank; // 名次
};
void addStudent(struct Student students[], int *count) {
printf("请输入学生的学号:");
scanf("%d", &students[*count].id); printf("请输入学生的姓名:");
scanf("%s", students[*count].name);
printf("请输入学生的数学成绩:");
scanf("%d", &students[*count].mathGrade);
printf("请输入学生的英语成绩:");
scanf("%d", &students[*count].engGrade);
students[*count].total = students[*count].mathGrade + students[*count].engGrade;
students[*count].average = (float)students[*count].total / 2;
(*count)++;
printf("学生信息添加成功!n");
}
void displayStudents(struct Student students[], int count) {
printf("学号\t姓名\t数学成绩\t英语成绩\t总分\t平均分\t名次\n");
for (int i = 0; i < count; i++) {
printf("%d\t%s\t%d\t%d\t%d\t%.2f\t%d\n", students[i].id, students[i].name, students[i].mathGrade, students[i].engGrade, students[i].total, students[i].average, students[i].rank);
}
}
void calculateRank(struct Student students[], int count) {
for (int i = 0; i < count; i++) {
students[i].rank = 1;
for (int j = 0; j < count; j++) {
if (students[j].total > students[i].total) {
students[i].rank++;
}
}
}
}
int main() {
struct Student students[100];
int count = 0;
int select;
while (1) {
printf("学生成绩管理系统\n");
printf("1. 添加学生记录\n");
printf("2. 显示学生信息\n");
printf("3. 计算名次\n");
printf("0. 退出\n");
printf("请选择操作:");
scanf("%d", &select);
switch (select) {
case 1:
addStudent(students, &count);
break;
case 2:
displayStudents(students, count);
break;
case 3:
calculateRank(students, count);
printf("名次计算完成!\n");
break;
case 0:
exit(0);
default:
printf("无效的选择!\n");
break;
}
}
return 0;
}
```
阅读全文