C++习题 商品销售(商店销售某一商品,每天公布统一的折扣(discount)。同时允许销售人员在销售时灵活掌握售价(price),在此基础上,一次购10件以上者,还可以享受9.8折优惠。)

Description

商店销售某一商品,每天公布统一的折扣(discount)。同时允许销售人员在销售时灵活掌握售价(price),在此基础上,一次购10件以上者,还可以享受9.8折优惠。现已知当天m个销货员销售情况为

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

               101                                              5                            23.5

               102                                            12                            24.56

               103                                           100                           21.5
 
请编写程序,计算出当日此商品的总销售款sum以及每件商品的平均售价。要求用静态数据成员和静态成员函数。
(提示: 将折扣discount,总销售款sum和商品销售总件数n声明为静态数据成员,再定义静态成员函数average(求平均售价)和display(输出结果)。

Input

m和m个销货员销售情况

Output

总销售款sum以及每件商品的平均售价

Sample Input

3
101 5 23.5
102 12 24.56
103 100 21.5

Sample Output

2387.66
20.41

HINT

 1 #include<iostream>
 2 #include<iomanip>
 3 using namespace std;
 4 class Product
 5 {
 6 public:
 7     int n1;
 8     float s;
 9     static int n;
10     static float discount;
11     static float sum;
12     Product(){}
13  Product(int num,int quantity,float price)
14  {
15      n1=quantity;
16      if(quantity>10)
17          s=quantity*price*0.98;
18      else
19          s=quantity*price;
20      s=s*0.95;
21  }
22 void  total ()
23  {
24     sum=sum+s;
25     n=n+n1;    
26  }
27 static void display()
28 {
29     cout<<sum<<endl<<sum/n;
30 }
31 };
32 float Product::discount=0.05;
33 float Product::sum=0;
34 int Product::n=0;
35 int main()
36 {
37     const int NUM =10;
38     Product Prod[10];
39     int m,i;
40     cin>>m;
41     int num;
42     int quantity;
43     float price;
44     for(i=0; i<m; i++)
45     {
46         cin>>num>>quantity>>price;
47         Product temp(num,quantity,price);
48         Prod[i]=temp;
49     }
50     for(i=0; i<m; i++)
51         Prod[i].total();
52     cout<<setiosflags(ios::fixed);
53     cout<<setprecision(2);
54     Product::display();
55     return 0;
56 }

 

posted @ 2014-04-07 15:09  浅水戏虾sty  阅读(11304)  评论(0编辑  收藏  举报