我是靠谱客的博主 温婉季节,最近开发中收集的这篇文章主要介绍基于C语言实现点菜系统,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

本文实例为大家分享了C语言点菜系统的具体代码,供大家参考,具体内容如下

用C语言编写的简单的餐厅点菜系统,操作简单,代码不多,菜单可以自己更改,价格也是

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include"windows.h"
struct cai /*cai结构体 实现对菜品 已点份数、名称、原材料 的记录*/
{
 int fenshu;
 char name[50];
 int use;
 int price;
};
typedef int ElemType;
struct List /*该线性表实现对菜品原材料的剩余量的记录,线性表【i】对应菜品的点餐菜单编码*/
{ 
 ElemType* list;
 int size;
 int MaxSize;
};
/*以下为线性表的函数*/
void InitList(struct List* L,int ms)  
{
 if(ms<=0){printf("ms 值非法!n");exit(1);}
 L->MaxSize=ms;
 L->list=malloc(ms*sizeof(ElemType));
 if(!L->list)
 {
 printf("动态存储分配失败!");
  exit(1);
 }
 L->size=0;
}
void againMalloc(struct List *L)
{
 ElemType *p=realloc(L->list,2*L->MaxSize*sizeof(ElemType));
 if(!p){
 printf("分配存储空间失败!");
 exit(1);
 }
L->list=p;
L->MaxSize=2*L->MaxSize;
}
void InsertLastList(struct List *L,ElemType x)
{
 if(L->size==L->MaxSize)
 againMalloc(L);
 L->list[L->size]=x;
 L->size++;
}
/*表格函数*/
void cddayin(struct cai a[])
{
 int i=0,j=0,s=0;
 for(i=0;i<30;i++)
 {if(a[i].fenshu>0) j++;}
 if(j!=0)
 {
 printf("已点菜/酒品编号  已点菜品名称  已点份数/瓶数  价格n");
  for(i=0;i<30;i++)
  if(a[i].fenshu>0) 
 {printf(" %5d     %10s%14d    %d¥  n",i,a[i].name,a[i].fenshu,a[i].fenshu*a[i].price);
 s=s+a[i].fenshu*a[i].price;
 } 
  printf("           您好,您点餐价格合计=%d¥n",s);
 }
 if(j==0)
  printf("顾客尚未点餐,无法进行菜单打印!n");
}
void ycliao(struct List *yuan,struct cai a[])
{
 int i=1,p=0,k=0;
 for(i=0;i<30;i++)
 {
 do{
 p=a[i].use%100;
 yuan->list[p]=yuan->list[p]-a[i].fenshu;
 a[i].use=a[i].use/100;
 }while(a[i].use!=0);
 } 
 printf("|-------------------------------------------------------|--------------------|n");
 printf("|------------------原材料余量---------------------------|-----酒品余量-------|n");
 printf("|-------------------------------------------------------|--------------------|n");
 printf("| 10.鸡肉=%3d  11.猪肉=%3d   12.鱼肉=%3d | 50.雪花啤酒=%3d |n",yuan->list[10],yuan->list[11],yuan->list[12],yuan->list[50]);
 printf("| 13.黄瓜=%3d  14.土豆=%3d   15.豆腐=%3d | 51.燕京啤酒=%3d |n",yuan->list[13],yuan->list[14],yuan->list[15],yuan->list[51]);
 printf("| 16.茄子=%3d  17.青椒=%3d   18.牛肉=%3d | 52.二锅头=%3d  |n",yuan->list[16],yuan->list[17],yuan->list[18],yuan->list[52]);
 printf("| 19.大葱=%3d  20.鲜鸭血=%3d  21.花生=%3d |     |n",yuan->list[19],yuan->list[20],yuan->list[21]);
 printf("| 22.花椒=%3d  23.酱=%3d   24.胡萝卜=%3d |     |n",yuan->list[22],yuan->list[23],yuan->list[24]);
 printf("| 25.辣椒=%3d  26.芹菜=%3d   27.豆皮=%3d |     |n",yuan->list[25],yuan->list[26],yuan->list[27]);
 printf("|-------------------------------------------------------|--------------------|n");
 printf("|-------------------------------------------------------|--------------------|n");
}
void diancai(struct cai a[])
{ 
 int p=0,wep=0;
 do{
 printf("  |----------------------------------------------|-------------------|n");
 printf("  |----------菜品(输入-1确认并结束点餐)----------|-------酒品--------|n");
 printf("  |----------------------------------------------|-------------------|n");
 printf("  | 1.宫爆鸡丁  2.鱼香肉丝  3.京酱肉丝 | 21.雪花啤酒  |n");
 printf("  | 4.地三鲜   5.水煮鱼   6.麻婆豆腐 | 22.燕京啤酒  |n");
 printf("  | 7.夫妻肺片  8.拍黄瓜   9.鲜鸭血 | 23.二锅头  |n");
 printf("  |----------------------------------------------|-------------------|n");
 printf("  |----------------------------------------------|-------------------|n");
 scanf("%d",&p);
 system("CLS");
 if(p>=1&&p<=9)
 {
 printf("   |------------------------------------------|n");
  printf("   |------------------份数--------------------|n");
  printf("   |------------------------------------------|n");
  printf("   | 1.一份   2.两份     |n");
  printf("   | 3.三份   4.其他请直接输入  |n"); 
  printf("   |------------------------------------------|n");
  printf("   |------------------------------------------|n");
 scanf("%d",&wep);
 if(wep>50)
 {system("CLS");printf("您输入的值异常或过大,请您检查输入的值!n");continue;}/*防止误输入*/
 else if(wep<=50)
 {a[p].fenshu+=wep;
  system("CLS");
 }
 }
 else if(p>=21&&p<=23)
 {
 
  printf("   |--------------------------------------------------------|n");
  printf("   |-------------------------酒品数量-----------------------|n");
  printf("   |--------------------------------------------------------|n");
  printf("   | 1.一瓶 2.两瓶 3.三瓶 4.其他瓶数请直接输入  |n"); 
  printf("   |--------------------------------------------------------|n");
  printf("   |--------------------------------------------------------|n");
 scanf("%d",&wep);
 if(wep>50)
 {system("CLS");printf("您输入的值异常或过大,请您检查输入的值!n");continue;}/*防止误输入*/
 else if(wep<=50)
 {
 a[p].fenshu+=wep;
  system("CLS");
 }
 }
 else if(p!=-1)
 printf("对不起,你输入的编码没有对应菜品,请重新输入!n"); 
 }while(p!=-1);
 system("CLS");
 cddayin(a);
}
void ycldayin(struct List yuan,struct cai a[])
{
 char l='';
 printf("显示原材料余量?(Y/N)n");
 l=getch();
 if(l=='Y'||l=='y')
 {system("CLS");
 ycliao(&yuan,a);}
 else
 { system("CLS");
 printf("nnnn");}
} 
main()
{
 
 int i=0;
 char l='';
 struct List yuan;   /* yuan前不用加“*” */
 struct cai a[30]={
 {0,"",0},
 {0,"宫爆鸡丁",10131421,15},{0,"鱼香肉丝",1124,14},{0,"京酱肉丝",112327,16},
 {0,"地三鲜",141617,10},{0,"水煮鱼",122225,50},{0,"麻婆豆腐",152225,11},
 {0,"夫妻肺片",18212625,17},{0,"拍黄瓜",13252223,8},{0,"鲜鸭血",20,20},
 {0,"",0},{0,"",0},{0,"",0},
 {0,"",0},{0,"",0},{0,"",0},
 {0,"",0},{0,"",0},{0,"",0},
 {0,"",0},{0,"",0},
 {0,"雪花啤酒",50,5},{0,"燕京啤酒",51,6},{0,"二锅头",52,4},
 {0,"",0},{0,"",0},{0,"",0},
 {0,"",0},{0,"",0},{0,"",0}};
 InitList(&yuan,60);
  for(i=0;i<60;i++)
 InsertLastList(&yuan,100);//+rand()%50
  printf("nnnnnnnn");
  printf("   |--------------------------------------------------------|n");
  printf("   |---------------- 欢迎来到春晓点餐系统! -----------------|n"); 
  printf("   |--------------------------------------------------------|n");
 Sleep(2500);
  system("CLS");
  diancai(a);    /*点餐函数,开始点餐吧!*/
 ycldayin(yuan,a);
 printf("nnnn");
  printf("   |--------------------------------------------------------|n");
  printf("   |-------------- 欢迎再次使用春晓点餐系统! ---------------|n"); 
  printf("   |--------------------------------------------------------|n");
 printf("nnnnnn");
}

更多学习资料请关注专题《管理系统开发》。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持靠谱客。

最后

以上就是温婉季节为你收集整理的基于C语言实现点菜系统的全部内容,希望文章能够帮你解决基于C语言实现点菜系统所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(100)

评论列表共有 0 条评论

立即
投稿
返回
顶部