编写一个类定义形式的结构体变量people。该结构体变量包括数据成员有年龄(age)、身高(height)、体重(weight)、函数成员有进食(eating)、运动(sporting)、睡眠(sleeping)。在主函数中通过结构体变量访问类的所有成员。
#include<iostream>
using namespace std;
struct people
{
int age;//年龄
int hight;//身高
int weight;//体重
void eatting()//进食函数
{weight=weight+1;};
void sporting()//运动函数
{hight=hight+1;};
void sleeping()//睡眠函数
{
age=age+1;
hight=hight+1;
weight=weight+1;
};
}p1;
int main()
{
cout<<"请输入年龄:";
cin>>p1.age;
cout<<"请输入身高(单位:cm):";
cin>>p1.hight;
cout<<"请输入体重(单位:kg):";
cin>>p1.weight;
cout<<"调用前的结果:"<<endl;;
cout<<p1.age<<" "<<p1.hight<<" "<<p1.weight<<endl;
p1.eatting();
cout<<"调用进食函数后的结果:"<<endl;
cout<<p1.age<<" "<<p1.hight<<" "<<p1.weight<<endl;
p1.sleeping();
cout<<"调用睡眠函数后的结果:"<<endl;
cout<<p1.age<<" "<<p1.hight<<" "<<p1.weight<<endl;
p1.sporting();
cout<<"调用运动函数后的结果:"<<endl;
cout<<p1.age<<" "<<p1.hight<<" "<<p1.weight<<endl;
return 0;
}