/*定义一个PERSON类,数据成员包括姓名、年龄、身高和体重,函数成员包括构造函数、复制构造函数、析构函数及其他必要的成员函数。
要求定义三个私有static数据成员,能够获取到PERSON类对象的平均年龄、平均身高和平均体重。
编写主函数进行结果验证。*/
#include<iostream>
#include<string>
using namespace std;
#define MAX_SIZE 10
class Person{
char name[30];
double age,height,weight;
private:
static double AveAge,AveHeight,AveWeight;
void show();
void get();
void aveage();
void aveheight();
void aveweight();
};
Person::Person(char *name,int age,double height,double weight){
strcpy(this.name,name);
this.age = age;
this.height = height;
this.weight = weight;
}
void Person::get( Person *p )
{
//cout<<"请输入姓名 年龄 身高 体重"<<endl;
cin>>p.name;
cin>>p.age;
cin>>p.height;
cin>>p.weight;
}
/*void show(){
}*/
void Person::aveage( )
{
double sum=0;
for(int i=0;i<MAX_SIZE;i++)
{
sum+=member[i].age;
}
AveAge=sum/MAX_SIZE;
cout<<"aveage="<<AveAge<<endl;
}
void Person::aveheight( )
{
double sum=0;
for(int i=0;i<MAX_SIZE;i++)
{
sum+=member[i].height;
}
AveHeight=sum/MAX_SIZE;
cout<<"aveheight="<<AveHeight<<endl;
}
void Person::aveweight( )
{
double sum=0;
for(int i=0;i<MAX_SIZE;i++)
{
sum+=member[i].weight;
}
AveWeight=sum/MAX_SIZE;
cout<<"aveweight="<<AveWeight<<endl;
}
void main() {
Person a;
Person member[MAX_SIZE];
cout<<"Please input the count of people"<<endl;
int num;
cin>>num;
for(int i=0;i<num;i++)
{
a.get(*(member+i));
}
a.aveage();
a.aveheight();
a.aveweight();
}
}