学生信息管理系统c语言程序设计
时间: 2023-09-09 19:12:09 浏览: 46
以下是一个简单的学生信息管理系统的C语言程序设计:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_STUDENTS 50
typedef struct {
char name[20];
int age;
char gender[10];
float score;
} Student;
Student students[MAX_STUDENTS];
int num_students = 0;
void add_student() {
if (num_students == MAX_STUDENTS) {
printf("Maximum number of students reached\n");
return;
}
printf("Enter student name: ");
scanf("%s", students[num_students].name);
printf("Enter student age: ");
scanf("%d", &students[num_students].age);
printf("Enter student gender: ");
scanf("%s", students[num_students].gender);
printf("Enter student score: ");
scanf("%f", &students[num_students].score);
num_students++;
}
void print_student(Student s) {
printf("%-20s %-10d %-10s %-10.2f\n", s.name, s.age, s.gender, s.score);
}
void list_students() {
printf("%-20s %-10s %-10s %-10s\n", "Name", "Age", "Gender", "Score");
for (int i = 0; i < num_students; i++) {
print_student(students[i]);
}
}
void find_student() {
char name[20];
printf("Enter student name: ");
scanf("%s", name);
for (int i = 0; i < num_students; i++) {
if (strcmp(students[i].name, name) == 0) {
printf("%-20s %-10d %-10s %-10.2f\n", students[i].name, students[i].age, students[i].gender, students[i].score);
return;
}
}
printf("Student not found\n");
}
int main() {
int choice;
while (1) {
printf("1. Add student\n");
printf("2. List students\n");
printf("3. Find student\n");
printf("4. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
add_student();
break;
case 2:
list_students();
break;
case 3:
find_student();
break;
case 4:
exit(0);
default:
printf("Invalid choice\n");
}
}
return 0;
}
```
该程序定义了一个结构体`Student`来保存学生的信息,包括姓名、年龄、性别和成绩。使用一个数组`students`来保存所有学生的信息,最多可以保存50个学生的信息。程序提供了三个功能:添加学生、列出所有学生和查找学生。
在添加学生时,程序要求用户输入学生的姓名、年龄、性别和成绩,然后将这些信息保存到`students`数组中。如果已经保存了50个学生的信息,则提示“Maximum number of students reached”。
在列出所有学生时,程序会遍历`students`数组并输出每个学生的信息。
在查找学生时,程序要求用户输入要查找的学生的姓名,然后遍历`students`数组查找该学生的信息。如果找到了该学生的信息,则输出该学生的信息;否则输出“Student not found”。
程序使用`while`循环来反复显示菜单,并根据用户的选择执行相应的操作。如果用户选择退出,则使用`exit`函数退出程序。
相关推荐
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.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)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![cpp](https://img-home.csdnimg.cn/images/20210720083646.png)
![c](https://img-home.csdnimg.cn/images/20210720083646.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)