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.

171 lines
3.5 KiB

}
<<<<<<< HEAD
// 函数定义
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)
=======
else
{
printf("学生已存在");
}
}
//修改
void update_data(void)
>>>>>>> 3aaec9cca337fd57c2c1b138e8ad7fee782cc079
{
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)
{
<<<<<<< HEAD
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);
=======
printf("学生不存在");
}
else
{
printf("输入学生学号:");
scanf("%d", &stu[num].number);
printf("输入学生姓名:");
scanf("%s", stu[num].name);
printf("输入学生成绩:");
scanf("%d", &stu[num].score);
printf("学生 %d 已更新", num);
}
}
//删除
void delete_data(void)
{
int num;
printf("输入学生学号:");
scanf("%d", &num);
int f = 0, i, j;
for (i = 0; i < num_parts; i++)
{
if (num == stu[i].number)
{
f = 1;
break;
}
}
if (f == 0)
{
printf("学生不存在");
}
else
{
for (j = i; j < num_parts - 1; j++)
{
stu[j] = stu[j + 1];
}
num_parts--;
printf("删除成功");
}
}
void read_data(void)
{
puts("读取数据");
printf("请输入文件名");
char filename[256];
scanf("%s", filename);
FILE *fp = fopen(filename, "r");
if (fp == NULL)
{
perror(filename);
return;
}
int i = 0;
while (fscanf(fp, "%d,%[^,],%d", &stu[i].number, stu[i].name, &stu[i].score) == 3)
{
i++;
}
fclose(fp);
num_parts = i;
printf("读取 %d 记录\n", num_parts);
}
>>>>>>> 3aaec9cca337fd57c2c1b138e8ad7fee782cc079