VC++小问题,很简单

来源:百度知道 编辑:UC知道 时间:2024/06/04 06:44:29
1.一个名为CPerson的类有以下属性:姓名、身份证号、性别和年龄,请用C++语言定义这个类,并为上述属性定义相应的方法。

输出结果:
Please Input a Person's Information:
Name: Bill
Identity: 2345677788666
Sex: male
Age: 35

输入的人员信息:
姓名: Bill
身份证号: 2345677788666
性别: male
年龄: 35

程序结束已销毁对象
Press any key to continue

VC6.0源程序:
#include <iostream.h>
#include <iomanip.h>

class CPerson
{
public:
CPerson();
~CPerson();
char name[20];
char identity[20];
char sex[8];
int age;
void myWrite();
void myOut();
};

CPerson::CPerson()
{
cout<<"Please Input a Person's Information:"<<endl;
}
void CPerson::myWrite()
{
cout<<"Name: ";
cin.getline(name,20);
cout<<"Identity: ";
cin.getline(identity,20);
cout<<"Sex: &