people成长数据计算

#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;
}

  • 8
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值