创建一个person类

来源:百度知道 编辑:UC知道 时间:2024/06/08 00:52:40
创建一个person类,属性包括姓名,性别,出生日期.然后从person类生出一个教师类,新增加的属性有专业,职称和主讲课程(一门).并要求定义相应的设置性的成员函数和输出信息的成员函数.

class person
{
public:
char name;
char sex;
int birthday;
};
class teacher: public person
{
public:
char subject;
char title;
char course;

}

老大,你那样定义行吗?怎么好些成员都是char 类型,你存什么啊?

单词错了吧

#include<iostream.h>
#include<string.h>

class person
{
private:
char name[8];
char sex[4];
char birthday[20];
public:
void Setperson(char *a,char *b,char *c)
{
strcpy(name,a);
strcpy(sex,b);
strcpy(birthday,c);
}
void Printperson()
{
cout<<"姓名:"<<name<<endl;
cout<<"性别:"<<sex<<endl;
cout<<"生日:"<<birthday<<endl;
}
};

class teacher: public person
{
private:
char subject[20];
char title[10];