#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=10;
if(quantity>10)rate=0.98*rate;
sum=sum+quantity*price*(1-discount);
n=n+quantity;
}
void Product::display ()
{cout<<sum<<endl;
cout<<average()<<endl;
}
float Product::average ()
{
return(sum/n);
}
float Product::discount=0.05f;
float Product::sum=0;
int Product::n=0;
int main()
{
Product Prod[3]={Product(101,5,23.5f),Product(102,12,24.56f),Product(103,100,21.5f)};
for (int i=0;i<3;i++)
Prod[i].total();
Product::display ();
return 0;
}
呼唤远方
Helenr