C语言程序设计学生成绩管理系统
时间: 2023-07-10 21:04:08 浏览: 116
C程序设计学生成绩管理系统
好的,一个C语言程序设计的学生成绩管理系统可以包括以下功能:
1. 学生信息的添加、删除、修改和查询功能;
2. 成绩录入功能,可以输入学生的各科成绩;
3. 成绩统计功能,可以计算学生的总分、平均分等;
4. 排名功能,可以根据总分或某个科目的成绩进行排序;
5. 成绩报表功能,可以输出学生的成绩单或各种统计报表。
以下是一个简单的程序示例:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// 定义学生结构体
typedef struct {
char name[20]; // 学生姓名
int id; // 学生学号
float score[3]; // 学生成绩,共三科
float total; // 学生总分
float average; // 学生平均分
} Student;
// 定义全局变量
Student students[100]; // 存储学生信息的数组
int count = 0; // 学生数量
// 添加学生信息
void addStudent() {
printf("请输入学生姓名:");
scanf("%s", students[count].name);
printf("请输入学生学号:");
scanf("%d", &students[count].id);
printf("请输入学生的语文、数学、英语成绩(用空格分隔):");
scanf("%f %f %f", &students[count].score[0], &students[count].score[1], &students[count].score[2]);
students[count].total = students[count].score[0] + students[count].score[1] + students[count].score[2];
students[count].average = students[count].total / 3;
printf("添加成功!\n");
count++;
}
// 删除学生信息
void deleteStudent() {
int id;
printf("请输入要删除的学生学号:");
scanf("%d", &id);
int index = -1;
for (int i = 0; i < count; i++) {
if (students[i].id == id) {
index = i;
break;
}
}
if (index == -1) {
printf("未找到该学生!\n");
} else {
for (int i = index; i < count - 1; i++) {
students[i] = students[i + 1];
}
count--;
printf("删除成功!\n");
}
}
// 修改学生信息
void modifyStudent() {
int id;
printf("请输入要修改的学生学号:");
scanf("%d", &id);
int index = -1;
for (int i = 0; i < count; i++) {
if (students[i].id == id) {
index = i;
break;
}
}
if (index == -1) {
printf("未找到该学生!\n");
} else {
printf("请输入学生姓名:");
scanf("%s", students[index].name);
printf("请输入学生的语文、数学、英语成绩(用空格分隔):");
scanf("%f %f %f", &students[index].score[0], &students[index].score[1], &students[index].score[2]);
students[index].total = students[index].score[0] + students[index].score[1] + students[index].score[2];
students[index].average = students[index].total / 3;
printf("修改成功!\n");
}
}
// 查询学生信息
void queryStudent() {
int id;
printf("请输入要查询的学生学号:");
scanf("%d", &id);
int index = -1;
for (int i = 0; i < count; i++) {
if (students[i].id == id) {
index = i;
break;
}
}
if (index == -1) {
printf("未找到该学生!\n");
} else {
printf("学生姓名:%s\n", students[index].name);
printf("学生学号:%d\n", students[index].id);
printf("语文成绩:%g\n", students[index].score[0]);
printf("数学成绩:%g\n", students[index].score[1]);
printf("英语成绩:%g\n", students[index].score[2]);
printf("总分:%g\n", students[index].total);
printf("平均分:%g\n", students[index].average);
}
}
// 统计学生信息
void statisticsStudent() {
float totalScore = 0;
float totalAverage = 0;
for (int i = 0; i < count; i++) {
totalScore += students[i].total;
totalAverage += students[i].average;
}
printf("学生总数:%d\n", count);
printf("总分:%g\n", totalScore);
printf("平均分:%g\n", totalScore / count);
printf("平均平均分:%g\n", totalAverage / count);
}
// 排序学生信息
void sortStudent() {
int choice;
printf("请选择排序方式(1:按总分排序,2:按语文成绩排序,3:按数学成绩排序,4:按英语成绩排序):");
scanf("%d", &choice);
switch (choice) {
case 1:
for (int i = 0; i < count - 1; i++) {
for (int j = 0; j < count - i - 1; j++) {
if (students[j].total < students[j + 1].total) {
Student temp = students[j];
students[j] = students[j + 1];
students[j + 1] = temp;
}
}
}
break;
case 2:
for (int i = 0; i < count - 1; i++) {
for (int j = 0; j < count - i - 1; j++) {
if (students[j].score[0] < students[j + 1].score[0]) {
Student temp = students[j];
students[j] = students[j + 1];
students[j + 1] = temp;
}
}
}
break;
case 3:
for (int i = 0; i < count - 1; i++) {
for (int j = 0; j < count - i - 1; j++) {
if (students[j].score[1] < students[j + 1].score[1]) {
Student temp = students[j];
students[j] = students[j + 1];
students[j + 1] = temp;
}
}
}
break;
case 4:
for (int i = 0; i < count - 1; i++) {
for (int j = 0; j < count - i - 1; j++) {
if (students[j].score[2] < students[j + 1].score[2]) {
Student temp = students[j];
students[j] = students[j + 1];
students[j + 1] = temp;
}
}
}
break;
default:
printf("输入有误!\n");
return;
}
printf("排序成功!\n");
}
// 输出学生信息
void printStudent() {
printf("姓名\t学号\t语文\t数学\t英语\t总分\t平均分\n");
for (int i = 0; i < count; i++) {
printf("%s\t%d\t%g\t%g\t%g\t%g\t%g\n", students[i].name, students[i].id, students[i].score[0], students[i].score[1], students[i].score[2], students[i].total, students[i].average);
}
}
int main() {
int choice;
while (1) {
printf("\n*****学生成绩管理系统*****\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("请输入操作编号:");
scanf("%d", &choice);
switch (choice) {
case 1:
addStudent();
break;
case 2:
deleteStudent();
break;
case 3:
modifyStudent();
break;
case 4:
queryStudent();
break;
case 5:
statisticsStudent();
break;
case 6:
sortStudent();
break;
case 7:
printStudent();
break;
case 8:
printf("感谢使用系统,再见!\n");
exit(0);
default:
printf("输入有误,请重新输入!\n");
}
}
return 0;
}
```
这个程序使用了结构体来存储学生信息,通过循环实现不同的功能。你可以根据自己的需求进行修改和扩展。
阅读全文