#include<iostream>
using namespace std;
class aa
{
private:
int num;
int quantity;
float price;
static float discount;
static float sum;
static int n;
public:
aa(int n,int q,float p)
{
num=n;price=p;
}
void total();
static float average();
static void display();
};
void aa::total()
{
float rate=1.0;
if(quantity>10)
{
rate=rate*0.98;
}
sum=sum+quantity*price*rate*(1-discount);
n=n+quantity;
}
void aa::display()
{
cout<<sum<<endl;
cout<<average<<endl;
}
float aa::average()
{
return (sum/n*1.0);
}
float aa::discount=0.05;
float aa::sum=0;
int aa::n=0;
int main()
{
aa prod[3]={aa(101,5,23.5),aa(102,12,24.56),aa(103,100,21.5)};
for(int i=0;i<3;i++)
{
prod[i].total();
}
aa::display();
return 0;
}
c++
最新推荐文章于 2023-04-15 20:25:02 发布