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