資源簡介
鏈表實現學生管理系統
代碼片段和文件信息
#include?
#include?
#include?
struct?Student
{
????int?id;
????char?name[20];
????int?age;
????struct?Student?*next;
};
enum?my_func
{
????f_add=1
????f_delate
????f_find
????f_change
????f_printf_all
????ESC
};
void?add(struct?Student?*p_head);
void?delate(struct?Student?*p_head);
void?find(struct?Student?*p_head);
void?change(struct?Student?*p_head);
void?printf_all(struct?Student?*p_head);
void?menu(struct?Student?*p_head);
int?num?=?0;
int?main()
{
????struct?Student?*p_head?=?(struct?Student?*)malloc(sizeof(struct?Student));
????p_head->next?=?NULL;
????menu(p_head);
????return?0;
}
void?menu(struct?Student?*p_head)
{???
????int?choose=0;
????while?(1)
????{
????????printf(“****************************\n“);
????????printf(“***?歡迎使用學生管理系統???***\n“);
????????printf(“***???1、增加學生信息?????***\n“);
????????printf(“***???2、刪除信息?????????***\n“);
????????printf(“***???3、查詢信息?????????***\n“);
????????printf(“***???4、更改信息?????????***\n“);
????????printf(“***???5、打印所有學生信息??***\n“);
????????printf(“***???6、退出?????????????***\n“);
????????printf(“***?學生總人數:%d?????????***\n“?num);
????????printf(“*****************************\n“);
????????printf(“***??請輸入你的選項序號??***\n“);
????????scanf(“?%d“?&choose);
????????getchar();??//等待輸入ENTER
????????printf(“***************************\n“);
????????switch?(choose)
????????{
????????????case?f_add:
????????????????add(p_head);
????????????????break;
????????????case?f_delate:
????????????????delate(p_head);
????????????????break;
????????????case?f_find:
????????????????find(p_head);
????????????????break;
????????????case?f_change:
????????????????change(p_head);
????????????????break;
????????????case?f_printf_all:
????????????????printf_all(p_head);
????????????????break;
????????????case?ESC:
????????????????printf(“成功退出,歡迎再次使用!\n“);
????????????????return;
????????????default:
????????????????printf(“輸入有誤,請重新輸入!\n“);
????????}
????}
???
}
void?add(struct?Student?*p_head)
{
????struct?Student?*p?=?p_head;
????struct?Student?*tmp?=?(struct?Student?*)malloc(sizeof(struct?Student));
????tmp->next?=?NULL;
????printf(“請輸入你要添加學生的ID\n“);
????scanf(“%d“?&tmp->id);
????getchar();
????
????while?(1)
????{
????????if(p->next?==?NULL)?????????//剛開始?p->next?=?NULL;
????????{
????????????p->next?=?tmp;
????????????tmp->next?=?NULL;
????????????p->next->id?=?tmp->id;
????????????num++;
????????????tmp?=?NULL;
????????????break;
????????}
????????if(p->next->id?==?tmp->id)
????????{
????????????printf(“ID重復,請重新輸入\n“);
????????????scanf(“%d“?&tmp->id);
????????????getchar();
????????????p?=?p_head;
????????}else
????????{
????????????p?=?p->next;????//移動
????????}
????}
????printf(“請輸入你要添加學生的姓名\n“);
????scanf(“%s“?p->next->name);
????getchar();
????printf(“請輸入你要添加學生的年齡\n“);
????scanf(“%d“?&p->next->age);
????getchar();
????printf(“你添加的學生的信息是:\n“);
????pri
評論
共有 條評論