class CStudent
{
public:
CStudent(); //构造函数
~CStudent(); //析构函数
void SetAge(int nAge); //成员函数
int GetAge();
void SetHeight(int nHeight);
int GetHeight();
private:
int m_nAge; //成员变量
int m_nHeight;
};
CStudent::CStudent()
: m_nAge(18) //初始化列表
, m_nHeight(170)
{
}
CStudent::~CStudent()
{
}
void CStudent::SetAge(int nAge)
{
m_nAge = nAge;
}
int CStudent::GetAge()
{
return m_nAge;
}
void CStudent::SetHeight(int nHeight)
{
m_nHeight = nHeight;
}
int CStudent::GetHeight()
{
return m_nHeight;
}
当然是随便写个类的定义,加点构造函数和输出输入的接口
class student
{
char name[100] ;//string name
char stunum[100];//....
int age;
student(char *iname, char *istunum, int iage)
{
strcpy(name, iname);
strcpy(stunum, istunum);
age=iage;
}
void Show()
{
cout<
int GetAge() {return age;}
char * GetStunum() {return stunum;}
char * GetName() {return name;}
};
class student{
//属性
public:
char name[20];
int age;
//方法
public:
void study();
};