慕桂英3389331
1234567891011121314151617181920212223242526272829303132333435363738394041424344#include <iostream>using namespace std;class store{public: store(int n,int q,double p); store(){} //加上默认构造函数 void total(); static double average(); double display();private: int num; int quantity; static int SumOfQuan; double price; static double sum;} ;/*全局声明*/int store::SumOfQuan=0;double store::sum=0.0;store::store(int n,int q,double p){ num = n; quantity = q; price = p;}void store::total(){ sum = sum + quantity*price; SumOfQuan = SumOfQuan + quantity;}double store::average(){ //static 在外面不用再加 return (sum/SumOfQuan);}double store::display(){ cout<<"总收款额: "<<sum<<" 平均售价: "<<SumOfQuan<<endl; return 0.0; //返回值}int main(){ store s[3]; //这没有默认构造函数 int i = 0; for(;i<3;i++){ s[i].total(); //这里是调用函数 } s[0].display(); return 0;}