2020-11-18

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

销货员号 销货件数 销货单价
101 5 23.5
102 12 24.56
103 100 21.5

请编写程序,计算出当日次商品的总销售款以及没一件商品的平均售价。要去用静态数据成员和静态成员函数。

#include <iostream>
using namespace std;
class Product
{
public:
	Product(int m,int q,float p):num(m),quantity(q),price(p){ };
	void total();
	static float average();
	static void display();
private:
	int num;
	int quantity;
	float price;
	static float discount;
	static float sum;
	static int n;
};
void Product::total()
{
	float rate=1.0;
	if(quantity>10)
		rate=0.98*rate;
	sum=sum+quantity*price*rate*(1-discount);
	n=n+quantity;
}
void Product::display()
{
	cout<<sum<<endl;
	cout<<average()<<endl;
}
float Product::average()
{
	return (sum/n);
}
float Product::discount=0.05;
float Product::sum=0;
int Product::n=0;
int main()
{
	Product Pro[3]={Product(101,5,23.5),Product(102,12,24.56),Product(103,100,21.5)};
	for(int i=0;i<3;i++)
		Pro[i].total();
	Product::display();
	return 0;
}

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

STRUGGLE_xlf

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

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

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

打赏作者

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

抵扣说明:

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

余额充值