c语言大作业学生成绩管理系统
时间: 2024-01-03 13:22:43 浏览: 129
C语言大作业-学生成绩管理系统
5星 · 资源好评率100%
根据提供的引用内容,C语言大作业学生成绩管理系统包括以下功能:
1. 录入每个学生的学号、姓名和各科考试成绩。
2. 计算每门课程的总分和平均分。
3. 计算每个学生的总分和平均分。
4. 按每个学生的总分由高到低排出名次表。
以下是一个示例代码,展示了如何实现学生成绩管理系统的部分功能:
```c
#include <stdio.h>
#include <stdlib.h>
// 定义学生结构体
typedef struct student {
int stdio;
char name[20];
double chinese;
double math;
double english;
double politics;
double sum;
struct student *next;
} Student;
// 录入学生信息
void input(Student **llist) {
Student *p, *q;
p = *llist;
q = (Student *)malloc(sizeof(Student));
printf("请输入学号:");
scanf("%d", &(q->stdio));
printf("请输入姓名:");
scanf("%s", q->name);
printf("请输入语文成绩:");
scanf("%lf", &(q->chinese));
printf("请输入数学成绩:");
scanf("%lf", &(q->math));
printf("请输入英语成绩:");
scanf("%lf", &(q->english));
printf("请输入政治成绩:");
scanf("%lf", &(q->politics));
q->sum = q->chinese + q->math + q->english + q->politics;
q->next = NULL;
if (*llist == NULL) {
*llist = q;
} else {
while (p->next != NULL) {
p = p->next;
}
p->next = q;
}
}
// 计算每门课程的总分和平均分
void calculateCourse(Student *llist) {
double chineseSum = 0, mathSum = 0, englishSum = 0, politicsSum = 0;
int count = 0;
Student *p = llist;
while (p != NULL) {
chineseSum += p->chinese;
mathSum += p->math;
englishSum += p->english;
politicsSum += p->politics;
count++;
p = p->next;
}
double chineseAvg = chineseSum / count;
double mathAvg = mathSum / count;
double englishAvg = englishSum / count;
double politicsAvg = politicsSum / count;
printf("语文总分:%lf 平均分:%lf\n", chineseSum, chineseAvg);
printf("数学总分:%lf 平均分:%lf\n", mathSum, mathAvg);
printf("英语总分:%lf 平均分:%lf\n", englishSum, englishAvg);
printf("政治总分:%lf 平均分:%lf\n", politicsSum, politicsAvg);
}
// 计算每个学生的总分和平均分
void calculateStudent(Student *llist) {
Student *p = llist;
while (p != NULL) {
p->sum = p->chinese + p->math + p->english + p->politics;
double avg = p->sum / 4;
printf("学号:%d 姓名:%s 总分:%lf 平均分:%lf\n", p->stdio, p->name, p->sum, avg);
p = p->next;
}
}
// 按每个学生的总分由高到低排出名次表
void sort(Student *llist) {
Student *p, *q;
int temp;
char tempName[20];
double tempSum;
for (p = llist; p != NULL; p = p->next) {
for (q = p->next; q != NULL; q = q->next) {
if (q->sum > p->sum) {
temp = p->stdio;
p->stdio = q->stdio;
q->stdio = temp;
strcpy(tempName, p->name);
strcpy(p->name, q->name);
strcpy(q->name, tempName);
tempSum = p->sum;
p->sum = q->sum;
q->sum = tempSum;
}
}
}
printf("名次表:\n");
p = llist;
int rank = 1;
while (p != NULL) {
printf("第%d名 学号:%d 姓名:%s 总分:%lf\n", rank, p->stdio, p->name, p->sum);
rank++;
p = p->next;
}
}
int main() {
Student *llist = NULL;
int choice;
while (1) {
printf("\n--学生成绩管理系统--\n");
printf("1. 录入学生信息\n");
printf("2. 计算每门课程的总分和平均分\n");
printf("3. 计算每个学生的总分和平均分\n");
printf("4. 按每个学生的总分由高到低排出名次表\n");
printf("0. 退出\n");
printf("请输入您的选择:");
scanf("%d", &choice);
switch (choice) {
case 1:
input(&llist);
break;
case 2:
calculateCourse(llist);
break;
case 3:
calculateStudent(llist);
break;
case 4:
sort(llist);
break;
case 0:
exit(0);
default:
printf("输入错误,请重新输入!\n");
break;
}
}
return 0;
}
```
阅读全文