学生成绩管理系统+c语言
时间: 2024-01-03 17:21:47 浏览: 38
```c
#include <stdio.h>
#include <string.h>
typedef struct person {
char num[10]; //学号
char name[20]; //姓名
float score; //成绩
} Person;
void addScore(Person *p, int *count) {
printf("请输入学号:");
scanf("%s", p[*count].num);
printf("请输入姓名:");
scanf("%s", p[*count].name);
printf("请输入成绩:");
scanf("%f", &p[*count].score);
(*count)++;
}
void deleteScore(Person *p, int *count, char *num) {
for (int i = 0; i < *count; i++) {
if (strcmp(p[i].num, num) == 0) {
for (int j = i; j < *count - 1; j++) {
p[j] = p[j + 1];
}
(*count)--;
printf("删除成功\n");
return;
}
}
printf("未找到该学号\n");
}
void updateScore(Person *p, int count, char *num) {
for (int i = 0; i < count; i++) {
if (strcmp(p[i].num, num) == 0) {
printf("请输入新的成绩:");
scanf("%f", &p[i].score);
printf("更新成功\n");
return;
}
}
printf("未找到该学号\n");
}
void queryScore(Person *p, int count, char *num) {
for (int i = 0; i < count; i++) {
if (strcmp(p[i].num, num) == 0) {
printf("学号:%s, 姓名:%s, 成绩:%.2f\n", p[i].num, p[i].name, p[i].score);
return;
}
}
printf("未找到该学号\n");
}
float calculateAverage(Person *p, int count) {
float sum = 0;
for (int i = 0; i < count; i++) {
sum += p[i].score;
}
return sum / count;
}
void displayScores(Person *p, int count) {
for (int i = 0; i < count; i++) {
printf("学号:%s, 姓名:%s, 成绩:%.2f\n", p[i].num, p[i].name, p[i].score);
}
}
int main() {
Person persons[100];
int count = 0;
int choice;
char num[10];
while (1) {
printf("\n1.增加成绩 2.删除成绩 3.更新成绩 4.查询成绩 5.计算平均成绩 6.展示所有成绩 7.退出\n");
printf("请选择操作:");
scanf("%d", &choice);
switch (choice) {
case 1:
addScore(persons, &count);
break;
case 2:
printf("请输入要删除的学号:");
scanf("%s", num);
deleteScore(persons, &count, num);
break;
case 3:
printf("请输入要更新的学号:");
scanf("%s", num);
updateScore(persons, count, num);
break;
case 4:
printf("请输入要查询的学号:");
scanf("%s", num);
queryScore(persons, count, num);
break;
case 5:
printf("平均成绩为:%.2f\n", calculateAverage(persons, count));
break;
case 6:
displayScores(persons, count);
break;
case 7:
return 0;
default:
printf("输入有误\n");
}
}
return 0;
}
```
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)