学生管理系统c语言版0
时间: 2023-12-26 15:28:09 浏览: 62
以下是一个简单的学生信息管理系统的C语言代码示例:
```c
#include <stdio.h>
#include <string.h>
#define MAX_STUDENTS 100
typedef struct {
char num[10];
char name[20];
int age;
float score;
} Student;
int main() {
Student students[MAX_STUDENTS];
int count = 0;
while (1) {
printf("请选择操作:\n");
printf("1. 添加学生信息\n");
printf("2. 查询学生信息\n");
printf("3. 修改学生信息\n");
printf("4. 删除学生信息\n");
printf("5. 显示所有学生信息\n");
printf("0. 退出\n");
int choice;
scanf("%d", &choice);
switch (choice) {
case 1: {
if (count >= MAX_STUDENTS) {
printf("学生信息已满,无法添加!\n");
break;
}
printf("请输入学号:");
scanf("%s", students[count].num);
printf("请输入姓名:");
scanf("%s", students[count].name);
printf("请输入年龄:");
scanf("%d", &students[count].age);
printf("请输入成绩:");
scanf("%f", &students[count].score);
count++;
printf("学生信息添加成功!\n");
break;
}
case 2: {
char num[10];
printf("请输入要查询的学号:");
scanf("%s", num);
int found = 0;
for (int i = 0; i < count; i++) {
if (strcmp(students[i].num, num) == 0) {
printf("学号:%s\n", students[i].num);
printf("姓名:%s\n", students[i].name);
printf("年龄:%d\n", students[i].age);
printf("成绩:%.2f\n", students[i].score);
found = 1;
break;
}
}
if (!found) {
printf("未找到该学号对应的学生信息!\n");
}
break;
}
case 3: {
char num[10];
printf("请输入要修改的学号:");
scanf("%s", num);
int found = 0;
for (int i = 0; i < count; i++) {
if (strcmp(students[i].num, num) == 0) {
printf("请输入新的姓名:");
scanf("%s", students[i].name);
printf("请输入新的年龄:");
scanf("%d", &students[i].age);
printf("请输入新的成绩:");
scanf("%f", &students[i].score);
found = 1;
printf("学生信息修改成功!\n");
break;
}
}
if (!found) {
printf("未找到该学号对应的学生信息!\n");
}
break;
}
case 4: {
char num[10];
printf("请输入要删除的学号:");
scanf("%s", num);
int found = 0;
for (int i = 0; i < count; i++) {
if (strcmp(students[i].num, num) == 0) {
for (int j = i; j < count - 1; j++) {
students[j] = students[j + 1];
}
count--;
found = 1;
printf("学生信息删除成功!\n");
break;
}
}
if (!found) {
printf("未找到该学号对应的学生信息!\n");
}
break;
}
case 5: {
if (count == 0) {
printf("暂无学生信息!\n");
break;
}
printf("所有学生信息如下:\n");
for (int i = 0; i < count; i++) {
printf("学号:%s\n", students[i].num);
printf("姓名:%s\n", students[i].name);
printf("年龄:%d\n", students[i].age);
printf("成绩:%.2f\n", students[i].score);
printf("\n");
}
break;
}
case 0: {
printf("感谢使用学生信息管理系统,再见!\n");
return 0;
}
default:
printf("无效的操作!\n");
break;
}
}
}
```
阅读全文