当前位置:首页 » 编程语言 » 用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;
}要注扒迟意加括号啊