程序代码:
#include <iostream>
#include <string>
using std::cout;
using std::cin;
using std::endl;
using std::string;
class Human
{
public:
void GetName()
{
cout<<"请输入名字:";
std::getline(std::cin, thename);
}
void GetStature()
{
cout<<"请输入身高(厘米):";
cin>>stature;
}
void GetWeight()
{
cout<<"请输入体重(公斤):";
cin>>weight;
}
void PrintStature(){cout<<"身高为:"<<stature<<"厘米"<<endl;}
void PrintWeight(){cout<<"体重为:"<<weight<<"公斤"<<endl;}
void PrintName(){cout<<"姓名为:"<<thename<<endl;}
private:
string thename;
int stature;
int weight;
};
int main()
{
char GoOn='y';
Human *Xman=new Human;//定义指针对象
while(GoOn=='y')
{
Xman->GetName();
Xman->GetStature();
Xman->GetWeight();
Xman->PrintName();
Xman->PrintStature();
Xman->PrintWeight();
cout<<"是否继续输入?(y/n)";
cin>>GoOn;
if(GoOn=='n'){break;}
}
delete Xman;
return 0;
}