在C语言的学生管理系统的增删查改中再添加一个选择的功能,就是选择某个学生
找找你的程序的菜单,一般有一个
switch case 的代码
在里面依葫芦画瓢即可。
参考GPT的内容和自己的思路:
在学生管理系统中增加选择某个学生的功能,可以通过以下步骤实现:
添加一个新功能菜单选项,例如选择某个学生(Select a student)。
当用户选择该选项时,提示用户输入要选择的学生的学号或姓名等信息。
根据用户输入的信息,在学生信息列表中查找该学生。
如果找到该学生,则显示该学生的详细信息并提供修改或删除选项。
如果未找到该学生,则提示用户该学生不存在。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_STUDENTS 100
typedef struct {
char id[10];
char name[20];
int age;
float score;
} student;
student students[MAX_STUDENTS];
int count = 0;
void add_student() {
// 添加学生信息的代码
}
void delete_student() {
// 删除学生信息的代码
}
void modify_student() {
// 修改学生信息的代码
}
void search_student() {
// 查询学生信息的代码
}
void select_student() {
char input[20];
printf("Please enter the student ID or name you want to select: ");
scanf("%s", input);
for (int i = 0; i < count; i++) {
if (strcmp(students[i].id, input) == 0 || strcmp(students[i].name, input) == 0) {
printf("Selected student information:\n");
printf("ID: %s\n", students[i].id);
printf("Name: %s\n", students[i].name);
printf("Age: %d\n", students[i].age);
printf("Score: %.2f\n", students[i].score);
printf("1. Modify student information\n");
printf("2. Delete student information\n");
printf("Please select an operation: ");
int choice;
scanf("%d", &choice);
switch (choice) {
case 1:
modify_student();
break;
case 2:
delete_student();
break;
default:
printf("Invalid choice!\n");
}
return;
}
}
printf("The selected student does not exist.\n");
}
void print_menu() {
printf("\n------------------------\n");
printf("Student Management System\n");
printf("------------------------\n");
printf("1. Add student information\n");
printf("2. Delete student information\n");
printf("3. Modify student information\n");
printf("4. Search student information\n");
printf("5. Select a student\n");
printf("0. Exit\n");
printf("Please select an operation: ");
}
int main() {
int choice;
do {
print_menu();
scanf("%d", &choice);
switch (choice) {
case 0:
printf("Exit the system.\n");
break;
case 1:
add_student();
break;
case 2:
delete_student();
break;
case 3:
modify_student();
break;
case 4:
search_student();
break;
case 5:
select_student();
break;
default:
printf("Invalid choice!\n");
}
} while (choice != 0);
return 0;
}
可以写一个搜索函数,返回节点指针