當前位置:首頁 » 編程語言 » 用c語言寫出購物清單
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

用c語言寫出購物清單

發布時間: 2023-05-21 15:59:01

1. 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);
}

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

3. C語言程序

#include<bits/stdc++.h>
using namespace std;
int main()
{
// freopen("ch3_1.in","r",stdin);
// freopen("ch3_1.out","w",stdout);
int sum,m;
cin>>m;
if(0<簡清m&&m<100) cout<<早咐鏈"小禮品一份";
if(m>=100)
{
sum=m/陸孫100;
cout<<sum<<"個10元代金券"<<" "<<"小禮品一份";
}

return 0;
}

4. 關於C語言

你的程序是可以運行的舉慧搏,但是格正祥式不對
這樣改一下就好了:
#include<stdio.h>
int main()
{
int i,t;
scanf("%d",&t);
float a,c[100];
for(i=0;i<t;i++)
{
scanf("%f",&a);
if(a<1000)
c[i]=a;

if(a>=1000&&a<2000)
c[i]=a*0.95;

if(a>=2000&&a<3000)
c[i]=a*0.90;

if(a>=3000&&a<5000)
c[i]=a*0.85;

if(a>碧宏=5000)
c[i]=a*0.80;

}
for (i=0;i<t;i++)
{
printf("%.1f\n",c[i]);
}

return 0;
}

5. C語言大神

#include<stdio.h>

main()
{
intleixing=0;
doublejine=0.0;

printf("激悉****************** ");
printf("1普通客戶 ");
printf("2辯鉛攜VIP客戶 ");
printf("****************** ");
printf("請輸入客戶類型:_");
scanf("%d",&leixing);
//滿200減50;滿300減80;滿500減150;滿700減200;滿1000減300

printf("請輸入購物金額:");
scanf("%lf"攜伏,&jine);

if(jine>1000)
jine=jine-300;
else
if(jine>700)
jine=jine-200;
else
if(jine>500)
jine=jine-150;
else
if(jine>300)
jine=jine-80;
else
if(jine>200)
jine=jine-50;

if(leixing==1)
printf("該客戶為普通客戶,所需支付的實際金額為%lf元。 ",jine);

if(leixing==2)
printf("該客戶為VIP客戶,所需支付的實際金額為%lf元。 ",jine*0.9);
}

6. C語言實現超市POS系統購買商品(名稱單價數量)(不超過50樣商品)購買清單輸入總金額統計結算清單

語言實現超市POS系統購買商品(名稱單價數量)(不超過50樣商品

7. 用C語言設計一個超市購物列印系統

我自己設計了一個,你試試!操作結束後按Ctrl+z顯示清單。使用方面有什麼不懂可以問我!
#include "stdio.h"
typedef struct{
char node[100]; /*商品編號*/
char name[100];/*商品名稱*/
float price;/*商品價格*/
} datatype;

typedef struct node{
datatype food[100];
int len;/*存放商品總數*/
}SPku;

datatype Input(void)
{datatype x;<br/> scanf("%s %s %f",x.node,x.name,&x.price);<br/>首消 printf("輸入完畢!");<br/>return x;<br/>}

void create(SPku *r)
{ int i;
printf("\n輸入商品總數:");
scanf("%d",&r->len);
for(i=0;i<r->len;i++)
{printf("\n輸入商品編號 名稱 價格:"); <br/> r->food[i]=Input();<br/> }
}
int strlen(char s[])
{int i;<br/> for(i=0;i<s[i];i++);<br/> return i;<br/> }
int compare(char y[],char s[])
{int i;<br/>if(strlen(y)!=strlen(s))<br/> return 0;<br/>else<br/>轎脊 for(i=0;i<strlen(y);i++)<br/>者帆知 if(y[i]!=s[i])<br/> return 0;<br/> return 1;<br/>}

void Output(datatype f)
{
printf("\n%s %s %f",f.node,f.name,f.price);
}

int judge(SPku *r,char nd[])
{ int i;
for(i=0;i<r->len;i++)
if(compare(r->food[i].node,nd))
{ Output(r->food[i]) ;
return i;
}
return 1000;
}

main()
{SPku r,n;<br/> char nd[100];<br/> int k,j,i,y=0;<br/> printf("\n開始創建資料庫...");<br/> create(&r);<br/> printf("\n*********商品總單*********");<br/> for(i=0;i<r.len;i++)<br/> Output(r.food[i]);<br/> printf("\n**************************");<br/>while((j=getchar())!=EOF)<br/> {<br/> printf("\n掃描輸入商品的編號:");<br/> gets(nd);<br/> printf("輸入成功!");<br/> k=judge(&r,nd);<br/> if(k==1000) <br/> printf("\n無此商品...");<br/> else<br/> n.food[y++]=r.food[k];<br/> }
printf("\n*********商品清單*********");
n.len=y;
for(i=0;i<n.len;i++)
Output(n.food[i]);
}

8. c語言寫銀行交易明細

c語言寫銀行交易明擾巧細方法如下
首先打開VC++文件》》》新建
創建一個C++空白文檔先聲明頭緩仔鍵文件#include
聲明變數char *p[10]={"零","一","二","三","四","五","六","七","八","九戚罩"};
由於用到了自定義函數,所以先聲明void PrintInterger(char a[], int len);/*輸出整數部分 */void PrintDecimal(char a[],int len);/*輸出小數部分 */
函數1,用於輸出整數部分,主要是用switch case進行匹配轉換void PrintInterger(char a[], int len)。

9. C語言新手求教

#include<乎碧stdio.h>
int main(void)
{
float x,rate,p;
printf("input x:\春頃李n");
scanf("%f",&x);
if(x<300)
{
p=x;
rate=1;
}
else if(x>=300&&x<500)
{
rate=0.9;
p=x*0.9;
}
else
{
rate=0.7;
p=x*0.7;
}
printf(%f%f\n",p,rate);
return 0;
}要注扒遲意加括弧啊