当前位置:网站首页>食堂用户菜品关系系统(C语言课设)
食堂用户菜品关系系统(C语言课设)
2022-07-06 21:52:00 【云琤】
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<windows.h>
//用户的相关操作
int Umanu();//用户操作列表
void Uoperate(int function);//用户的指令判定
struct Users* ReadFile(char* filename);//读取之前文件之中的用户数据
struct Users* login(struct Users* Uhead);//创建用户的操作
void reg(struct Users* Uhead);//登录操作
void writeFile(struct Users* head, char* filename);//将用户信息写入文件
void Uchange(struct Users* head);//修改用户密码
void operate();//操作列表
void SearchCook(struct cook* head);//寻找对应菜品,内部调用search和print
struct cook* search(struct cook* head);//小的搜索函数,执行指定搜索
void Write(struct cook* head, char* filename);//写入菜品数据
void Comment(struct cook* head);//评价菜品
void Add(struct cook* head);//在链表末尾加入新的菜品
void Allprint(struct cook* head);//打印链表中的全部元素
void print(struct cook* temp);//打印单个节点,作为内部工具类函数存在
void Change(struct cook* head);//修改菜品内容
struct cook* Read(char* filename);//读出存入的菜品内容
struct Users
{
char ID[21];//用户的ID
char passWord[21];//用户的密码
struct Users* next;//链表操作,指向下一个存储块
};
struct Users* login(struct Users* Uhead)
{
struct Users* newUser = (struct Users*)malloc(sizeof(struct Users));
struct Users* temp = Uhead;
printf("创建您的ID(1-20位):\n");
scanf("%s", newUser->ID);
printf("请输入您设置的密码(1-20位) :\n");
scanf("%s", newUser->passWord);
if (temp != NULL)
{
while (temp->next != NULL)
{
temp = temp->next;
}
temp->next = newUser;
temp = temp->next;
}
else
{
temp = newUser;
Uhead = temp;
}
newUser->next = NULL;
return Uhead;
}
void reg(struct Users* Uhead)
{
int a = 0;
printf("请输入您的ID :\n");
char UID[20];
scanf("%s", &UID);
struct Users* temp = Uhead;
while (temp != NULL)
{
if (strcmp(temp->ID, UID) == 0)
{
a = 1;
break;
}
else
{
temp = temp->next;
}
}
if (a != 1)
{
printf("该ID还未注册!请先注册!\n");
Sleep(1500);
int function = Umanu();
Uoperate(function);
return;
}
char passWord[20];
int flag = 1;
while (flag)
{
printf("请输入您的密码 :\n");
scanf("%s", passWord);
if (strcmp(passWord,temp->passWord)==0)
{
flag = 0;
printf("密码正确 !欢迎使用 !\n");
Sleep(1000);
return;
}
else
{
printf("密码错误 !请30秒后重试 !\n");
Sleep(30000);
}
}
}
struct Users* ReadFile(char* filename)
{
struct Users* temp = NULL;
struct Users* Uhead = temp = (struct Users*)malloc(sizeof(struct Users));;
struct Users* newUser = (struct Users*)malloc(sizeof(struct Users));
newUser->next = NULL;
FILE* fp = fopen(filename, "r");
if (fp == NULL)
{
return 0;
}
fscanf(fp, "%s\t%s\n", temp->ID, temp->passWord);
Uhead = temp;
temp->next = NULL;
while(fscanf(fp,"%s\t%s\n",newUser->ID,newUser->passWord)!=EOF)
{
temp->next = newUser;
temp = temp->next;
newUser = (struct Users*)malloc(sizeof(struct Users));
newUser->next = NULL;
}
fclose(fp);
return Uhead;
}
void destory(struct Users*Uhead)
{
char UID[21];
printf("请输入您的ID :\n");
char chioce[5];
scanf("%s", UID);
char passWord[21];
struct Users* temp = Uhead;
while (temp->ID == UID)
{
temp = temp->next;
}
printf("请输入密码 :\n");
scanf("%s", passWord);
while (passWord == temp->passWord)
{
printf("请输入您的密码 :\n");
scanf("%d", &passWord);
if (passWord == temp->passWord)
{
int flag = 1;
printf("密码正确 !确定要销毁账号吗 ?(yes/no)\n");
while (flag)
{
scanf("%s", chioce);
if (chioce == "yes")
{
flag = 0;
struct Users* n = NULL;
struct Users* p = Uhead;
n = temp->next;
while (p->next == temp)
{
p = p->next;
}
p->next = n;
free(temp);
return;
}
else if (chioce == "no")
{
flag = 0;
printf("已取消该操作 !\n");
Sleep(5);
system("cls");
int function = Umanu();
Uoperate(function);
return;
}
else
{
printf("请输入正确操作 !\n");
}
return;
}
}
else
{
printf("密码错误 !请30秒后重试 !\n");
// Sleep(30);
}
}
}
void Uchange(struct Users* head)
{
struct Users* temp = head;
printf("请输入您的ID :\n");
char ID[20];
scanf("%s", ID);
while (temp != NULL)
{
if (strcmp(ID, temp->ID) == 0)
{
char password[20];
while (1)
{
printf("请输入原本的密码 :\n");
scanf("%s", password);
if (strcmp(password, temp->passWord) == 0)
{
printf("请输入修改之后的密码 :\n");
scanf("%s", temp->passWord);
break;
}
else
{
printf("密码错误!!!输入正确后方可修改!!!\n");
Sleep(3000);
}
}
}
else
{
temp = temp->next;
}
}
}
void writeFile(struct Users* head, char *filename)
{
FILE* fp = NULL;
fp = fopen(filename, "w+");
struct Users* temp = head;
while (temp != NULL)
{
fprintf(fp, "%s\t%s\n", temp->ID, temp->passWord);
temp = temp->next;
}
fclose(fp);
}
int Umanu()
{
printf("----------------------------------------------------------------------\n");
printf("| 食堂用户菜品管理系统 |\n");
printf("|--------------------------------------------------------------------|\n");
printf("| 1.注册新用户 |\n");
printf("| 2.登录用户 |\n");
printf("| 3.修改账户密码 |\n");
printf("----------------------------------------------------------------------\n");
int function = 0;
printf("请输入指令 :\n");
scanf("%d", &function);
return function;
}
void Uoperate(int function)
{
struct Users* Uhead = (struct Users*)malloc(sizeof(struct Users));
Uhead->next = NULL;
char filename[100] = "D:\\关于学习勇敢的尝试\\食堂用户菜品管理系统\\食堂用户菜品管理系统\\用户资料";
Uhead = ReadFile(filename);
if (function == 1)
{
Uhead = login(Uhead);
printf("注册成功 !欢迎使用 !\n");
writeFile(Uhead, filename);
Sleep(5);
system("cls");
return;
}
else if (function == 2)
{
reg(Uhead);
writeFile(Uhead,filename);
}
else if (function == 3)
{
Uchange(Uhead);
writeFile(Uhead, filename);
int function = Umanu();
Uoperate(function);
}
else
{
printf("请输入正确的指令!!!\n");
int function = Umanu();
Uoperate(function);
}
}
void manu()
{
printf("----------------------------------------------------------------------\n");
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("| 8.退出系统 |\n");
printf("----------------------------------------------------------------------\n");
}
struct cook
{
char name[50];//菜名
float price;//价格
char met[150];//材料
int num = 0;//评价人数
float avecom = 0;//平均评价分数
struct cook* next;//链表操作
};
void Write(struct cook* head, char* filename)
{
FILE* fp = NULL;
fp = fopen(filename, "w");
struct cook* newUser = (struct cook*)malloc(sizeof(struct cook));
struct cook* temp = head;
while (temp != NULL)
{
fprintf(fp, "%s\t%f\t%s\t%f\t%d\n", temp->name, temp->price, temp->met, temp->avecom, temp->num);
temp = temp->next;
}
return;
}
void Comment(struct cook* head)
{
struct cook* temp = head;
struct cook* flag = search(temp);
if (flag != NULL)
{
printf("请输入您的评分 :\n");
float comment = 0;
scanf("%f", &comment);
flag->avecom = ((flag->avecom * flag->num) + comment) / (flag->num + 1);
flag->num++;
printf("评价成功!\n");
return;
}
else
{
printf("找不到对应菜品!\n");
return;
}
}
void SearchCook(struct cook* head)
{
struct cook* flag = search(head);
if (flag != NULL)
{
printf("找到了!\n");
print(flag);
}
else
{
printf("未能找到对应菜品!\n");
}
}
struct cook* search(struct cook* head)
{
struct cook* temp = head;
char name[50];
printf("请输入您要操作的菜名 :\n");
scanf("%s", name);
int flag = 0;
while (temp != NULL)
{
if (strcmp(name, temp->name) == 0)
{
flag = 1;
return temp;
}
else
{
temp = temp->next;
}
}
if (flag == 0)
{
return NULL;
}
}
void Add(struct cook* head)
{
struct cook* temp = head;
while (temp->next != NULL)
{
temp = temp->next;
}
struct cook* newCook = (struct cook*)malloc(sizeof(struct cook));
printf("请输入您想添加的菜品的具体信息(菜名/价格/材料/综合评分/评价人数) :\n");
scanf("%s", newCook->name);
scanf("%f", &newCook->price);
scanf("%s", newCook->met);
scanf("%f", &newCook->avecom);
scanf("%d", &newCook->num);
temp->next = newCook;
newCook->next = NULL;
printf("添加成功!\n");
}
void Allprint(struct cook* head)
{
struct cook* temp = head;
while (temp->next != NULL)
{
print(temp);
temp = temp->next;
}
print(temp);
return;
}
void print(struct cook* temp)
{
printf("菜名:%s\n", temp->name);
printf("价格:%0.2f\n", temp->price);
printf("材料:%s\n", temp->met);
printf("综合评分:%0.2f\n", temp->avecom);
printf("评价人数(%d)\n", temp->num);
}
void Change(struct cook* head)
{
struct cook* temp = head;
int flag = 0;
int function;
struct cook* fflag = search(head);
if (fflag == NULL)
{
printf("没有对应菜品!!!\n");
return;
}
else
{
while (1)
{
printf("请输入想修改的内容:(1.菜品名称/2.材料/3.价格)\n");
scanf("%d", &function);
if (function == 1)
{
printf("请输入新的菜名 :\n");
scanf("%s", fflag->name);
printf("修改成功!\n");
break;
}
else if (function == 2)
{
printf("请输入新的材料列表 :\n");
scanf("%s", fflag->met);
printf("修改成功!\n");
break;
}
else if (function == 3)
{
printf("请输入新的价格 :\n");
scanf("%f", &fflag->price);
printf("修改成功!\n");
break;
}
else
{
printf("请输入正确的指令!!!\n");
Sleep(10000);
}
}
}
}
struct cook* Delete(struct cook* head)
{
struct cook* temp = head;
struct cook* next = NULL;
struct cook* flag = search(head);
if (flag != NULL)
{
if (flag == head)
{
head = head->next;
return head;
}
else
{
while (temp->next != flag)
{
temp = temp->next;
}
temp->next = flag->next;
return head;
}
}
else
{
printf("未能找到对应菜品!\n");
}
}
struct cook* Create(struct cook* head)
{
struct cook* temp = head;
if (head != NULL)
{
while (temp->next != NULL)
{
temp = temp->next;
}
}
struct cook* Next = (struct cook*)malloc(sizeof(cook));
Next->next = NULL;
printf("请输入你想要录入的数据(菜名/价格/材料/综合评分/评价人数) :\n若想结束,请输入end\n");
while (1)
{
scanf("%s", Next->name);
if (strcmp(Next->name, "end") == 0)
{
break;
}
scanf("%f", &Next->price);
scanf("%s", Next->met);
scanf("%f", &Next->avecom);
scanf("%d", &Next->num);
if (temp == NULL)
{
temp = Next;
head = temp;
}
else
{
Next->next = NULL;
temp->next = Next;
temp = temp->next;
}
Next= (struct cook*)malloc(sizeof(cook));
}
return head;
}
struct cook* Read(char* filename)
{
struct cook* head = NULL;
struct cook* temp = (struct cook*)malloc(sizeof(cook));
struct cook* newCook = (struct cook*)malloc(sizeof(struct cook));
newCook->next = NULL;
FILE* fp = fopen(filename, "r");
if (fp == NULL)
{
return NULL;
}
fscanf(fp, "%s%f%s%f%d", temp->name, &temp->price, temp->met, &temp->avecom, &temp->num);
head = temp;
temp->next = NULL;
while (fscanf(fp, "%s%f%s%f%d", newCook->name, &newCook->price, newCook->met, &newCook->avecom, &newCook->num) != EOF)
{
temp->next = newCook;
temp = temp->next;
newCook = (struct cook*)malloc(sizeof(struct cook));
newCook->next = NULL;
}
fclose(fp);
return head;
}
void operate()
{
int fun = 0;
printf("请输入指令 :\n");
struct cook* Head = NULL;
char filename[100]="D:\\关于学习勇敢的尝试\\食堂用户菜品管理系统\\食堂用户菜品管理系统\\菜品资料";
struct cook* head = Read(filename);
while (scanf("%d", &fun) != EOF)
{
if (fun == 1)
{
head = Create(head);
}
else if (fun == 2)
{
head = Delete(head);
}
else if (fun == 3)
{
Change(head);
}
else if (fun == 4)
{
Allprint(head);
}
else if (fun == 5)
{
Add(head);
}
else if (fun == 6)
{
SearchCook(head);
}
else if (fun == 7)
{
Comment(head);
}
else if (fun == 8)
{
Write(head,filename);
printf("感谢您的使用!\n");
return;
}
else
{
printf("请输入正确的指令!!!\n");
}
manu();
printf("请输入指令 :\n");
}
}
int main()
{
int function = Umanu();
Uoperate(function);
system("cls");
manu();
operate();
}
该系统我主要划分为两个大模块,分别就是对于用户的操作和对于菜品的操作,对用户的操作,首先提供void Uoperate(),是用户的操作面板,之后选用if-else if-else对指令的解析和调用函数的选择都在这个操作面板,设计内容为
1、注册新用户
2、登录用户
3、修改账户密码
对于不同的指令执行不同的操作,菜品模块类似于用户模块,提供void operate()函数,是菜品的操作面板,也是对于指令的解析和选择调用函数
1、导入菜品信息
2、删除菜品信息
3、修改菜品信息
4、打印菜品信息
5、增加菜品信息
6、查找菜品信息
7、评价菜品
8、退出系统
主函数main中主要调用就是Uoperate和operate函数,对指令的读取判定和执行都在这两个函数中,这两个函数返回空类型,只负责执行函数。
此系统中还有两个结构体用来存储不同信息
struct Users
{
char ID[21];//用户的ID
char passWord[21];//用户的密码
struct Users* next;//链表操作,指向下一个存储块
};struct cook
{
char name[50];//菜名
float price;//价格
char met[150];//材料
int num = 0;//评价人数
float avecom = 0;//平均评价分数
struct cook* next;//链表操作
};该系统主要用于用户管理,此时在此段代码中一共有两个链表,一个链表用于存储用户信息,另一个链表用于存储菜品信息。此处特地减少了在主函数中的代码,主函数只负责调用四个主要函数,分别为用户操作菜单,用户操作面板,菜品操作菜单和菜品操作面板。
仍有许多方面可以改善,比如注册用户和登录用户时候密码的保密性欠缺,用户可以直接看到自己输入的密码,但是实际上应该隐藏数字,防止密码泄露。同时对于用户面板的操作比较单一,而且操作过少,应该增加部分功能,比如销毁账户和退出系统。面板颜色也可以更改,但是在如上代码中没有加入相应操作。这些都是可以在之后弥补的点。
边栏推荐
- 【自动化经验谈】自动化测试成长之路
- 未婚夫捐5亿美元给女PI,让她不用申请项目,招150位科学家,安心做科研!
- mpf2_线性规划_CAPM_sharpe_Arbitrage Pricin_Inversion Gauss Jordan_Statsmodel_Pulp_pLU_Cholesky_QR_Jacobi
- [team learning] [phase 34] Baidu PaddlePaddle AI talent Creation Camp
- EasyCVR平台接入RTMP协议,接口调用提示获取录像错误该如何解决?
- 英特尔David Tuhy:英特尔傲腾技术成功的原因
- The root file system of buildreoot prompts "depmod:applt not found"
- How to solve the problem of adding RTSP device to easycvr cluster version and prompting server ID error?
- 2022中青杯数学建模B题开放三孩背景下的生育政策研究思路
- CUDA Programming
猜你喜欢

超越Postman,新一代国产调试工具Apifox,用起来够优雅
![[coded font series] opendyslexic font](/img/5e/e1512ffe494b5d0e7d6d6765644126.png)
[coded font series] opendyslexic font

【自动化经验谈】自动化测试成长之路

This "advanced" technology design 15 years ago makes CPU shine in AI reasoning

CUDA Programming

MySQL data loss, analyze binlog log file

史上最全MongoDB之部署篇
![[OA] excel document generator: openpyxl module](/img/e3/e6a13a79ad9023cf263d1926a224b5.png)
[OA] excel document generator: openpyxl module

機器人(自動化)課程的持續學習-2022-

NFT meta universe chain diversified ecosystem development case
随机推荐
True global ventures' newly established $146million follow-up fund was closed, of which the general partner subscribed $62million to invest in Web3 winners in the later stage
How to solve the problem of adding RTSP device to easycvr cluster version and prompting server ID error?
深耕开发者生态,加速AI产业创新发展 英特尔携众多合作伙伴共聚
B站大佬用我的世界搞出卷积神经网络,LeCun转发!爆肝6个月,播放破百万
Master the secrets of software security testing methods, and pinch the security test report with your hands
广告归因:买量如何做价值衡量?
Network Security Learning - Information Collection
[team learning] [phase 34] Baidu PaddlePaddle AI talent Creation Camp
JetBrain Pycharm的一系列快捷键
buildroot的根文件系统提示“depmod:applt not found”
Highly paid programmers & interview questions. Are you familiar with the redis cluster principle of series 120? How to ensure the high availability of redis (Part 1)?
Five years of automated testing, and finally into the ByteDance, the annual salary of 30W is not out of reach
Unity3d can change colors and display samples in a building GL material
Digital chemical plants realize the coexistence of advantages of high quality, low cost and fast efficiency
软件测试之网站测试如何进行?测试小攻略走起!
接口自动化测试实践指导(中):接口测试场景有哪些
How to write a resume that shines in front of another interviewer [easy to understand]
Golang calculates constellations and signs based on birthdays
Restore backup data on GCS with br
leetcode 53. Maximum subarray maximum subarray sum (medium)