某宝上的一个商家主要经销的产品为运动服装和球类,在五一节来临之际,为扩大销量,采用一定的促销手段:
1)对于运动服装采用折扣方式促销,例如八五折,即原服装售价*85%为该服装的最终售价:
2)对于球类商品采用满减方式促销,例如满200减40,买家选购的球类商品价格满200即减40,满400减80,依次类推。请根据上述描述,请你利用面向对象的编程思想,帮该商家编写一个程序,能够对买家在本店铺购买的商品自动计算应付金额。
首先看题,只有2种商品:
先使用宏定义好衣服和球的价格 如一个球 50块,一件衣服 300块
定义2个int类型,clothers和ball
然后使用公式计算
衣服总价就是 clothers单价0.85
球的话就是用公式。推导得 (球总价%200)*40为优惠价格
代码如下:
#include <iostream>
using namespace std;
#define BALL_PRICE 50
#define CLOTHERS_PRICE 300
class Shop
{
public:
Shop(int clothers,int ball){
m_clothers=clothers;
m_ball=ball;
}
Shop(){}
~Shop(){}
void Buy(int clothers,int ball)
{
m_clothers=clothers;
m_ball=ball;
}
void Show()
{
float colthersCount=m_clothers*CLOTHERS_PRICE*0.85;
int ballCount= m_ball*BALL_PRICE;
int n=ballCount/200;
float ballDiscount=(n)*40;
cout<<"Count = "<<colthersCount+ballCount-ballDiscount<<endl;
}
private:
int m_clothers=0;
int m_ball=0;
};
int main()
{
Shop shop(2,5);
shop.Show();
return 0;
}