请大侠们帮小弟看看哦 谢谢咯
#include <iostream>using namespace std;
class A
{public:
A(int n,int q,float p):num(n),quantity(q),price(p){}
void total();
static float average();
private:
int num;
int quantity;
int price;
static float sum;
static int count;
};
void A::total()
{sum+=price;
count++;}
float A::average()
{return(sum/count);
}
float A::sum=0;
int A::count=0;
int main()
{A a[3]={
A(101,5,23.5),
A(102,12,24.56),
A(103,100,21.5),
};
for(int i=0;i<=3;i++)
a[i].total();
cout<<"total="<<A::sum<<endl;
cout<<"average="<<A::average()<<endl;
return 0;
}