my homewoke

作者在 2009-05-21 17:10:27 发布以下内容
#include<iostream>
#include<string>
using namespace std;
class Teacher
{public:
Teacher(int n,string nam,char s)
{num=n;
 name=nam;
 sex=s;
}
void display();
protected:
 int num;
 string name;
 char sex;
};
void Teacher::display()
{cout<<"num="<<num<<endl;
cout<<"name="<<name<<endl;
cout<<"sex="<<sex<<endl;}
class BirthDate
{ public:
BirthDate(int y,int m,int d)
{year=y;month=m;day=d;}
void display();
protected:
 int year;
 int month;
 int day;
};
class Professor:public Teacher,public BirthDate
{public:
Professor(int n,string nam,char s,int y,int m,int d):
Teacher(n,nam,s),BirthDate(y,m,d){}
void display();

private:

};
void Professor::display()
{cout<<"num="<<num<<endl;
cout<<"name="<<name<<endl;
cout<<"sex="<<sex<<endl;
cout<<"year="<<year<<endl;
cout<<"month="<<month<<endl;
cout<<"day="<<day<<endl;
}
int main()
{   Teacher t(123,"asd",'k');
 Professor prof1(072211101,"zhoudongdong",'man',2009,5,18);
Teacher *pt=&t;
pt->display();
pt=&prof1;
pt->display();
return 0;
}
c++ | 阅读 1631 次
文章评论,共0条
游客请输入验证码
浏览1631次
文章分类
文章归档
最新评论