商店銷售某一商品,商店每天公佈統一的折扣(discount)

商店銷售某一商品,商店每天公佈統一的折扣(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. }  

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章