利用c语言建立一个学生信息基本管理系统能输入学号,班级,姓名,性别,年龄,爱好,可以对学生的信息进行输入,追加,修改,删除,浏览全部,插入,退出
时间: 2024-05-13 09:15:32 浏览: 29
好的,下面是一个简单的学生信息基本管理系统的C语言代码,包括了输入学生信息、追加、修改、删除、浏览全部、插入、退出等功能:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_STUDENT 100
typedef struct {
char id[20];
char name[20];
char gender[10];
int age;
char hobby[50];
} Student;
Student students[MAX_STUDENT];
int studentCount = 0;
void inputStudentInfo(Student *student);
void addStudent(Student *student);
void modifyStudent();
void deleteStudent();
void browseAllStudent();
void insertStudent();
void exitSystem();
int main() {
int choice;
while (1) {
printf("\n====== 学生信息管理系统 ======\n");
printf("1. 录入学生信息\n");
printf("2. 追加学生信息\n");
printf("3. 修改学生信息\n");
printf("4. 删除学生信息\n");
printf("5. 浏览全部学生信息\n");
printf("6. 插入学生信息\n");
printf("7. 退出系统\n");
printf("请选择操作:");
scanf("%d", &choice);
switch (choice) {
case 1:
inputStudentInfo(&students[studentCount]);
studentCount++;
printf("录入成功!\n");
break;
case 2:
inputStudentInfo(&students[studentCount]);
addStudent(&students[studentCount]);
studentCount++;
printf("追加成功!\n");
break;
case 3:
modifyStudent();
break;
case 4:
deleteStudent();
break;
case 5:
browseAllStudent();
break;
case 6:
insertStudent();
break;
case 7:
exitSystem();
exit(0);
default:
printf("无效操作,请重新选择!\n");
break;
}
}
return 0;
}
void inputStudentInfo(Student *student) {
printf("请输入学号:");
scanf("%s", student->id);
printf("请输入姓名:");
scanf("%s", student->name);
printf("请输入性别:");
scanf("%s", student->gender);
printf("请输入年龄:");
scanf("%d", &student->age);
printf("请输入爱好:");
scanf("%s", student->hobby);
}
void addStudent(Student *student) {
int i;
for (i = 0; i < studentCount; i++) {
if (strcmp(students[i].id, student->id) == 0) {
strcpy(students[i].name, student->name);
strcpy(students[i].gender, student->gender);
students[i].age = student->age;
strcpy(students[i].hobby, student->hobby);
return;
}
}
printf("追加失败,学号不存在!\n");
}
void modifyStudent() {
char id[20];
printf("请输入要修改的学生学号:");
scanf("%s", id);
int i;
for (i = 0; i < studentCount; i++) {
if (strcmp(students[i].id, id) == 0) {
inputStudentInfo(&students[i]);
printf("修改成功!\n");
return;
}
}
printf("修改失败,学号不存在!\n");
}
void deleteStudent() {
char id[20];
printf("请输入要删除的学生学号:");
scanf("%s", id);
int i;
for (i = 0; i < studentCount; i++) {
if (strcmp(students[i].id, id) == 0) {
int j;
for (j = i; j < studentCount - 1; j++) {
students[j] = students[j + 1];
}
studentCount--;
printf("删除成功!\n");
return;
}
}
printf("删除失败,学号不存在!\n");
}
void browseAllStudent() {
int i;
printf("学号\t姓名\t性别\t年龄\t爱好\n");
for (i = 0; i < studentCount; i++) {
printf("%s\t%s\t%s\t%d\t%s\n", students[i].id, students[i].name, students[i].gender, students[i].age, students[i].hobby);
}
}
void insertStudent() {
int pos;
printf("请输入要插入的位置(从1开始):");
scanf("%d", &pos);
if (pos < 1 || pos > studentCount + 1) {
printf("无效位置!\n");
return;
}
Student student;
inputStudentInfo(&student);
int i;
for (i = studentCount; i >= pos; i--) {
students[i] = students[i - 1];
}
students[pos - 1] = student;
studentCount++;
printf("插入成功!\n");
}
void exitSystem() {
printf("感谢使用学生信息管理系统,再见!\n");
}
```
这个系统使用了结构体存储学生信息,可以进行录入、追加、修改、删除、浏览全部、插入和退出等操作。注意,这个系统没有进行数据持久化,所以每次关闭系统后都会丢失数据。如果需要进行数据持久化,可以使用文件存储学生信息,或者使用数据库。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![cpp](https://img-home.csdnimg.cn/images/20210720083646.png)
![c](https://img-home.csdnimg.cn/images/20210720083646.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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)