当前位置:首页 » 编程语言 » C语言点餐系统打印购物清单
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

C语言点餐系统打印购物清单

发布时间: 2023-05-08 13:25:24

❶ 用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语言编写点菜系统

简单的点菜系统,可供学习:
#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语言实现超市POS系统购买商品(名称单价数量)(不超过50样商品)购买清单输入总金额统计结算清单

语言实现超市POS系统购买商品(名称单价数量)(不超过50样商品

❺ C语言编写“超市结账系统” 急急急!!!

#include
<stdio.h>
#include
<fstream>
#include
<iostream>
#include
<string>
#include
<vector>
#include
<assert.h>
using
namespace
std;
//
Item
info
base
class
class
ItemInfo{
public:
ItemInfo(){}
ItemInfo(string
barcode,
string
name,
float
price)
{
this->barcode
=
barcode;
this->name
=
name;
this->price
=
price;
}
ItemInfo(string
barcode)
{
this->barcode
=
barcode;
}
void
Display()
{
cout
<<
barcode
<<"\t"<<name<<"\t"<<price<<
endl;
}
void
Input()
{
cout
<<
"输入条形码:"
<<
endl;
cin
>>
barcode;
cout
<<
"输入名称:"
<<
endl;
cin
>>
name;
cout
<<
"输入价格:"
<<
endl;
cin
>>
price;
}
void
Modify()
{
cout
<<
"输入名称:"
<<
endl;
cin
>>
name;
cout
<<
"输入价格:"
<<
endl;
cin
>>
price;
}
friend
ostream&
operator<<(ostream&
stream,
ItemInfo&
item){
stream
<<
item.barcode
<<'\t'<<
item.price
<<'\t'<<
item.name<<endl;
return
stream;
}
friend
istream&
operator>>(istream&
stream,
ItemInfo&
item){
stream
>>
item.barcode
>>
item.price
>>
item.name;
return
stream;
}
public:
string
barcode;
string
name;
float
price;
};
//
Interface
class
class
DataProvider{
public:
virtual
void
GetFullData(string
barcode,
string&
name,
float&
price)
=
0;
};
//
Purchase
item
class
class
ItemPurchaseInfo
:
public
ItemInfo{
public:
ItemPurchaseInfo():ItemInfo(){}
ItemPurchaseInfo(string
barcode,
int
count=1)
:
ItemInfo(barcode)
{
this->count
=
count;
}
//
Rember
to
call
this
when
barcode
set
void
GetFullData(DataProvider&
aPro)
{
aPro.GetFullData(barcode,
name,
price);
}
void
Input()
{
cout
<<
"输入条形码:"
<<
endl;
cin
>>
barcode;
cout
<<
"输入数量:"
<<
endl;
cin
>>
count;
}
void
Display()
{
cout
<<
barcode
<<"\t"<<name<<"\t"<<price<<"\t"<<count<<
endl;
}
public:
string
barcode;
int
count;
};
//
Item
list
class
class
ItemList
{
public:
ItemList(){items.clear();}
friend
ostream&
operator<<(ostream&
stream,
ItemList&
list){
unsigned
int
count
=
list.items.size();
stream
<<count<<endl;
for(unsigned
int
i(0);i<count;i++)
stream<<
list.items.at(i);
return
stream;
}
friend
istream&
operator>>(istream&
stream,
ItemList&
list){
unsigned
int
count(0);
stream
>>count;
list.items.clear();
for(unsigned
int
i(0);i<count;i++){
ItemInfo
item;
stream
>>
item;
list.items.insert(list.items.end(),
item);
}
return
stream;
}
void
Add(ItemInfo
item)
{
items.insert(items.end(),
item);
}
void
Modify()
{
string
barcode;
cout
<<
"输入条形码:"
<<
endl;
cin
>>
barcode;
for(unsigned
int
i(0);i<items.size();i++)
{
if(items.at(i).barcode
==
barcode
)
{
items.at(i).Modify();
}
}
}
public:
vector<ItemInfo>
items;
};
//
Purchase
item
list
class
class
PurchaseItemList
{
public:
PurchaseItemList(){items.clear();}
void
Add(ItemPurchaseInfo
item)
{items.insert(items.end(),
item);}
public:
vector<ItemPurchaseInfo>
items;
};
//
Implements
the
interface
class
class
Cashier
:
public
DataProvider
{
public:
Cashier()
:
purchase(),
stock(){}
~Cashier(){}
public:
//
User
funcs
void
CheckIn(){
purchase.items.clear();
int
opt(0);
do
{
unsigned
int
i(0);
ItemPurchaseInfo
ipi;
ipi.Input();
purchase.Add(ipi);
cout
<<
"按0退出,任意键继续"
<<
endl;
cin
>>
opt;
}
while(opt);
}
void
CheckOut(){
for(unsigned
int
i(0);
i
<
purchase.items.size();
i++)
{
purchase.items.at(i).GetFullData(
*this
);
}
float
checkin(0);
cout
<<
"输入收款数:"
<<
endl;
cin
>>
checkin;
DisplayList(checkin);
}
void
Display()
{
cout
<<
endl<<"商品清单
"<<
stock.items.size()
<<
endl;
cout
<<"--------------------------------------"
<<
endl;
for(unsigned
int
i(0);i<
stock.items.size();
i++){
stock.items.at(i).Display();
}
cout
<<"--------------------------------------"
<<
endl;
}
void
DisplayList(float
checkin)
{
cout
<<
endl<<"购物小票清单"
<<
endl;
cout
<<"--------------------------------------"
<<
endl;
float
total(0.0);
for(unsigned
int
i(0);
i
<
purchase.items.size();
i++)
{
purchase.items.at(i).Display();
total
+=
purchase.items.at(i).price
*
purchase.items.at(i).count;
}
cout
<<"--------------------------------------"
<<
endl;
cout
<<"货款合计:"<<
total
<<
"元"
<<
endl;
cout
<<"收款数:"<<
checkin
<<
"元"
<<
endl;
float
change(checkin-total);
assert(
change
>=
0.0);
cout
<<"找零:"<<
change
<<
"元"
<<
endl<<
endl;
}
friend
ostream&
operator<<(ostream&
stream,
Cashier&
c){
stream
<<
c.stock;
return
stream;
}
friend
istream&
operator>>(istream&
stream,
Cashier&
c){
c.stock.items.clear();
stream
>>
c.stock;
return
stream;
}
public:
//
interface
func
void
GetFullData(string
barcode,
string&
name,
float&price)
{
//
go
through
stock
and
find
the
item
by
barcode
matching
for(unsigned
int
i(0);
i
<
stock.items.size();
i++)
{
if(stock.items.at(i).barcode
==
barcode)
{
name
=
stock.items.at(i).name;
price
=
stock.items.at(i).price;
}
}
}
public:
PurchaseItemList
purchase;
ItemList
stock;
};
int
main()
{
int
opt(0);
Cashier
cashier;
ifstream
fin("data.bin",
ios::in
|
ios::binary);
fin.seekg(0,
ios::beg);
//cashier.stock.Load(fin);
fin
>>
cashier;
fin.close();
ofstream
fout;
ItemInfo
item;
do{
cout
<<
"1.
新购买"
<<
endl;
cout
<<
"2.
输入新商品信息"
<<
endl;
cout
<<
"3.
修改商品信息"
<<
endl;
cout
<<
"4.
显示商品信息"
<<
endl;
cout
<<
"0.
退出"
<<
endl;
cin
>>
opt;
switch(opt)
{
case
1:
cashier.CheckIn();
cashier.CheckOut();
break;
case
2:
item.Input();
cashier.stock.Add(item);
fout.open("data.bin",
ios::out|
ios::binary);
fout.seekp(0,ios::beg);
fout
<<
cashier;
fout.close();
break;
case
3:
cashier.stock.Modify();
fout.open("data.bin",
ios::out|
ios::app
|
ios::binary);
fout
<<
cashier;
fout.close();
break;
case
4:
cashier.Display();
break;
default:
break;
}
}
while(opt);
return
0;
}

❻ C语言实习,餐厅点菜系统程序代码!

#include<stdio.h>
#include<stdlib.h>
#defineROW12
#defineCOL12
#defineROW2COL1
#defineCOL24
intmain(void)
{
intarr1[ROW1][COL1]=
{
{1,2},
{3,4}
},
arr2[ROW2][COL2]=
{
{1,2,1,2},
{1,2,1,2}
},
arr3[ROW2][COL2],i,j,k;
for(i=0;i<ROW1;i++)
{
for(j=0;j<COL2;j++)
{
arr3[i][j]=0;
for(k=0;k<ROW2;k++)
{
arr3[i][j]+=arr1[i][k]*arr2[k][j];
}
}
}
for(i=0;i<ROW2;i++)
{
for(j=0;j<COL2;j++)
{
printf("%-3d",arr3[i][j]);
}
printf(" ");
}
system("pause");
return(0);
}

❼ 想象超市中,一个顾客结帐的情况。编写一个程序,计算他购物的总额,并打印输出结果。

想想什么啊????
顾客说“你在干什么呢??”
收款员说“我在编一个程序给你结算阿~!”
顾客说“哦,那你算出来了吗?”
收款员说“尊敬的顾客,您应付0元钱”
顾客说“太好了~!谢谢你~!”
收款员说“不用谢,欢迎下次光临~!”

❽ c语言编程,这个程序怎么写

只要输出在屏幕上么

#include <stdio.h>
#define PRICE 1.5
main()
{
int n;
double s;
printf("请输入你购买产品数量(单位:瓶):");
scanf("%d",&n);
printf("请输入你支付的现金(单位:元):");
scanf("%lf",&s);
printf("购货清单\n");
printf("---------------------------------------------------------\n");
printf("商品名称\t数量\t小计\n");
printf("矿泉水\t%d\t%.2lf\n",n,n*PRICE);
printf("---------------------------------------------------------\n");
printf("总计\t%.2lf\n",n*PRICE);
printf("支付金额:%.2lf\n",s);
printf("找零:%.2lf\n",s-n*PRICE);
}