c语言写个学生成绩管理系统
时间: 2023-12-02 16:41:45 浏览: 91
C语言写的学生成绩管理系统
以下是两种C语言实现学生成绩管理系统的例子:
1.利用结构体数组实现学生成绩管理系统
```c
#include <stdio.h>
#include <string.h>
#define MAX_STUDENT_NUM 100
struct Student {
char name[20];
int id;
float score;
};
int main() {
struct Student students[MAX_STUDENT_NUM];
int count = 0;
char end[] = "end";
while (1) {
printf("请输入学生姓名:");
scanf("%s", students[count].name);
if (strcmp(students[count].name, end) == 0) {
break;
}
printf("请输入学生学号:");
scanf("%d", &students[count].id);
printf("请输入学生分数:");
scanf("%f", &students[count].score);
count++;
}
printf("学生信息如下:\n");
printf("姓名\t学号\t分数\n");
for (int i = 0; i < count; i++) {
printf("%s\t%d\t%.2f\n", students[i].name, students[i].id, students[i].score);
}
return 0;
}
```
2.利用结构体实现学生成绩管理系统(包含增删改查功能)
```c
#include <stdio.h>
#include <string.h>
#define MAX_STUDENT_NUM 100
struct Student {
char name[20];
int id;
float score;
};
int findStudentById(struct Student students[], int count, int id) {
for (int i = 0; i < count; i++) {
if (students[i].id == id) {
return i;
}
}
return -1;
}
void addStudent(struct Student students[], int *count) {
if (*count >= MAX_STUDENT_NUM) {
printf("学生信息已满,无法添加!\n");
return;
}
printf("请输入学生姓名:");
scanf("%s", students[*count].name);
printf("请输入学生学号:");
scanf("%d", &students[*count].id);
printf("请输入学生分数:");
scanf("%f", &students[*count].score);
(*count)++;
printf("添加成功!\n");
}
void deleteStudent(struct Student students[], int *count) {
int id;
printf("请输入要删除的学生学号:");
scanf("%d", &id);
int index = findStudentById(students, *count, id);
if (index == -1) {
printf("未找到该学生!\n");
return;
}
for (int i = index; i < *count - 1; i++) {
students[i] = students[i + 1];
}
(*count)--;
printf("删除成功!\n");
}
void modifyStudent(struct Student students[], int count) {
int id;
printf("请输入要修改的学生学号:");
scanf("%d", &id);
int index = findStudentById(students, count, id);
if (index == -1) {
printf("未找到该学生!\n");
return;
}
printf("请输入学生姓名:");
scanf("%s", students[index].name);
printf("请输入学生分数:");
scanf("%f", &students[index].score);
printf("修改成功!\n");
}
void queryStudent(struct Student students[], int count) {
int id;
printf("请输入要查询的学生学号:");
scanf("%d", &id);
int index = findStudentById(students, count, id);
if (index == -1) {
printf("未找到该学生!\n");
return;
}
printf("学生信息如下:\n");
printf("姓名\t学号\t分数\n");
printf("%s\t%d\t%.2f\n", students[index].name, students[index].id, students[index].score);
}
int main() {
struct Student students[MAX_STUDENT_NUM];
int count = 0;
while (1) {
printf("请选择操作:\n");
printf("1.输入学生信息\n");
printf("2.输出学生信息\n");
printf("3.查询学生信息\n");
printf("4.修改学生信息\n");
printf("5.删除学生信息\n");
printf("6.退出程序\n");
int choice;
scanf("%d", &choice);
switch (choice) {
case 1:
addStudent(students, &count);
break;
case 2:
printf("学生信息如下:\n");
printf("姓名\t学号\t分数\n");
for (int i = 0; i < count; i++) {
printf("%s\t%d\t%.2f\n", students[i].name, students[i].id, students[i].score);
}
break;
case 3:
queryStudent(students, count);
break;
case 4:
modifyStudent(students, count);
break;
case 5:
deleteStudent(students, &count);
break;
case 6:
return 0;
default:
printf("输入有误,请重新输入!\n");
break;
}
}
return 0;
}
```
阅读全文