用c语言帮我写一个学生信息管理系统,要求有(1)系统菜单,上面要有1.添加2.显示3.修改4.删除5.查找6.排序0.退出;(2)要满足系统菜单上的功能。
时间: 2024-02-03 22:12:23 浏览: 68
一个关于c语言的学生信息管理系统的程序,,,
好的,以下是一个简单的学生信息管理系统的C语言实现:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_STUDENTS 100 // 最大学生数量
#define MAX_NAME_LENGTH 20 // 学生姓名最大长度
// 学生信息结构体
typedef struct {
int id; // 学号
char name[MAX_NAME_LENGTH]; // 姓名
int age; // 年龄
} Student;
// 学生信息数组
Student students[MAX_STUDENTS];
// 当前学生数量
int studentCount = 0;
void printMenu() {
printf("学生信息管理系统\n");
printf("1.添加\n");
printf("2.显示\n");
printf("3.修改\n");
printf("4.删除\n");
printf("5.查找\n");
printf("6.排序\n");
printf("0.退出\n");
}
void addStudent() {
if (studentCount >= MAX_STUDENTS) {
printf("学生数量已达到上限\n");
return;
}
printf("请输入学生信息:\n");
Student student;
printf("学号:");
scanf("%d", &student.id);
printf("姓名:");
scanf("%s", student.name);
printf("年龄:");
scanf("%d", &student.age);
students[studentCount] = student;
studentCount++;
printf("添加成功\n");
}
void displayStudents() {
printf("学号\t姓名\t年龄\n");
for (int i = 0; i < studentCount; i++) {
Student student = students[i];
printf("%d\t%s\t%d\n", student.id, student.name, student.age);
}
}
void modifyStudent() {
int id;
printf("请输入要修改的学生学号:");
scanf("%d", &id);
for (int i = 0; i < studentCount; i++) {
Student *student = &students[i];
if (student->id == id) {
printf("请输入新的学生信息:\n");
printf("姓名:");
scanf("%s", student->name);
printf("年龄:");
scanf("%d", &student->age);
printf("修改成功\n");
return;
}
}
printf("找不到该学生信息\n");
}
void deleteStudent() {
int id;
printf("请输入要删除的学生学号:");
scanf("%d", &id);
for (int i = 0; i < studentCount; i++) {
Student *student = &students[i];
if (student->id == id) {
for (int j = i; j < studentCount - 1; j++) {
students[j] = students[j + 1];
}
studentCount--;
printf("删除成功\n");
return;
}
}
printf("找不到该学生信息\n");
}
void searchStudent() {
int id;
printf("请输入要查找的学生学号:");
scanf("%d", &id);
for (int i = 0; i < studentCount; i++) {
Student student = students[i];
if (student.id == id) {
printf("学号\t姓名\t年龄\n");
printf("%d\t%s\t%d\n", student.id, student.name, student.age);
return;
}
}
printf("找不到该学生信息\n");
}
void sortStudents() {
for (int i = 0; i < studentCount - 1; i++) {
for (int j = 0; j < studentCount - 1 - i; j++) {
if (students[j].id > students[j + 1].id) {
Student temp = students[j];
students[j] = students[j + 1];
students[j + 1] = temp;
}
}
}
printf("排序成功\n");
}
int main() {
int choice;
do {
printMenu();
printf("请选择操作:");
scanf("%d", &choice);
switch (choice) {
case 1:
addStudent();
break;
case 2:
displayStudents();
break;
case 3:
modifyStudent();
break;
case 4:
deleteStudent();
break;
case 5:
searchStudent();
break;
case 6:
sortStudents();
break;
case 0:
printf("谢谢使用\n");
break;
default:
printf("无效的操作\n");
break;
}
printf("\n");
} while (choice != 0);
return 0;
}
```
这个程序实现了上述要求,你可以根据需要进行修改和完善。
阅读全文