学生档案管理系统c语言代码
时间: 2023-12-28 21:05:30 浏览: 126
以下是一个简单的学生档案管理系统的C语言代码示例:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_STUDENTS 100
struct Student {
char name[50];
int age;
float gpa;
};
int main() {
struct Student students[MAX_STUDENTS];
int numStudents = 0;
while (1) {
printf("请选择操作:\n"); printf("1. 添加学生\n");
printf("2. 显示所有学生\n");
printf("3. 退出\n");
int choice;
scanf("%d", &choice);
switch (choice) {
case 1:
if (numStudents >= MAX_STUDENTS) {
printf("学生数量已达到上限!\n");
break;
}
printf("请输入学生姓名:");
scanf("%s", students[numStudents].name);
printf("请输入学生年龄:");
scanf("%d", &students[numStudents].age);
printf("请输入学生GPA:");
scanf("%f", &students[numStudents].gpa);
numStudents++;
printf("学生添加成功!\n");
break;
case 2:
if (numStudents == 0) {
printf("没有学生记录!\n");
break;
}
printf("所有学生信息如下:\n");
for (int i = 0; i < numStudents; i++) {
printf("姓名:%s,年龄:%d,GPA:%f\n", students[i].name, students[i].age, students[i].gpa);
}
break;
case 3:
printf("程序已退出。\n");
exit(0);
default:
printf("无效的选择!\n");
break;
}
}
return 0;
}
```
阅读全文