作品简介
通过菜单,以完成菜谱输入,查询,分类,推荐等功能,此外,还添加了同菜不同名的映射检测机制以及个性化推荐机制。
程序特色
同菜不同名映射检测:
在实际生活中,我们常常会因为生活地区的不同而对相同的菜有着不同的叫法,为避免用户在使用此系统时出现以上情况,该程序采用了映射体结构来存储同名不同菜的检测。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
void del() {
system("cls");
char name[20];
int found = 0;
printf("请输入你要删除的菜名:\n");
scanf("%s", name);
char mappedName[20];
//定义一个映射名字,检测出是否存在同菜不同名的情况
//比如宫保鸡与宫保鸡丁指向同一道菜,我们可以定义一个结构体来存储这些映射进而在检索名字时进行检测
strcpy(mappedName, name); // 复制输入的菜名
for (int i = 0; mappings[i].original[0] != '\0'; i++) {
// 检测是否为空字符,若不是,则继续遍历
if (strcmp(name, mappings[i].original) == 0) {
//比较用户输入的名字与映射数组的名字
strcpy(mappedName, mappings[i].mapped);
//复制给映射名字
break;
}
}
for (int i = 0; i < dish_count; i++) {//遍历整个菜谱
if (strcmp(dishes[i].name, mappedName) == 0) {
// 检查当前菜品名称
printf("确定要删除么?(y/n)\n");
//再次询问,以免误删
char isTure;
while (getchar() != '\n');
//去掉换行符
scanf("%c",&isTure);
if(isTure == 'y'){
for (int j = i; j < dish_count - 1; j++) {
// 将后续菜品向前移动一位,覆盖掉要删除的菜品
dishes[j] = dishes[j + 1];
}
dish_count--;
printf("已删除。\n");
found = 1;
save_to_file();
break;
}
else{
printf("已取消删除。\n");
system("pause");
return ;
}
}
}
if (!found) {
printf("未找到该菜名,请重试。\n");
}
system("pause");
}
个性化推荐机制:
有时,我们会面临不知吃什么的难题,这时我们的推荐系统就可以很好的帮助我们解决这个问题,在个性化口味的同时,为您推荐公认的高分菜!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
void recommend() {
system("cls");
int count = 0;
UserProfile profile;//定义一个结构体变量,方便后续添加新的功能
printf("请输入您的爱好(麻辣,咸鲜等): ");
scanf("%s", profile.personality);
getchar(); // 清除缓冲区中的换行符
char recommended_cuisine[20] = ""; // 初始化为空字符串。
if (strcmp(profile.personality, "麻辣") == 0 || strcmp(profile.personality, "") == 0) {//匹配爱好与菜系
strcpy(recommended_cuisine, "川菜");
} else if (strcmp(profile.personality, "咸鲜") == 0 || strcmp(profile.personality, "浓厚") == 0) {
strcpy(recommended_cuisine, "鲁菜");
} else if (strcmp(profile.personality, "清淡") == 0 || strcmp(profile.personality, "鲜美") == 0) {
strcpy(recommended_cuisine, "粤菜");
} else if (strcmp(profile.personality, "清新") == 0 || strcmp(profile.personality, "鲜嫩") == 0) {
strcpy(recommended_cuisine, "淮扬菜");
} else if (strcmp(profile.personality, "滑爽") == 0 || strcmp(profile.personality, "清香") == 0) {
strcpy(recommended_cuisine, "浙菜");
} else if (strcmp(profile.personality, "醇厚") == 0 || strcmp(profile.personality, "色香味俱全") == 0) {
strcpy(recommended_cuisine, "徽菜");
} else if (strcmp(profile.personality, "咸香") == 0 || strcmp(profile.personality, "酸辣") == 0) {
strcpy(recommended_cuisine, "湘菜");
} else if (strcmp(profile.personality, "新奇") == 0 || strcmp(profile.personality, "荤香") == 0) {
strcpy(recommended_cuisine, "闽菜");
} else {
printf("很抱歉,系统还在适应你的习惯\n");
return; // 如果性格不匹配任何菜系,则返回。
}
printf("推荐的菜系为:%s\n", recommended_cuisine); // 输出推荐的菜系。
DISH recommended[SIZE];//定义结构体数组
for (int i = 0; i < dish_count; i++) {
if (dishes[i].score >= 5 && strcmp(dishes[i].cuisine, recommended_cuisine) == 0 ) {
// 假设评分大于等于5且复合用户口味为好菜
recommended[count++] = dishes[i];
}
}
if (count > 0) {
printf("推荐的菜品有:\n");
for (int i = 0; i < count && i<3; i++) {//推荐三道好菜
printf("%d. %s %s- 评分:%d\n", i + 1, recommended[i].name, recommended[i].cuisine, recommended[i].score);
}
} else {
printf("没有推荐的菜品。\n");
}
system("pause");
}