#include <iostream.h>
class person
{
protected:
int no;
char name[8];
public:
void getdata()
{
cout << " 编号:";
cin >> no;
cout << " 姓名:";
cin >> name;
}
void dispdata()
{
cout << " 编号:" << no << endl;
cout << " 姓名:" << name << endl;
}
};
class teacher : public person
{
protected:
char prof[10];
char depart[10];
public:
void getdata()
{
cout << "输入一个教师数据:" << endl;
person::getdata();
cout << " 职称:";
cin >> prof;
cout << " 教研室:";
cin >> depart;
}
void dispdata()
{
cout << "输出一个教师数据:" << endl;
person::dispdata();
cout << " 职称:" << prof << endl;
cout << " 教研室:" << depart << endl;
}
};
class student : public person
{
protected:
char sex[2];
char cname[10];
public:
void getdata()
{
person::getdata();
cout << "性别:";
cin >> sex;
cout << " 班号:";
cin >> cname;
}
void dispdata()
{
person::dispdata();
cout << "性别:" << sex << endl;
cout << " 班号:" << cname << endl;
}
};
class unstudent:public student
{
private:
int degree1;
int degree2;
int degree3;
public:
void getdata()
{
cout << "输入一个大学生数据:" << endl;
student::getdata();
cout << " 英语:";
cin >> degree1;
cout << " 高等数学:";
cin >> degree2;
cout << " 数据结构:";
cin >> degree3;
}
void dispdata()
{
cout << "输出一个大学生数据:" << endl;
student::dispdata();
cout << " 英语:" << degree1 << endl;
cout << " 高等数学:" << degree2 << endl;
cout << " 数据结构:" << degree3 << endl;
cout << " 平均分:" << (degree1+degree2+degree2)/3 << endl;
}
};
class mistudent:public student
{
private:
int degree1;
int degree2;
int degree3;
public:
void getdata()
{
cout << "输入一个中学生数据:" << endl;
student::getdata();
cout << " 英语:";
cin >> degree1;
cout << " 数学:";
cin >> degree2;
cout << " 语文:";
cin >> degree3;
}
void dispdata()
{
cout << "输出一个中学生数据:" << endl;
student::dispdata();
cout << " 英语:" << degree1 << endl;
cout << " 数学:" << degree2 << endl;
cout << " 语文:" << degree3 << endl;
cout << " 平均分:" << (degree1+degree2+degree2)/3 << endl;
}
};
void main()
{
teacher t;
t.getdata();
unstudent s1;
s1.getdata();
mistudent s2;
s2.getdata();
t.dispdata();
s1.dispdata();
s2.dispdata();
}