From ea399bbd8cc8fb337ad8de9ea0be085321ae96c9 Mon Sep 17 00:00:00 2001 From: wangkaixuan <@ bzu.edu.cn> Date: Wed, 26 Apr 2023 19:36:32 +0800 Subject: [PATCH] 1 --- daima | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/daima b/daima index e69de29..d437315 100644 --- a/daima +++ b/daima @@ -0,0 +1,90 @@ +} + +// 函数定义 +void init(void) +{ + puts("程序启动"); +} +void quit(void) +{ + puts("程序退出"); + exit(EXIT_SUCCESS); +} +void display_menu(void) +{ + printf("\n%d 读取 | %d 保存 | %d 打印 | %d 查询 | %d 添加\n%d 修改 | %d 删除 | %d 排序 | %d 图表 | %d 退出\n\n", CMD_READ, CMD_SAVE, CMD_PRINT, CMD_QUERY, CMD_INSERT, CMD_UPDATE, CMD_DELETE, CMD_SORT, CMD_CHART, CMD_QUIT); +} +int make_choice(void) +{ + int c; // 用户输入 + int n = 0; // 正确读入的数据项个数 + while (n == 0) + { + printf("请选择:"); + n = scanf("%d", &c); // 尝试读入整数 c + scanf("%*[^\n]"); // 跳过一行中剩余的字符 + } + return c; +} + +//查询 +void query_data(void) +{ + int num; + printf("输入学生学号: "); + scanf("%d", &num); + int f = -1; + for (int i = 0; i < num_parts; i++) + { + if (num == stu[i].number) + { + f = i; + break; + } + } + if (f == -1) + { + printf("学生不存在"); + } + else + { + printf("学生学号:%d\n", stu[f].number); + printf("学生姓名:%s\n", stu[f].name); + printf("学生成绩:%d\n", stu[f].score); + } +} + +//打印 +void print_data(void) +{ + printf("NUMBER | NAME score\n"); + for (int i = 0; i < num_parts; i++) + { + printf("%d | %s %d\n", stu[i].number, stu[i].name, stu[i].score); + } +} + +//添加 +void add_data(void) +{ + int num; + printf("输入学生学号:"); + scanf("%d", &num); + int f = 0; + for (int i = 0; i < num_parts; i++) + { + if (num == stu[i].number) + { + f = 1; + break; + } + } + if (f == 0) + { + stu[num_parts].number = num; + printf("输入学生姓名:"); + scanf("%s", &stu[num_parts].name); + printf("输入学生成绩:"); + scanf("%d", &stu[num_parts].score); + num_parts++; + printf("学生 %d 添加成功\n", num); \ No newline at end of file