部分源码
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_RESTAURANTS 100
#define MAX_USERS 100
//企鹅联系--------------3765140556
// 定义结构体
typedef struct {
int CommentId;
int UserId;
int restaurantId;
char restaurantName[50];
char time[50];
char comment[100];
int rating;
char content[100];
char username[50];
} Comment;
typedef struct {
int restaurantId;
char name[50];
char introduction[100];
char phone[20];
char address[100];
int isOpen;
char openingHours[50];
int rating;
char description[200];
} Restaurant;
typedef struct {
int id;
char name[50];
char description[100];
char cuisine[50];
char type[50];
int weight;
float price;
} Dish;
typedef struct {
int age;
int UserId;
char username[50];
char name[50];
char password[50];
char realName[50];
char phone[20];
char hobby[50];
char address[100];
char remark[100];
char note[200];
} User;
// 初始化数据
Restaurant restaurants[100];
int restaurantCount = 0;
Dish dishes[1000];
int dishCount = 0;
User users[100];
int userCount = 0;
Comment comments[1000];
int commentCount = 0;
// 函数声明
//餐厅模块
void addRestaurant(Restaurant* restaurants, int* count);
void deleteRestaurant(Restaurant* restaurants, int* count);
void searchRestaurant(Restaurant* restaurants, int count);
void updateRestaurant(Restaurant* restaurants, int count);
void displayAllRestaurants(Restaurant* restaurants, int count);
void saveRestaurantsToFile(Restaurant* restaurants, int count);
void loadRestaurantsFromFile(Restaurant* restaurants, int* count);
//菜品模块
void addDish(Dish* dishes, int* count);
void deleteDish(Dish* dishes, int* count);
void searchDish(Dish* dishes, int count);
void updateDish(Dish* dishes, int count);
void saveDishesToFile(Dish* dishes, int count);
void displayAllDishes(Dish* dishes, int count);
void displayDishCount(int count);
void loadDishesFromFile(Dish* dishes, int* count);
//用户模块
void addUser(User* users, int* count);
void deleteUser(User* users, int* count);
void searchUser(User* users, int count);
void updateUser(User* users, int count);
void saveUsersToFile(User* users, int count);
void loadUsersFromFile(User* users, int* count);
//评价模块
void addComment(Comment* comments, int* commentCount, User* users, int userCount, Restaurant* restaurants, int restaurantCount);
void deleteComment(Comment* comments, int* count);
void searchComment(Comment* comments, int count);
void updateComment(Comment* comments, int count);
void saveCommentsToFile(Comment* comments, int count);
void printAllComments(Comment* comments, int commentCount);
void loadReviewsFromFile(Comment* comments, int* commentCount);
// 主函数
int main()
{
// 读取文件数据到结构体数组中
loadRestaurantsFromFile(restaurants, &restaurantCount);
// 读取用户数据文件
loadUsersFromFile(users, &userCount);
// 读取用户评价数据文件
loadReviewsFromFile(comments, &commentCount);
// 读取菜品数据文件
loadDishesFromFile(dishes, &dishCount);
while(1){
// 菜单界面
while (1) {
printf("********** 餐饮菜品评价管理系统 **********\n");
printf("* 1. 菜品管理 *\n");
printf("* 2. 用户评价管理 *\n");
printf("* 3. 餐厅管理 *\n");
printf("* 4. 用户管理 *\n");
printf("* 0. 退出系统 *\n");
printf("******************************************\n");
printf("请输入功能编号:");
int choice;
scanf("%d", &choice);
switch (choice) {
case 1:
// 菜品管理子模块
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("* 7. 显示菜品数量 *\n");
printf("* 0. 返回上级菜单 *\n");
printf("*****************************************\n");
printf("请输入功能编号:");
int dishChoice;
scanf("%d", &dishChoice);
switch (dishChoice) {
case 1:
addDish(dishes, &dishCount);
break;
case 2:
deleteDish(dishes, &dishCount);
break;
case 3:
searchDish(dishes, dishCount);
break;
case 4: