33,311
社区成员
发帖
与我相关
我的任务
分享
#include <iostream.h>
#include <afx.h>
class CLesson
{
private:
CString LessonName;
protected:
int LessonTime;
public:
CString Teacher;
void LessonInit(CString name,int time,CString teacher)
{
LessonName=name;
LessonTime=time;
Teacher=teacher;
}
void LessonShow()
{
cout<<"Lesson:"<<LessonName<<" Time:"<<LessonTime<<" Teacher:"<<Teacher<<endl;
}
virtual void TeacherInfo()
{
cout<<"BaseClass show "<<Teacher<<endl;
};
};
class CSubLesson : public CLesson
{
public:
void TimeInfo()
{
cout<<"Class Hour is "<<LessonTime<<endl;
}
void TimeInfo(int m)
{
cout<<"Class Hour is "<<LessonTime * m<<"分钟"<<endl;
}
void TeacherInfo()
{
cout<<"subClass show "<<Teacher<<endl;
}
};
void main()
{
CLesson lesson;
lesson.LessonInit("物理",60,"张老师");
lesson.LessonShow();
CSubLesson sublesson;
sublesson.LessonInit("化学",40,"王老师");
sublesson.LessonShow();
sublesson.TimeInfo();
sublesson.TimeInfo(45);
CLesson *l;
l=&lesson;
l->TeacherInfo();
l=&sublesson;
l->TeacherInfo();
}