学生成绩管理系统的代码
时间: 2023-12-31 22:24:12 浏览: 67
以下是一个简单的学生成绩管理系统的代码示例:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct student {
int num;
char name[20];
float pingshi;
float shiyan;
float kaoshi;
};
void inputStudent(struct student *s) {
printf("请输入学生的学号:");
scanf("%d", &(s->num));
printf("请输入学生的姓名:");
scanf("%s", s->name);
printf("请输入学生的平时成绩:");
scanf("%f", &(s->pingshi));
printf("请输入学生的实验成绩:");
scanf("%f", &(s->shiyan));
printf("请输入学生的考试成绩:");
scanf("%f", &(s->kaoshi));
}
void printStudent(struct student s) {
printf("学号:%d\n", s.num);
printf("姓名:%s\n", s.name);
printf("平时成绩:%.2f\n", s.pingshi);
printf("实验成绩:%.2f\n", s.shiyan);
printf("考试成绩:%.2f\n", s.kaoshi);
}
void searchStudent(struct student *students, int count, int num) {
int i;
for (i = 0; i < count; i++) {
if (students[i].num == num) {
printStudent(students[i]);
return;
}
}
printf("未找到该学生!\n");
}
void printAllStudents(struct student *students, int count) {
int i;
for (i = 0; i < count; i++) {
printStudent(students[i]);
printf("\n");
}
}
void modifyStudent(struct student *students, int count, int num) {
int i;
for (i = 0; i < count; i++) {
if (students[i].num == num) {
inputStudent(&(students[i]));
printf("修改成功!\n");
return;
}
}
printf("未找到该学生!\n");
}
void deleteStudent(struct student *students, int *count, int num) {
int i, j;
for (i = 0; i < *count; i++) {
if (students[i].num == num) {
for (j = i; j < *count - 1; j++) {
students[j] = students[j + 1];
}
(*count)--;
printf("删除成功!\n");
return;
}
}
printf("未找到该学生!\n");
}
int main() {
struct student students[100];
int count = 0;
int choice;
int num;
while (1) {
printf("学生成绩管理系统\n");
printf("1. 录入学生信息\n");
printf("2. 查询学生信息\n");
printf("3. 查询全部学生信息\n");
printf("4. 修改学生信息\n");
printf("5. 删除学生信息\n");
printf("6. 退出系统\n");
printf("请输入您的选择:");
scanf("%d", &choice);
switch (choice) {
case 1:
inputStudent(&(students[count]));
count++;
printf("录入成功!\n");
break;
case 2:
printf("请输入要查询的学生学号:");
scanf("%d", &num);
searchStudent(students, count, num);
break;
case 3:
printAllStudents(students, count);
break;
case 4:
printf("请输入要修改的学生学号:");
scanf("%d", &num);
modifyStudent(students, count, num);
break;
case 5:
printf("请输入要删除的学生学号:");
scanf("%d", &num);
deleteStudent(students, &count, num);
break;
case 6:
printf("退出系统!\n");
exit(0);
default:
printf("无效的选择!\n");
break;
}
}
return 0;
}
```
阅读全文