帮我写一个学生信息管理系统的C语言程序
时间: 2023-03-26 18:01:30 浏览: 93
好的,我可以回答这个问题。以下是一个简单的学生信息管理系统的C语言程序:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_STUDENTS 100
struct student {
char name[50];
int id;
float gpa;
};
struct student students[MAX_STUDENTS];
int num_students = ;
void add_student() {
if (num_students >= MAX_STUDENTS) {
printf("Error: too many students\n");
return;
}
struct student s;
printf("Enter student name: ");
scanf("%s", s.name);
printf("Enter student ID: ");
scanf("%d", &s.id);
printf("Enter student GPA: ");
scanf("%f", &s.gpa);
students[num_students] = s;
num_students++;
}
void print_student(struct student s) {
printf("%s (ID: %d, GPA: %.2f)\n", s.name, s.id, s.gpa);
}
void print_all_students() {
int i;
for (i = ; i < num_students; i++) {
print_student(students[i]);
}
}
void search_student() {
char name[50];
printf("Enter student name to search: ");
scanf("%s", name);
int i;
for (i = ; i < num_students; i++) {
if (strcmp(students[i].name, name) == ) {
print_student(students[i]);
return;
}
}
printf("Student not found\n");
}
int main() {
int choice;
while (1) {
printf("1. Add student\n");
printf("2. Print all students\n");
printf("3. Search student\n");
printf("4. Quit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
add_student();
break;
case 2:
print_all_students();
break;
case 3:
search_student();
break;
case 4:
exit();
default:
printf("Invalid choice\n");
}
}
return ;
}
相关推荐
![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)
![](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)