当前位置:首页 » 编程语言 » 超市购物金额的c语言
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

超市购物金额的c语言

发布时间: 2023-05-19 18:29:51

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

Ⅱ 求助,简单的C程序编写 商场购物,每满100元减20元,每满500,再减20,如购物770元,实付

#include<stdio.h>

int main(void)
{
int money;
printf("请输入购物消费金额.\n");
scanf("%d",&money);
int result=0;
result=money-money/100*20-money/500*20;
printf("实际付款金额为:%d",result);
printf("\n");
return 0;
}

这么简单的程序看得懂吧,不需要我说明吧

Ⅲ c语言 用chile和do chile编写一个超市购物结账价格的程序

#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()
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()
void Add(ItemPurchaseInfo 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语言for语句循环结构(求小明应付金额具体如题!!)

/*c语言for语句循环结构(求小明应付金额解答如下!!)*/
#include<stdio.h>
main()/*缺省值*/
{
inta;
烂颤脊floatb[100],sum;/*分配数组*/
printf("购买物品总量: ");
scanf("%d",&a);
for(i=0;i<a;++i)/*for语句的应用*/
{
printf("每个物品的价格:洞带 ");
scanf("%.1f",&b[i]);
sum+=b[i];
}
if(sum<300)/*条件判断*/
饥渗{
printf("应付款:%.1f",sum);
}
elseif(sum>=500)
{
printf("应付款:%.1f",sum*0.8);
}
else
printf("应付款:%.1f",sum*0.9);
}

Ⅳ 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/>...

Ⅵ c语言编程超市促销,满200送40,键盘输入客户购买总金额,屏幕输出返送的金额数

#include<stdio.h>
void main()
{
int money,back=0;
printf("请输入客户购买慧知总金扮碧亏额:\n");
scanf("%d",&money);
if(money>0)
back=money/200*40;
printf("厅神返送的金额数为:%d\n",back);
}

Ⅶ c语言 如何用switch语句编写一个有关商场购物金额优惠的选择程序

#include <stdio.h>

int main(int argc, char** argv)
{
int amount = 0;
scanf("%d", &amount);//输入顾客购买的总额
int status = amount/1000;
switch (status)
{
case 0: break;
case 1: amount = amount * 0.95; break;
case 2: amount = amount*0.90; break;
case 3: amount *= 0.85; break;
default: amount *= 0.80; break;
}
printf("%d\n", amount);//打印出打折后的总额

return 0;
}

Ⅷ 运用c语言程序写一个超市收银情况

#include <stdio.h>
#include <stdlib.h>
#define DIS 0.7
typedef struct buyrecond{
int id; //序号
char name[20]; //商品名称
float unitprice; //单价
int num; //数量

} BuyRecond;

typedef struct buylist{
BuyRecond *list;
int maxSize;
int size;
} BuyList;
//建立线性表
BuyList *createList(int maxsize);
void destroyList(BuyList *list);
//向表内添加元素
int appendRecond(BuyList *list,BuyRecond *recond);
//显示线性表
void displayList(BuyList *list);
int main()
{
int e;
BuyList *buyTab;
buyTab = createList(3);
e=1;
while(e!=0){
BuyRecond rec;
printf("输入第%d种商品名称(输入-1结束输入):",e);
gets(rec.name);
if(rec.name[0]=='-' && rec.name[1]=='1' && rec.name[2]=='\0')
break;
printf("输入第%d种商品单价:",e);
scanf("%f",&rec.unitprice);
printf("输入第%d种商品数量:",e);
scanf("%d",&rec.num);
getchar();
if(!appendRecond(buyTab,&rec))
break;
}
displayList(buyTab);
destroyList(buyTab);
getchar();
return 0;
}

BuyList *createList(int maxsize)
{
BuyList *pl = (BuyList *)malloc( sizeof(BuyList) );
pl->list = (BuyRecond *)calloc(maxsize, sizeof(BuyRecond));
pl->size = 0;
pl->maxSize = maxsize;
return pl;
}
void destroyList(BuyList *list)
{
free( list->list );
free( list );
}
int appendRecond(BuyList *list,BuyRecond *recond)
{
if(list->size == list->maxSize){

BuyRecond *p = (BuyRecond *)calloc(list->size * 2, sizeof(BuyRecond));
if(p==NULL){
printf("内存分配失败!无法添加元素。\n");
return 0;
}
memcpy(p, list->list, list->size*sizeof(BuyRecond));
list->maxSize = list->size * 2;
free(list->list);
list->list = p;
}
recond->id=list->size+1;
list->list[list->size]=*recond;
list->size++;
return 1;
}
void displayList(BuyList *list)
{
int i;
float x;
printf("\n%-4s %c%-20s %10s %10s %10s %10s\n",
"项次",'|',"商品名称","单价","数量","小计","优惠价");
for(i=0;i<list->size;++i){
x=(list->list[i].num)*(list->list[i].unitprice);
printf("%-4d %c%-20s %10.0f %10d %10.2f %10.2f\n",
list->list[i].id,'|',list->list[i].name,
list->list[i].unitprice,list->list[i].num,
x,x*DIS);
}
printf("总计(%d项)\n",list->size);
}