#include <iostream>
#include <cstring>
using namespace std;
class Teacher
{
public:
Teacher(int,char [],char);
void display();
private:
int num;
char name[20];
char sex;
};
Teacher::Teacher(int n,char nam[],char s)
{
num=n;
strcpy(name,nam);
sex=s;
}
void Teacher::display()
{
cout<<"num:"<<num<<endl;
cout<<"name:"<<name<<endl;
cout<<"sex:"<<sex<<endl;
}
class BirthDate
{
public:
BirthDate(int,int,int);
void display();
void change(int,int,int);
private:
int year;
int month;
int day;
};
BirthDate::BirthDate(int y,int m,int d)
{
year=y;
month=m;
day=d;
}
void BirthDate::display()
{
cout<<"birthday:"<<month<<"/"<<day<<"/"<<year<<endl;
}
void BirthDate::change(int y,int m,int d)
{
year=y;
month=m;
day=d;
}
class Professor:public Teacher
{
public:
Professor(int,char [],char,int,int,int,float);
void display();
void change(int,int,int);
private:
float area;
BirthDate birthday;
};
Professor::Professor(int n,char nam[20],char s,int y,int m,int d,float a):
Teacher(n,nam,s),birthday(y,m,d),area(a){ }
void Professor::display()
{
Teacher::display();
birthday.display();
cout<<"area:"<<area<<endl;
}
void Professor::change(int y,int m,int d)
{
birthday.change(y,m,d);
}
int main()
{
Professor prof1(1001,"wei",'M',1996,8,1,130);
cout<<endl<<"original data:"<<endl;
prof1.display();
cout<<endl<<"new data:"<<endl;
prof1.change(1996,5,6);
prof1.display();
return 0;
}
5.10
最新推荐文章于 2024-06-03 15:54:48 发布