當前位置:首頁 » 編程語言 » c語言模擬超市結賬程序填空
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

c語言模擬超市結賬程序填空

發布時間: 2022-04-24 15:42:42

1. 求一個簡單的C語言超市收銀

#include "stdio.h"
#include "math.h"
#include "windows.h"
int main()
{
float a[10] = {0};
int i = 0;
float Sum = 0;
for(i = 0 ; i < 10 ; i++)
{
scanf("%f",&a[i]);
Sum += a[i];
}
float aver = Sum / 10;
printf("%f\n",aver);
sleep(10000);
return 1;
}

2. 大一C語言:模擬超市售貨系統

  1. 給親些提示幫助吧,商品做一個結構體,包含價格,種類,庫存數量,條形碼,折扣。

  2. 超市的數據是按商品來的,和客人無關喔~超市不需要知道客人的情況,只需要知道商品的情況。

  3. 如果非要客人信息,那麼可以改成會員制度,那麼客人的結構體就是是否會員,購買日期,購買商品品種,購買數量,結賬價格。

  4. 最後還需要一個購買事件結構體,就是購買總額,結賬總額,找零總額。

  5. 接下來3大主要數據部分准備完畢,接下來就是過程編程了,就需要模擬一下購物過程來操作以上的3大數據結構就行了。


還有不懂請私信我私聊。

3. 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;
}

4. 求一個簡單的C語言超市收銀系統,最好配上流程圖

說實話,網上搜的才有可能是最詳細,最容易理解,最適合初學者的。
超市系統確實有難有易,你說要簡單的,可以,簡單到什麼程度呢?要注冊登陸么?要商品錄入么?商品信息有哪些呢,進銷存系統是不是都要包含呢?要寫文件么?最大多少商品?
這些你都不說,光說做一個系統,跟網上的那些無腦需求有什麼區別?
最想不通的是你還要流程圖...你搜搜看網路知道里要流程圖的有多少?你覺的100積分有人會費時費力的給你搞這個么?
伸手黨不可恥,可恥的是不動腦子的伸手黨。

5. C語言如何用C-Free編寫一個超市收銀軟體,就是能買東西,完了進行結賬

因為C++兼容C語言的,所以在VisualStudio2010新建一個C++項目就可以實現編寫一個C語言程序方法如下:1、電腦上安裝微軟公司的VS2010,可以從dreamspark上下載正版或通過其他途徑獲得,安裝即可。2、打開VS20103、可以通過點擊文件--新建--項目建立工程或者點擊歡迎頁的「新建項目」建立工程。4、彈出對話框,勾選「空項目」建立工程,工程名可任意填英文字元,如project1,其他不用填。5、建立工程後,在右側有一個「解決方案資源管理器」,找到源文件,右擊,再左擊添加--新建項--C++文件,這樣就在工程project1下建立了一個源文件,名稱比如為源.cpp,就可以編輯代碼了。如果你已經用其他字元編輯軟體寫好了C++源程序,也可以右擊源文件,左擊--現有項,在文件夾中找到你的源程序添加到工程下。6、編輯好了源文件,就可以運行或調試了,初學者是寫簡單的程序,所以只用一個源文件就行了。點擊調試--開始運行(不調試)就直接編譯運行,有錯誤的話系統會提示。7、如果要調試,可以點擊調試--逐語句(F10)或逐過程(F11)8、調試前點擊調試--窗口(也就是watch)可以選擇不同的顯示結果,可以顯示出變數的變化過程,方便調試。點擊「繼續」結束調試。

6. C語言編寫超市收銀系統

這里沒有商品信息,需要自己編碼添加。

#include <stdio.h>
#include <string.h>

typedef struct ln //會員信息
{
char id[20];//會員賬號
char key[20];//會員密碼
int sum;//會員積分
struct ln *next;
} member;

struct lm//商品信息
{
int id;//商品編號
char name[50];//商品名稱
int stock;//商品庫存
} goods[1000];

member *registe(member *t);//注冊;
void buy();

int main()
{
member *head=(member *)malloc(sizeof(member));
strcpy(head->id, "0"), strcpy(head->key, "0");//超市管理員
head->next=NULL;
int i, a, n, boo=0;

while(1)
{
printf(" 注冊會員請按1:\n");
printf(" 會員直接登錄請按2:\n");
printf(" 退出請按0:\n");
scanf("%d", &a);
if(a==0) break;
if(a==1) head=registe(head);
else if(a==2) boo=login(head);
if(boo) break;
}
if(a && boo==1)
{
printf(" 尊貴的會員,您登錄成功!\n");
buy();
}

printf(" 已經安全退出\n");
}

member *registe(member *t)//注冊
{
printf(" 現在開始會員注冊\n\n");
char id[20], key[20];
member *p, *q, *r;
p=t;
while(p->next) p=p->next;//尋找鏈表中最後一個結點
while(1)
{
printf(" 請輸入您注冊的賬號,密碼:\n");
scanf("%s %s", id, key);
q=t;
while(q)//判斷該賬號是否已經被注冊
{
if(strcmp(q->id, id)==0) break;
else q=q->next;
}
if(q==NULL)//賬號沒有注冊
{
r=(member *)malloc(sizeof(member));
r->next=NULL;
p->next=r;
strcpy(r->id, id);
strcpy(r->key, key);
r->sum=1000;//會員默認的積分為1000
break;
}
else printf("該賬號已被注冊,請重新輸入賬號,密碼\n");
}
printf("恭喜您,已經注冊成功。現在可以登錄了\n\n");

return t;
}

int login(member *t)//登錄
{
printf(" 現在開始登錄\n");
member *p;
char id[20], key[20];
int a, boo=0;
while(1)
{
printf(" 請輸入您的賬號,密碼:\n");
scanf("%s", id);
if(strcmp(id, "#")==0) break;
scanf("%s", key);
p=t;
while(p)
{
if(strcmp(p->id, id)==0 && strcmp(p->key, key)==0) break;
else p=p->next;
}
if(p==NULL)
{
printf("對不起,該賬號不存在或密碼錯誤。請重新登錄\n");
printf(" 退出登錄請按#\n");
}
else if(strcmp(id, "0")!=0)
{
boo=1;
break;
}
}

return boo;
}

void buy()
{
char s[20];
int n, i;
while(1)
{
printf(" 請輸入商品的編號或者名稱:\n");
scanf("%s", s);
if(strcmp(s, "0")==0) break;
if(s[0]>='1' && s[0]<='9')
{
n=atoi(s);
for(i=0; i<1000; i++)
{
if(goods[i].id==n) break;
}
if(i>=1000)
{
printf(" 商品不存在請重新輸入,退出請按0\n");
}
else
{
printf(" 您已購買成功。\n");
}
}
else
{
for(i=0; i<1000; i++)
{
if(strcmp(goods[i], s)==0) break;
}
if(i>=1000)
{
printf(" 商品不存在請重新輸入,退出請按0\n");
}
else
{
printf(" 您已購買成功。\n");
}
}
}
}

7. C語言編寫的收銀台結算程序。

//以下是參考代碼有相似結構,數據結構自己設計一下。
//如果沒參考價值,手下留情,別點不採納。

#defineMAXPARKINGPOS100
#defineMAXPRICETYPE3
#defineMAXLINE4096

structdetail
{
charnum[MAXLINE];
charname[MAXLINE];
doublepricePerHour;
time_tstart;
time_tend;
doubleperiod;
doublecost;
};

staticintcurrentParkingNum=0;
staticstructdetaildetailBuf[MAXPARKINGPOS];
staticdoublepriceBuf[MAXPRICETYPE]={11.0,22.0,33.0};

intmain(void){
charbuf[MAXLINE];
structdetail*myParking;
intiChoice,leavingIndex,i,numEexisted;
structtm*begin,*end;

while(true){
selectService:
printf("Servicetype,whatisyourchoice? 1.park 2.leave 3.exit ");
gets(buf);

if(strcmp(buf,"3")==0){
return0;
}

if(strcmp(buf,"1")==0){
//park
if(currentParkingNum==MAXPARKINGPOS){
printf("Sorry,notempty! ");
continue;
}

myParking=detailBuf+currentParkingNum;

printf("yourname: ");
gets(myParking->name);

printf("yourparkingnum: ");
gets(myParking->num);

numEexisted=0;
for(i=0;i<currentParkingNum;i++){
if(strcmp(detailBuf[i].num,myParking->num)==0){
numEexisted=1;
break;
}
}

if(numEexisted!=0){
printf("Thecar%sisin ",myParking->num);
gotoselectService;
}

selectPrice:
printf("Servicecost,whatisyourchoice? ");
for(inti=0;i<MAXPRICETYPE;i++){
printf("%d.$%.2fperhour ",i+1,priceBuf[i]);
}
gets(buf);
iChoice=atoi(buf);
if(!(iChoice>=1&&iChoice<=MAXPRICETYPE)){
printf("Yourchoiceisincorrect! ");
gotoselectPrice;
}
myParking->pricePerHour=priceBuf[iChoice-1];

time(&myParking->start);

currentParkingNum++;

printf("Parckingok! ");
}elseif(strcmp(buf,"2")==0){
//leave

printf("yourparkingnum: ");
gets(buf);

myParking=NULL;
for(i=0;i<currentParkingNum;i++){
if(strcmp(detailBuf[i].num,buf)==0){
myParking=&detailBuf[i];
leavingIndex=i;
break;
}
}

if(myParking==NULL){
printf("Cannotfindyourcar! ");
continue;
}

myParking->end=time(&myParking->end);
myParking->period=difftime(myParking->end,myParking->start);

myParking->cost=myParking->period/3600.0*myParking->pricePerHour;

printf("******CostDetails****** ");
printf("name:%s ",myParking->name);
printf("number:%s ",myParking->num);
printf("price:%.2f ",myParking->pricePerHour);

begin=localtime(&myParking->start);
strftime(buf,sizeof(buf),"%Y-%m-%d%H:%M:%S",begin);
printf("begin:%s ",buf);

end=localtime(&myParking->end);
strftime(buf,sizeof(buf),"%Y-%m-%d%H:%M:%S",end);
printf("end:%s ",buf);

printf("period:%.2fhour(s) ",myParking->period/3600.0);

printf("cost:$%.2f ",myParking->cost);
printf("service:$%.2fperhour ",myParking->pricePerHour);

for(i=leavingIndex;i<currentParkingNum;i++){
if(i+1<currentParkingNum){
detailBuf[i]=detailBuf[i+1];
}
}

detailBuf[currentParkingNum-1].cost=0.0;
detailBuf[currentParkingNum-1].end=0;
detailBuf[currentParkingNum-1].name[0]='';
detailBuf[currentParkingNum-1].num[0]='';
detailBuf[currentParkingNum-1].period=0.0;
detailBuf[currentParkingNum-1].pricePerHour=0.0;
detailBuf[currentParkingNum-1].start=0;

currentParkingNum--;

printf("Leavingok! ");
}else{
printf("Yourchoiceisincorrect! ");
continue;
}
}

return0;
}

8. 求一個簡單的C語言超市收銀系統

這里沒有商品信息,需要自己編碼添加。
#include <stdio.h>
#include <string.h>
typedef struct ln //會員信息
{
char id[20];//會員賬號
char key[20];//會員密碼
int sum;//會員積分
struct ln *next;
} member;
struct lm//商品信息
{
int id;//商品編號
char name[50];//商品名稱
int stock;//商品庫存
} goods[1000];
member *registe(member *t);//注冊;
void buy();
int main()
{
member *head=(member *)malloc(sizeof(member));
strcpy(head->id, "0"), strcpy(head->key, "0");//超市管理員
head->next=NULL;
int i, a, n, boo=0;
while(1)
{
printf(" 注冊會員請按1:\n");
printf(" 會員直接登錄請按2:\n");
printf(" 退出請按0:\n");
scanf("%d", &a);
if(a==0) break;
if(a==1) head=registe(head);
else if(a==2) boo=login(head);
if(boo) break;
}
if(a && boo==1)
{
printf(" 尊貴的會員,您登錄成功!\n");
buy();
}
printf(" 已經安全退出\n");
}
member *registe(member *t)//注冊
{
printf(" 現在開始會員注冊\n\n");
char id[20], key[20];
member *p, *q, *r;
p=t;
while(p->next) p=p->next;//尋找鏈表中最後一個結點
while(1)
{
printf(" 請輸入您注冊的賬號,密碼:\n");
scanf("%s %s", id, key);
q=t;
while(q)//判斷該賬號是否已經被注冊
{
if(strcmp(q->id, id)==0) break;
else q=q->next;
}