2021-04-24

商店销售某一商品,每天公布统一的折扣(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(输出结果)。

#include <iostream>
using namespace std;
class shop {
    int num;
    int quantity;
    double price;
    static double discount;
    static double sum;
    static int n;
    static double average;
public:
    shop(int num,int quantity,double price):num(num),quantity(quantity),price(price){}
    shop(shop& p) { num = p.num; quantity = p.quantity; price = p.price; }
    void sum_cout() {
        double x=0;
        if (quantity < 10)
            x = quantity * price;
        else
            x = quantity * price * discount;
        sum +=x;
    }
    static void average_cout(shop a, shop b, shop c) {
        average = sum / (a.quantity + b.quantity + c.quantity);
        
    }
    void display() {
        cout <<"sum="<< sum <<endl<<"average="<< average<< endl;
    }
    
};
double shop::discount = 0.98;
double shop::sum = 0;
int shop::n = 3;
double shop::average = 0;

int main()
    {
    shop a(101, 5, 23.5), b(102, 12, 24.56), c(103, 100, 21.5);
    a.sum_cout(); b.sum_cout(); c.sum_cout();
    shop::average_cout(a,b,c);
    a.display();
    return 0;
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

/十贰/

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值