商店销售某一商品,每天公布统一的折扣(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(输出结果)。
m和m个销货员销售情况
总销售款sum以及每件商品的平均售价
#include#include using namespace std; class Product { public: int nm,sl; static int n; float dj,s; static float discount,sum; Product () {nm=0;sl=0;dj=0;s=0;} Product (int num,int quantity,float price) { nm=num; sl=quantity; dj=price; if(sl>10) s=sl*dj*0.98; else s=sl*dj; s=s*0.95; } void total () { sum=sum+s; n=n+sl; } static void display() { cout<<> >m; int num; int quantity; float price; for(i=0; i >num>>quantity>>price; Product temp(num,quantity,price); Prod[i]=temp; } for(i=0; i