文档介绍:#include <iostream>
#include <fstream>
#include <>
#include <iomanip>
#include <string>
using namespace std;
//***********************************************************************************************************************
//***************************** 定义一个人类***************************************************************************
class Person
{
protected:
int age;
string name;
string sex;
public:
Person() { name="小强"; age=19; sex="男"; }
Person(string n) { name=n; }
Person(string n,int a,string s) { name=n; age=a; sex=s; }
void setname() { cin>>name; }
void setsex();
void setage();
bool isname(string s) { if(name==s) return true;else return false; }
bool issex(string s) { if(sex==s) return true;else return false; }
bool isage(int s) { if(age==s) return true;else return false; }
bool biage(int a,int b) { if(age>=a&&age<=b) return true;else return false; }
string outname() { return name; }
string outsex() { return sex; }
int outage() { return age; }
virtual void showStatus()=0;
virtual void play()=0;
void showPerson();
};
void Person::setsex()
{
bool bo=true;
while(bo)
{
string t[]={"男","女","man","woman"};
cin>>sex;
for(int i=0;i<4;i++)
{
if(sex==t[i]) { bo=false; break; }
}
if(bo) cout<<"请输入(男或女;man or woman)"<<endl;
}
}
void Person::setage()
{
while(true)
{
bool boo=true;
char a[4];
cin>>a;
for(int i=0;a[i];i++)
{
if(!( ((int)a[i]) >47 && ((int)a[i])<58 )) { cout<<"年龄是纯数字的!\n请重新输入:"; boo=false; break; }
}
if(boo)
{ age=atoi(a);
if(age>151||age<=0)
cout<<"请输入一个大于0小于150的数"<<endl;
else break;
}
}
}
void Person::showPerson()
{
cout<<"姓名:"<<name<<endl;
cout<<"年龄:"<<age<<endl;
cout<<"性别:"<<sex<<endl;
}
//***********************************************************************************************************************
//****************************定义一个教师类,从人公有继承**************************************************************