當前位置:首頁 » 編程語言 » 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;
}
}
}
//新手學習,希望可以幫助你