#include<iostream>
using namespace std;
class People
{
public:
People(int a,int h,int w):age(a),height(h),weight(w){}
static int n();
void Eatting();
void Sporting();
void Sleeping();
void Show();
void ShowNum();
private:
int age;
int height;
int weight;
static int num;
};
int People::num=0;
int People::n()
{
num+=1;
return num;
}
void People::Eatting()
{
weight = weight+1;
}
void People::Sporting()
{
height=height+1;
}
void People::Sleeping()
{
age=age+1;
height=height+1;
weight=weight+1;
}
void People::Show()
{
cout<<"Number"<<People::n()<<":"<<endl;
cout<<"Age:"<<age<<"years old"<<endl;
cout<<"Height:"<<height<<"cm"<<endl;
cout<<"Weight:"<<weight<<"jin"<<endl<<endl;
}
int main()
{
People a(8,120,60),b(14,156,78),c(18,170,110);
a.Eatting();
a.Sporting();
a.Sleeping();
a.Show();
b.Eatting();
b.Sporting();
b.Sleeping();
b.Show();
c.Eatting();
c.Sporting();
c.Sleeping();
c.Show();
cout<<"Number of people:"<<People::n()-1<<endl;
return 0;
}
people成长数据计算
于 2023-12-27 22:07:58 首次发布