上机实验11:类的多态性应用.docx
《上机实验11:类的多态性应用.docx》由会员分享,可在线阅读,更多相关《上机实验11:类的多态性应用.docx(9页珍藏版)》请在第壹文秘上搜索。
1、上机实验11:类的多态性应用一、实验内容已知人类是学生类和教师类的基类,调试下面程序使之运行后输出下图结果?改写程序在主函数中使用指针数组的方式使之输出相同的运行结果。头文件People.h#pragmaonceclassCPeopIe(public:CPeopIefchar*name);CPeople(void);private:charname10;public:voiddisplay();char*getName(););程序文件People.cpp#includeStdAfx.h#includePeople.h#includeusingnamespacestd;CPeople:CPeo
2、ple(char*name)strcpy(this-name,name);)CPeople:CPeople(void)()voidCPeople:display()(nameendl;CoUt我是人,名字为:char*CPeople:getName()(returnname;)头文件Student.hftpragmaonceincludepeople.hclassCStudent:publicCPeopIe(public:CStudentfchar*name);CStudent(void);voiddisplay(););程序文件Studentxpp#includeStdAfx.h#inclu
3、deStudent.hftincludeusingnamespacestd;CStudent-CStudentfchar*name):CPeople(name)()CStudent:CStudent(void)()voidCStudent:display()(COUt我是学生,姓名为:,getName()endl;)头文件Teachenh#pragmaonce#includePeople.hclassCTeacher:publicCPeopIe(public:CTeacher(char*name);CTeacher(void);voiddisplay););程序文件TeaCher.c叩ftin
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 上机 实验 11 多态性 应用
