顺序表实现学生管理系统(参照顺序表技能)写出菜单界面switch选择,功能1创建顺序表(堆区),2录入学生信息,3插入一个学生信息,4删除一个学生信息,5按照位置修改一个学生信息,6、按照姓名顺序查找一个学生是否存在7、对学生年龄直接插入排序(从小到大)。
#ifndef STUDENT_H
#define STUDENT_H
typedef struct {
char name[50];
float score;
int age;
char phone[15];
} Student;
#endif
#ifndef SEQLIST_H
#define SEQLIST_H
#include "student.h"
#include <stdbool.h>
#define MAX_SIZE 100
typedef struct {
Student data[MAX_SIZE];
int length;
} SeqList;
#include "seqlist.h"
#include <stdio.h>
int main() {
SeqList list;
initSeqList(&list);
Student stu;
char nameSearch[50];
int choice, index;
float score;
int age;
char phone[15];
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("0. 退出系统\n");
printf("请选择操作:");
scanf("%d", &choice);
switch (choice) {
case 1:
initSeqList(&list);
printf("顺序表已创建。\n");
break;
case 2:
printf("请输入学生姓名、分数、年龄和电话:");
scanf("%s %f %d %s", stu.name, &score, &age, phone);
stu.score = score;
stu.age = age;
strcpy(stu.phone, phone);
insertStudent(&list, stu);
break;
case 3:
// 同2
break;
case 4:
printf("请输入要删除的学生索引:");
scanf("%d", &index);
deleteStudent(&list, index);
break;
case 5:
printf("请输入要修改的学生索引和新的学生信息:");
scanf("%d %s %f %d %s", &index, stu.name, &score, &age, phone);
stu.score = score;
stu.age = age;
strcpy(stu.phone, phone);
modifyStudent(&list, index, stu);
break;
case 6:
printf("请输入要查找的学生姓名:");
scanf("%s", nameSearch);
index = findStudent(&list, nameSearch);
if (index != -1) {
printf("找到学生:姓名:%s,分数:%.2f,年龄:%d,电话:%s\n",
list.data[index].name, list.data[index].score, list.data[index].age, list.data[index].phone);
} else {
printf("未找到该学生。\n");
}
break;
case 7:
sortStudents(&list);
displayList(&list);
break;
case 0:
printf("退出系统。\n");
return 0;
default:
printf("无效的选项,请重新选择。\n");
}
}
return 0;
}