为什么我的字符指针不能正常输出??
请大家给我检查一下,由于所学甚浅,我自己找不出错误来
#include<iostream>
using namespace std;
class date
{
public:
date(){year=1986;month=7;day=4;}
date(date &p);
~date(){}
void setdate(int y,int m,int d);
void setdate(date &p);
void ShowDate();
private:
int year,month,day;
};
date::date(date &p)
{
year=p.year;month=p.month;day=p.day;
}
void date::setdate(int y,int m,int d)
{
year=y;month=m;day=d;
}
void date::setdate(date &p)
{
year=p.year;month=p.month;day=p.day;
}
void date::ShowDate()
{
cout<<year<<"年"<<month<<"月"<<day<<"日"<<endl;
}
class person
{
public:
person();
person(person &p);
~person(){}
void setperson();
void showperson();
private:
int id;
char *sex;
date bir;
int card;
};
person::person()
{
id=0001;sex="male";bir.setdate(1986,7,4);card=123;
}
person::person(person &p)
{
id=p.id;
sex=p.sex;
bir.setdate(p.bir);
card=p.card;
}
void person::setperson()
{
char a[9];
int x,y,z;
cout<<"请输入员工的个人信息"<<endl;
cout<<"请输入员工的编号"<<endl;
cin>>id;
cout<<"请输入员工的性别"<<endl;
cin>>a;
sex=a;
cout<<"请输入员工的出生年月"<<endl;
cin>>x>>y>>z;
bir.setdate(x,y,z);
cout<<"请输入员工的身份证号码"<<endl;
cin>>card;
}
void person::showperson()
{
cout<<"------员工基本信息表--------"<<endl;
cout<<"编号"<<" "<<id<<endl;
cout<<"性别"<<" "<<sex<<endl;
cout<<"出生年月"<<" ";
bir.ShowDate();
cout<<"身份证号"<<" "<<card<<endl;
}
int main(void)
{
person b;
b.setperson();
b.showperson();
return 0;
}