商店销售某一商品,商店每天公布统一的折扣(discount)。同时允许销售人员

在销售时灵活掌握售价(price),在此基础上,对一此购10件以上者,还可以享受9.8折优惠,现已知当天3名销售员销售情况为:

售货员号(num) 售货件数(quantity)售货单价(price)

       101                      5                    23.5

       102                     12                   24.56

       103                    100                  21.5

 

 

  1. #include<iostream>  
  2. using namespace std;  
  3.  
  4. class Shop  
  5. {  
  6. public:  
  7.     Shop(int m,int q,float p):num(m),quantity(q),price(p){};  
  8.     void zongjia();  
  9.     static float average();  
  10.     static void display();  
  11. private:  
  12.     int num;//人员号码  
  13.     int quantity;//件数  
  14.     float price;//单价  
  15.     static float discount;//每天折扣  
  16.     static float sum;//总金额  
  17.     static int n;//总件数  
  18. };  
  19. void Shop::zongjia()  
  20. {  
  21.     float rate=1.0;  
  22.     if(quantity>10)rate=0.98*rate;  
  23.     sum=sum+quantity*price*rate*(1-discount);  
  24.     n=n+quantity;  
  25. }  
  26. void Shop::display()  
  27. {  
  28.     cout<<sum<<endl;  
  29.     cout<<average()<<endl;  
  30. }  
  31. float Shop::average()  
  32. {  
  33.     return (sum/n);  
  34. }  
  35. float Shop::discount=0.05;  
  36. float Shop::sum=0;  
  37. int Shop::n=0;  
  38. int main ()  
  39. {  
  40.     Shop s[3]={  
  41.         Shop(101,5,23.5),  
  42.         Shop(102,12,24.56),  
  43.         Shop(103,100,21.5)  
  44.     };  
  45.     int i;  
  46.     for(i=0;i<3;i++)  
  47.         s[i].zongjia();  
  48.     Shop::display();  
  49.     return 0;  
  50. }