當前位置:編程學習大全網 - 編程軟體 - 用C++商店銷售某壹件商品,每天公布統壹的折扣(discount)。同時允許銷售人員在銷售時靈活掌握售價(price)

用C++商店銷售某壹件商品,每天公布統壹的折扣(discount)。同時允許銷售人員在銷售時靈活掌握售價(price)

#include<iostream>

using?namespace?std;

class?shop

{

public:

shop(int?q=0,double?p=0):quantity(q),price(p){};

void?total();

static?float?average();

static?float?sum;

private:

int?quantity;

double?price;

static?double?discount;

static?int?n;

};

void?shop::total()

{

int?rate=1.0;

if(quantity>=10)rate=0.98*rate;

sum=sum+price*rate*discount*quantity;

n=n+quantity;

}

float?shop::average()

{

return(sum/n);

}

double?shop::discount=0.9;

float?shop::sum=0;

int?shop::n=0;

int?main()

{

shop?s[3]={shop(5,23.5),

shop(12,24.56),

shop(100,21.5)};

int?i;

for(i=0;i<3;i++)

s[i].total();

cout<<"總價是"<<shop::sum<<endl;

cout<<"單價是"<<shop::average()<<endl;

return?0;

}

  • 上一篇:華中數控為何連續跌,300161為何連續跌
  • 下一篇:上網課Zoom打電話的翻譯神器
  • copyright 2024編程學習大全網