本文实例为大家分享了C语言实现点餐系统的具体代码,供大家参考,具体内容如下
?| 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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
#include<iostream>
#include<cstring>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<cstring>
#include<conio.h>
using namespace std;
typedef struct member
{
char username[20];//用户名
char password[20];//密码
}Member;
typedef struct product
{
char name[20];//菜品名
int price;
int num;//销售数量
}Product;
/*菜单函数区*/
void menu1();/*主菜单*/
void menu2();/*管理员界面*/
void all_info();//点单信息
void member_log_up();//注册
void member_log_in_interface();//登录界面外观
int member_log_in();//登录
void check();
/*管理员菜单函数*/
void sell_info();//菜品所有信息
void password_manage();//用户名密码信息
int compare_password(char password[]);//对比密码函数
int main()
{
int flag1=1,flag_member=0,flag_admin=0;
int choice1,choice2;
while(flag1){
menu1();
printf("\n");
printf("请您选择(1-5):");
scanf("%d",&choice1);
if(choice1==1)/*会员登录*/
{
member_log_in_interface();
flag_member=member_log_in();
while(flag_member)
{
all_info();
check();
}
}
else if(choice1==2)/*会员注册*/
{
printf("\n\n\n\t\t\t正在进入用户注册界面...\n");
member_log_up();
}
else if(choice1==3)/*管理员登录*/
{
printf("请输入密码:");
char password[20]={0};
scanf("%s",password);
if(compare_password(password))
{
printf("\n\n\t\t\t\t --输入密码正确!--\n\n\t\t\t\t==正在进入管理员界面==\n");
flag_admin=1;
}
else
{
printf("\n\n\t\t\t\t --输入密码错误!--\n");
}
while(flag_admin)
{
menu2();
printf("请您选择(1-3):");
scanf("%d",&choice2);
switch(choice2)
{
case 1:password_manage();break;
case 2:sell_info();break;
case 3:flag_admin=0;break;
}
}
}
else if(choice1==4)/*退出系统*/
{
flag1=0;
}
}
printf("你已经安全退出系统!(按任意键关闭界面)\n\n\t欢迎您的再次使用!\n\n");
return 0;
}
void menu1()
{
system("color E9");
printf("\n\n");
printf("\t\t\t *=======================================*\n");
printf("\t\t\t| * - * - * Zhou Cheng - System - * - * |\n");
printf("\t\t\t| * * |\n");
printf("\t\t\t| | [1] 会员登录 | |\n");
printf("\t\t\t| * * |\n");
printf("\t\t\t| | [2] 会员注册 | |\n");
printf("\t\t\t| * * |\n");
printf("\t\t\t| | [3] 管理员登录 | |\n");
printf("\t\t\t| * * |\n");
printf("\t\t\t| | [4] 退出系统 | |\n");
printf("\t\t\t| * * |\n");
printf("\t\t\t| * - * - * - * - * - * - * - * - * - * |\n");
printf("\t\t\t *=======================================*\n");
}
void menu2()
{
printf("\n\n");
printf("\t\t\t *======================================*\n");
printf("\t\t\t| | * - * - * 管-理-员-界-面 * - * - * | |\n");
printf("\t\t\t| * * |\n");
printf("\t\t\t| | [1] 会员密码管理 | |\n");
printf("\t\t\t| * [2] 各产品销售信息 * |\n");
printf("\t\t\t| * [3] 退出管理员界面 * |\n");
printf("\t\t\t| | | |\n");
printf("\t\t\t| * - * - * - * - * -- * - * - * - * - * |\n");
printf("\t\t\t *======================================*\n");
}
int compare_password(char password[])/*管理员密码比对函数 */
{
int i,flag=1;
for(i=0;i<6;i++)
{
if(password[i]!='1'+i)flag=0;
}
return flag;
}
void member_log_up()//会员注册函数
{
Member member;
while(1)
{
printf("请输入您想创建的username(用户名):");
scanf("%s",member.username);
printf("请输入您的密码(20个字符以内):");
scanf("%s",member.password);
printf("是否确认创建(y/n):");
char ch=getch();
if(ch=='n')continue;
else if(ch=='y')
{
FILE *fp=fopen("memberInfo.txt","a+");
fprintf(fp,"%s %s ",member.username,member.password);
fclose(fp);
printf("\n您已注册成功!\n");
printf("--------正在返回大厅--------");
return ;
}
}
}
int member_log_in()
{
Member member[100];
FILE *fp=fopen("memberInfo.txt","a+");
int i=0;
while(!feof(fp))
{
fscanf(fp,"%s %s",member[i].username,member[i].password);
i++;
}
char username[20],password[20];
scanf("%s",username);
printf("\t\t\t 密码 (password):");
scanf("%s",password);
int flag=0;
for(int j=0;j<i;j++)
{
if(strcmp(username,member[j].username)==0&&strcmp(password,member[j].password)==0)
{
flag=1;
break;
}
}
return flag;
}
void member_log_in_interface()/*登入界面*/
{
printf("\n\n\n\t\t\t***================================*** \n");
printf("\t\t\t \n");
printf("\t\t\t 用户名 (username):");
}
void all_info()
{
Product product[100];
FILE *fp=fopen("productInfo.txt","a+");
int i=0;
while(!feof(fp))
{
fscanf(fp,"%s %d %d",product[i].name,&product[i].price,&product[i].num);
i++;
}
printf("编号--菜品名---------单价---\n");
for(int j=0;j<i;j++)
{
printf("%-6d%-15s%-7d\n",j+1,product[j].name,product[j].price);
}
printf("请输入想要购买的菜品编号以及数量(用空格分割):");
int num,count;
scanf("%d %d",&num,&count);
printf("此函数还没写完...\n");
printf("按任意键前往结算界面:");
char c;
scanf(" %c",&c);
}
void sell_info()
{
Product product[100];
FILE *fp=fopen("productInfo.txt","a+");
int i=0;
while(!feof(fp))
{
fscanf(fp,"%s %d %d",product[i].name,&product[i].price,&product[i].num);
i++;
}
printf("--菜品名---------单价---销售量---销售额--\n");
for(int j=0;j<i;j++)
{
printf(" %-15s%-7d%-9d%-8d\n",product[j].name,product[j].price,product[j].num,product[j].price*product[j].num);
}
printf("按任意键返回菜单:");
char c;
scanf(" %c",&c);
}
void password_manage()
{
Member member[100];
FILE *fp=fopen("memberInfo.txt","a+");
int i=0;
while(!feof(fp))
{
fscanf(fp,"%s %s",member[i].username,member[i].password);
i++;
}
printf("----用户名------------密码----------");
for(int j=0;j<i;j++)
{
printf("\n %-17s %-15s",member[j].username,member[j].password);
}
printf("按任意键返回菜单:");
char c;
scanf(" %c",&c);
}
void check()
{
printf("此函数还没写...\n");
printf("按任意键返回菜单:");
char c;
scanf(" %c",&c);
}
|
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/zhoucheng_123/article/details/106767492








发表评论
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。