Problem Description
一个教学系统至少有学生和教师两种类型的人员,假设教师的数据有教师编号、姓名、年龄、性别、职称和系别,
学生的数据有学号、姓名、年龄、性别、班级和语文、数学、英语三门课程的成绩。
现编程完成学生和教师档案数据的输入和显示。
要求如下:
设计三个类Person、Teacher、Student,Person是Teacher和Student的基类,
具有此二类共有的数据成员编号、姓名、年龄、性别,并具有输入和显示这些数据的成员函数;
Teacher类继承了Person类的功能,并增加职称和系别等数据成员和进行输入和显示的成员函数。
Student类继承了Person类的功能,并增加班级和语文、数学、英语三门课程的成绩等数据成员
及进行输入和显示的成员函数。
//你的代码将被嵌入在这里
int main() {
Teacher t1, t2(“T002”, “张华”, 33, “男”, “讲师”, “计算机系”);
Student s1, s2(“S002”, “李丽”, 19, “女”, “0309202”, 90, 92, 98);
t1.inputTeacher();
s1.inputStudent();
t1.printTeacher();
t2.printTeacher();
s1.printStudent();
s2.printStudent();
Person p = t1;
p.printPerson();
return 0;
}
Sample Input
T001 陈军 40 女 教授 电气工程 S001 向辉 28 男 0309201 99 98 97
Sample Output
num:T001 name:陈军 age:40 sex:女 title:教授 dep:电气工程 -------------------- num:T002 name:张华 age:33 sex:男 title:讲师 dep:计算机系 -------------------- num:S001 name:向辉 age:28 sex:男 classes:0309201 chinese:99 math:98 english:97 -------------------- num:S002 name:李丽 age:19 sex:女 classes:0309202 chinese:90 math:92 english:98 -------------------- num:T001 name:陈军 age:40 sex:女
#include<iostream>
#include<string>
using namespace std;
class Person
{
protected:
string num;//编号
string name;//姓名
int age;//年龄
string sex;//性别
public:
Person(string nu = "", string na = "", int ag = 0, string se = "");
void inputPerson()
{
cin >> num >> name >> age >> sex;
}
void printPerson()
{
cout << "num:" << num << endl;
cout << "name:" << name <<
endl;
cout << "age:" << age << endl;
cout<< "sex:" << sex << endl;
}
}; Person::Person(string nu,string na, int ae, string se)
{
num = nu;
name = na;
age = ae;
sex = se;
}
class Teacher:public Person
{
protected:
string title, dep;
public:
Teacher(){}
Teacher(string num,string name, int age, string sex, string title,string dep):Person(num,name,age,sex),title(title),dep(dep){}
void inputTeacher()
{
cin>>num>>name>>age>>sex>>title>>dep;
}
void printTeacher()
{
cout << "num:" << num << endl;
cout << "name:" << name <<
endl;
cout << "age:" << age << endl;
cout << "sex:" << sex << endl;
cout << "title:" << title << endl;
cout<< "dep:" << dep << endl;
cout << "--------------------" << endl;
}
};
class Student :public Person
{
protected:
string classes;
double math, chinese, english;
public:
Student(){}
Student(string num,string name,int age,string sex,string classes,double chinese,double math,double english):Person(num,name,age,sex),classes(classes),chinese(chinese),math(math),english(english){}
void inputStudent()
{
cin >> num >> name >> age >> sex;
cin >> classes;
cin >> chinese;
cin >> math;
cin >> english;
}
void printStudent()
{
cout << "num:" << num << endl;
cout << "name:" << name << endl;
cout << "age:" << age << endl;
cout << "sex:" << sex << endl;
cout << "classes:" << classes << endl;
cout<<"chinese:"<<chinese << endl;
cout << "math:" << math << endl;
cout<<"english:"<<english << endl;
cout << "--------------------" << endl;
}
};