當前位置:首頁 » 編程語言 » 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);
}