正确解答是:
/*要求设计一个基类:Person,作为学生类Student、教师类Teacher的基类,学生类中有编号、姓名、班号、成绩,
其中班号和成绩的输入和显示在Student中实现,教师数据中有编号、姓名、职称、部门,其中职称和部门的输入和显示
在Teacher类中实现,下面给出基类的成员:
Person类:
private:
int
no; //编号
char name[10]; //姓名
public:
void input();//编号和姓名的输入
void diaplay();//编号和姓名的输出
*/
#include<iostream>
#define maxsize 10
using namespace std;
class person
{
private:
int
no; //编号
char name[maxsize]; //姓名
public:
person()//编号和姓名的输入
{
cout<<"执行构造函数person"<<endl;
cout<<"请输入编号:"<<endl;
cin>>no;
cout<<"请输入姓名:"<<endl;
cin>>name;
}
void ashow()//编号和姓名的输出
{
cout<<"您输入的编号:"<<endl;
cout<<no;
cout<<"您输入的姓名:"<<endl;
cout<<name;
}
};
class student:public person
{
private:
char num[maxsize]; //班号
int
score;//分数
public:
student():person()
{
cout<<"执行构造函数student"<<endl;
cout<<"请输入班号:"<<endl;
cin>>num;
cout<<"请输入分数:"<<endl;
cin>>score;
}
void bshow()
{
ashow();
cout<<"您输入班号:"<<endl;
cout<<num;
cout<<"您输入分数:"<<endl;
cout<<score;
}
};
class teacher:public person
{
private:
char title[maxsize];//
职称
char department[maxsize]; //部门
public:
teacher():person()
{
cout<<"执行构造函数teacher"<<endl;
cout<<"请输入职称:"<<endl;
cin>>title;
cout<<"请输入部门:"<<endl;
cin>>department;
}
void cshow()
{
ashow();
cout<<"您输入的职位:"<<endl;
cout<<title;
cout<<"您输入的部门:"<<endl;
cout<<department;
}
};
void main()
{
cout<<"/////////////////////////////////////////////"<<endl;
cout<<"//////////////////////////////////////////////"<<endl;
person p1;
p1.ashow();
cout<<endl;
cout<<"/////////////////////////////////////////////"<<endl;
cout<<"/////////////////////////////////////////////"<<endl;
cout<<"------------------------学生资料------------------------"<<endl;
student s1;
s1.bshow();
cout<<endl;
cout<<"/////////////////////////////////////////////"<<endl;
cout<<"/////////////////////////////////////////////"<<endl;
cout<<"------------------------老师资料------------------------"<<endl;
teacher t1;
t1.cshow();
cout<<endl;
}