You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
test1/daima1.c

90 lines
1.9 KiB

#define NAME_LEN 31
#define MAX_PARTS 100
/
struct students
{
int number;
char name[NAME_LEN + 1];
int score;
};
static struct students stu[MAX_PARTS];
static int num_parts = 0;
#include <stdio.h>
#include <stdlib.h>
//定义常量
#define CMD_QUIT 0
#define CMD_QUERY 4
#define CMD_INSERT 5
#define CMD_UPDATE 6
#define CMD_DELETE 7
#define CMD_READ 1
#define CMD_SAVE 2
#define CMD_PRINT 3
#define CMD_SORT 8
#define CMD_CHART 9
// 菜单命令的编号
// 函数声明
void init(void);
void quit(void);
void display_menu(void);
int make_choice(void);
void read_data(void); // 读取
void save_data(void); // 保存
void print_data(void); // 打印
void query_data(void); // 查询
void add_data(void); // 添加
void update_data(void); // 修改
void delete_data(void); // 删除
void sort_data(void); // 排序
void make_chart(void); // 图表
int confirm(const char *msg);
// 主程序
int main(void)
{
init(); // 程序启动
while (1)
{
display_menu();
int c = make_choice();
switch (c)
{
case CMD_QUERY:
query_data();
break;
case CMD_INSERT:
add_data();
break;
case CMD_UPDATE:
update_data();
break;
case CMD_DELETE:
delete_data();
break;
case CMD_READ:
read_data();
break;
case CMD_SAVE:
save_data();
break;
case CMD_PRINT:
print_data();
break;
case CMD_SORT:
sort_data();
break;
case CMD_CHART:
make_chart();
break;
default:
puts("命令错误,请重新选择");
break;
case CMD_QUIT:
if (confirm("确定要退出吗?"))
quit(); // 仅在确认后退出
break;
}
}
return 0;