问答题

【说明】 本程序用于评选优秀教师和学生。当输入一系列教师或学生的记录后,将优秀学生及教师的姓名列出来。其类结构如下图所示:
【程序】 #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;} (1) }; class student: (2) { int num; public: void getnum() {cout<<"score:"; cin>>num;} bool isgood() {return (3) } }; class teacher: (2) { 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’) { (4) 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( (5) ) p[i]->printname(); }

【参考答案】

(1)virtual bool isgood()=0; (2)public base (3)(num>90)true......

(↓↓↓ 点击下方‘点击查看答案’看完整答案 ↓↓↓)