【分析解答题】
【说明】 本程序用于评选优秀教师和学生。当输入一系列教师或学生的记录后,将优秀学生及教师的姓名列出来。其类结构如下图所示:

【程序】 #include <iostream.h> #include <stdio. h> class base{ protected: char name[8]; public: void getname(){cout<<"name:"; cin>>name;} void printname(){cout<<"name:"<<name<<endl;} {{U}} (1) {{/U}} }; class student:{{U}} (2) {{/U}} { int num; public: void getnum() {cout<<"score:"; cin>>num;} bool isgood() {return{{U}} (3) {{/U}}} }; class teacher:{{U}} (2) {{/U}} { int num; public: void getnum() {cout<<"paper:"; cin>>num;} bool isgood() {return (num>3) true:false;} void main() { base *p[50]; student *pstud; teacher *ptech; char ch; int count=0; do{cout<<"input teacher(t) or student(s):";cin>>ch;if(ch==’s’){ pstud=new student; pstud->getname(); pstud->getnum(); p[count++]=pstud;}else if(ch==’t’){ {{U}} (4) {{/U}} ptech->getname(); ptech->getnum(); p[count++]=ptech;}else cout<<"input is wrong"<<endl; cout<<"continue to iput(y/n) "; cin>>ch; }while(ch==’y’); for(int i=0;i<count;i++) if({{U}} (5) {{/U}}) p[i]->printname(); }