商店销售某一商品,商店每天公布统一的折扣(discount)。同时允许销售人员
在销售时灵活掌握售价(price),在此基础上,对一此购10件以上者,还可以享受9.8折优惠,现已知当天3名销售员销售情况为:
售货员号(num) 售货件数(quantity)售货单价(price)
101 5 23.5
102 12 24.56
103 100 21.5
- #include<iostream>
- using namespace std;
- class Shop
- {
- public:
- Shop(int m,int q,float p):num(m),quantity(q),price(p){};
- void zongjia();
- static float average();
- static void display();
- private:
- int num;//人员号码
- int quantity;//件数
- float price;//单价
- static float discount;//每天折扣
- static float sum;//总金额
- static int n;//总件数
- };
- void Shop::zongjia()
- {
- float rate=1.0;
- if(quantity>10)rate=0.98*rate;
- sum=sum+quantity*price*rate*(1-discount);
- n=n+quantity;
- }
- void Shop::display()
- {
- cout<<sum<<endl;
- cout<<average()<<endl;
- }
- float Shop::average()
- {
- return (sum/n);
- }
- float Shop::discount=0.05;
- float Shop::sum=0;
- int Shop::n=0;
- int main ()
- {
- Shop s[3]={
- Shop(101,5,23.5),
- Shop(102,12,24.56),
- Shop(103,100,21.5)
- };
- int i;
- for(i=0;i<3;i++)
- s[i].zongjia();
- Shop::display();
- return 0;
- }