当前位置:首页 » 编程语言 » c语言套餐点餐题目
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

c语言套餐点餐题目

发布时间: 2023-05-05 21:55:05

c语言菜单点菜并计算价格问题

输出的格式对齐你自己可以调一下,程序本身没有任何问题。
程序是在Visual Studio 2008上编译运行的。

#include "stdafx.h"
#include <iostream>
#include <vector>
#include <string>
using namespace std;

char menu[6][8][16]={
{"菜单","开胃菜","主菜","主食","饭后甜点","饮料"},
{"开 胃 菜","烧椒皮蛋","蓝莓山药墩","竹笋干炒肉","干煎野山菌","小炒黄牛肉"},
{"主 菜","菠萝古老肉","水煮鱼","茄汁基围虾","盐焗手撕鸡","红烧黄花鱼","蚝油生菜","金牌蒜香骨"},
{"主 食","三鲜水饺","手擀面","米饭"},
{"饭后甜点","草莓奶昔","冰激凌","蛋糕"},
{"饮 料","雪碧","蔬菜汁","啤酒","果汁"},
};
double price[6][8]={
{0},
{0,8,10,8,13,12},
{0,15,20,35,30,28,8,18},
{0,15,12,2},
{0,10,16,10},
{0,5,8,8,8}
};
vector<int> menuvec; //保存选了那些菜单项
vector<int> foodvec; //保存选了那些食物
vector<int> countvec; //保存每个食物都选了几份

bool dinner()
{
for(int i = 0; i < 6; i++)
{
if (i == 0)
{
cout << menu[0][i] ;
cout<<":"<<endl;
}
else
{
cout << " " << i << ".";
cout << menu[0][i] << endl;
}
}
cout <<" "<<"0点餐结束"<<endl;

int imenu = 0; //选择菜单项
cout << "请选择 ";
cin >> imenu;
if (imenu == 0)
return false;
cout << " "<< imenu << "." << menu[0][imenu] << endl;
for(int i = 1; i < 8 ; i ++)
{
if (strcmp(menu[imenu][i],"") == 0)//如果没有此项食物则退出输出
break;
cout << " "<< i << "." << menu[imenu][i] << " " << price[imenu][i] << endl;
}
cout <<" 0 返回" << endl;
int ifood = 0;//选择要点的食物
int icount = 0;//选择要点的食物的份数
cout << "请选择";
cin >> ifood ;
if (ifood == 0)
return true;
cout <<"你点的是" << menu[imenu][ifood] << ","<<"请问你要几分:";
cin >> icount;

menuvec.push_back(imenu);
foodvec.push_back(ifood);
countvec.push_back(icount);

return true;
}
int main()
{
while(dinner())
{
system("cls");
}
system("cls");
cout << "你点的菜单是:" << endl;
cout << " 菜名 "<<" 单价 "<<" 数量 " <<" 价格 "<< endl;

vector<int>::iterator menuIter = menuvec.begin();
vector<int>::iterator foodIter = foodvec.begin();
vector<int>::iterator countIter = countvec.begin();
double pricesum = 0; //计算总价钱
for(;menuIter != menuvec.end(),foodIter!= foodvec.end(),countIter != countvec.end();menuIter++,foodIter++,countIter++)
{
int menutemp = *menuIter;
cout << menu[0][menutemp];
cout << ":";
int foodtemp = *foodIter;
cout << menu[menutemp][foodtemp];
cout << " " << price[menutemp][foodtemp];
int counttemp = *countIter;
cout << " "<<counttemp;
cout << " "<< counttemp*price[menutemp][foodtemp] << endl;
pricesum += counttemp*price[menutemp][foodtemp] ;
}
cout <<"-----------------------------------------------------------------------------"<<endl;
cout << " "<<"总价是 "<< pricesum << endl;
}

Ⅱ 用C语言为学校食堂做一个点菜系统,当用户选择自己喜欢的菜,所消费的钱就能显示出来。 菜谱封面如下:

#include <stdio.h>
void main()
{
int a[4],i,j,m;
char t;
printf(”********************************* \n1.红烧肉5.0元2.炸鸡翅3.0元\n3.炒芹菜2.0元4.五香蛋1.0元\n5.退出\n********************************\n\n”);
printf(“请输入您点的菜\n”);
for(i=0;i<=3;i++)
{ scanf(“%d”,&a[i]);j=i;
if(i<=2)
{ printf(“是否继续点菜\n回复Y OR N\n”);
scanf(“%c”,&t);
if(t==Y)
continue;
else if(t==N){j=i;break;}
else {printf(“error,自动结算\n”);j=i;break;}}
}
for(i=0,m=0;i<=j;i++)
m=m+a[i];
printf(“总金额%d\n”,m);
}
//手机编写,错误难免,问题不大,多多包含

Ⅲ c语言编程实现:有30个人,其中有男人,女人,小孩,在一家餐厅消费了500元,其中每个男孩人消费3

#include main(){ int x=0,y=0,z=0; for(x=0;x

Ⅳ C语言编写点菜系统

简单的点菜系统,可供学习:
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <netdb.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#define SERVPORT 3333
#define MAXDATASIZE 100 /*每次最大数据传输量 */

int main(int argc, char *argv[])
{
int sockfd, recvbytes;
char buf[MAXDATASIZE];
struct hostent *host;
struct sockaddr_in serv_addr;
if (argc < 2)
{ fprintf(stderr,"Please enter the server's hostname!\
"); exit(1); }

if ((host=gethostbyname(argv[1]))==NULL)
{ perror("gethostbyname出错!"); exit(1); }

if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
{ perror("socket创建出错!"); exit(1); }
//初始化客户端
serv_addr.sin_family=AF_INET;
serv_addr.sin_port=htons(SERVPORT);
serv_addr.sin_addr = *((struct in_addr *)host->h_addr);
bzero(&(serv_addr.sin_zero),8);
//connect
if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(struct sockaddr)) == -1)
{ perror("connect error!"); exit(1); }
//recv
if ((recvbytes=recv(sockfd, buf, MAXDATASIZE, 0)) ==-1)
{ perror("recv出错!"); exit(1); }

buf[recvbytes] = '\\0';
printf("Received: %s",buf);
close(sockfd);
return 0;
}
客户端#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/wait.h>
#define SERVPORT 3333 /*服务器监听端口号 */
#define BACKLOG 10 /* 最大同时连接请求数 */

int main()
{
int sockfd,client_fd,sin_size; /*sock_fd:监听socket;client_fd:数据传输socket */
struct sockaddr_in my_addr; /* 本机地址信息 */
struct sockaddr_in remote_addr; /* 客户端地址信息 */
//创建一个套接字,PF_INET,流式,
if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
{ perror("socket"); exit(1); }
//初始化服务端
my_addr.sin_family=AF_INET;
my_addr.sin_port=htons(SERVPORT);
my_addr.sin_addr.s_addr = INADDR_ANY;
bzero(&(my_addr.sin_zero),8);
//将套接字地址与所创建的套接字号联系起来
if (bind(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr)) == -1)
{ perror("bind"); exit(1); }
//愿意接收连接
if (listen(sockfd, BACKLOG) == -1)
{ perror("listen"); exit(1); }

while(1)
{
sin_size = sizeof(struct sockaddr_in);
if ((client_fd = accept(sockfd, (struct sockaddr *)&remote_addr, &sin_size)) == -1)
{ perror("accept"); continue; }

printf("received a connection from %s\
", inet_ntoa(remote_addr.sin_addr));

if (!fork()) { /* 子进程代码段 */

if (send(client_fd, "Hello, you are connected!\
", 26, 0) == -1)

perror("send"); close(client_fd); exit(0); }
close(client_fd); }
return 0;
}

Ⅳ c语言点菜系统

// 下面是前期的点餐系统的基础数据维护,其它功能你可以自己尝试写,如果遇到什么问题可以提出来追问喔,相信你可以解决的(我怕代码太多提交会受字数限制)。

//mm.h头文件
#include<stdio.h>
#include<stdlib.h>
#defineMENU_NUM_MAX100//假设有100种菜式
#defineLENsizeof(structMenuInfo)
structMenuInfo
{
intID;
charMenuName[20];
floatprice;
}Menu[MENU_NUM_MAX];

/*基础数据维护*/
voidAddMenu()
{
FILE*fp;
intmenu_num;

printf(" 你要添加多少种菜?:");
scanf("%d",&menu_num);
for(inti=0;i<menu_num;i++)
{
printf(" ");//addedthisline
printf(" 请输入ID:");
scanf("%d",&Menu[i].ID);
printf(" 请输入菜名:");
scanf("%s",Menu[i].MenuName);
printf(" 请输入[%s]菜的价格:",Menu[i].MenuName);
Menu[i].price=0.0f;//initialfloatprice
scanf("%f",&Menu[i].price);
fflush(stdin);
}

if((fp=fopen("MenuInfo.dat","ab"))==NULL)//openbinaryfile
{
printf("Can'topenfile ");
exit(1);
}
for(intj=0;j<menu_num;j++)
{
if(fwrite(&Menu[j],LEN,1,fp)!=1)//writingdatatobinaryfile
printf("Errorwritingfile. ");
}
fclose(fp);//closefilepoint
}

voidDisplayMenuInfo()
{
FILE*fp;
printf(" ID菜名 价格 ");//columnheadings
if((fp=fopen("MenuInfo.dat","rb"))==NULL)//openbinaryfile
{
printf("Can'topenfile ");
exit(1);
}

inti=0;
do
{
fseek(fp,i*LEN,SEEK_SET);//movefileheadlocation
if(fread(&Menu[i],LEN,1,fp))//
{
printf(" %d%5s %5.1f元 ",Menu[i].ID,Menu[i].MenuName,Menu[i].price);
i++;
}
}while(!feof(fp));

fclose(fp);
}
voidDeleteToMenu()
{
FILE*fp;
intMenuID;
inttodelete=-1;
inti=0;
printf("请输入要删除的菜名的ID:");
scanf("%d",&MenuID);

/**/
if((fp=fopen("MenuInfo.dat","rb"))==NULL)//openbinaryfile
{
printf("Can'topenfile ");
exit(1);
}

do
{
fseek(fp,i*LEN,SEEK_SET);//movefileheadlocation
if(fread(&Menu[i],LEN,1,fp))
{
if(Menu[i].ID==MenuID)todelete=i;
i++;
}
}while(!feof(fp));
fclose(fp);

if(todelete==-1)
{
printf("AmenuwiththatIDdoesn'texist ");
}
else
{
/**/
if((fp=fopen("MenuInfo.dat","wb"))==NULL)//openbinaryfile
{
printf("Can'topenfile ");
exit(1);
}

for(intj=0;j<i;j++)
{
if(j==todelete)continue;/*skiprecordtobedeleted*/
if(fwrite(&Menu[j],LEN,1,fp)!=1)//writingdatatobinaryfile
printf("Errorwritingfile. ");
}
fclose(fp);//closefilepoint
}
}
voidFindMenu()
{
FILE*fp;
intMenuID;
boolfind_mark=false;
printf(" 请输入你要查找的菜名ID:");
scanf("%d",&MenuID);

printf(" ID菜名 价格 ");//columnheadings
if((fp=fopen("MenuInfo.dat","rb"))==NULL)//openbinaryfile
{
printf("Can'topenfile ");
exit(1);
}

inti=0;
do
{
fseek(fp,i*LEN,SEEK_SET);//movefileheadlocation
fread(&Menu[i],LEN,1,fp);//
if(Menu[i].ID==MenuID)
{
printf(" %d%5s %5.1f元 ",Menu[i].ID,Menu[i].MenuName,Menu[i].price);
find_mark=true;
break;
}

i++;
}while(!feof(fp));

if(!find_mark)printf(" 尊敬的客户:我们餐厅没有你要点的菜喔,你可以试试我们的招牌菜啊^-^. ");

fclose(fp);
}
/*基础数据维护完毕*/
//sc.cpp主文件
#include<stdio.h>
#include<stdlib.h>
#include"mm.h"
voidmain(void)
{
//AddMenu();
//DisplayMenuInfo();
//FindMenu();
}

Ⅵ 跪求c语言大神!一个简单的菜单制作

#include<stdio.h>
structmi
{
charmenuItem[20];
floatmenuPrize;
};
structmimenuList[3]=
{
{"Egg",1},
{"Rice",5},
{"Nuddle",6}
};
voidorder()//定菜算帐单
{
inti[3],j,k;
doublesum=0;
doubletexafter;
printf("");
for(j=0;j<3;j++)
{
printf(" %d.%-10s",j+1,menuList[j].menuItem);
printf("%3.1f元 ",menuList[j].menuPrize);
printf("%s要几份:",menuList[j].menuItem);
scanf("%d",&k);
i[j]=k;
}
system("cls");
printf("您已定了 ");
for(j=0;j<3;j++)
{
if(i[j]!=0)
printf("%d份%s ",i[j],menuList[j].menuItem);
}
for(j=0;j<3;j++)
sum+=menuList[j].menuPrize*i[j];
texafter=sum*1.05;
printf("Sum=%-5.2lf",sum);
printf("Texafter=%-5.2lf",texafter);
printf(" pressanykeytocontinue");
getch();
system("cls");
}

intmain()
{
inti=1,j=0;
while(i)
{
printf(" ---------Pleaseselect---------- ");
printf("---------1.菜单---------- ");
printf("---------2.点菜---------- ");
printf("---------0.退出---------- ");
scanf("%d",&i);
switch(i)
{
case1:
for(j=0;j<3;j++)
{
printf("%d.%-10s",j+1,menuList[j].menuItem);
printf("%3.1f元 ",menuList[j].menuPrize);
}getch();system("cls");break;
case2:order();break;
case0:break;
}
}
}
//新手学习,希望可以帮助你