?
#include <iostream>
#include <string>
using namespace std;
enum Gender {Male, Female};
ostream& operator << (ostream& os, Gender gender) {
if (gender == Female) {
os << "Female";
}
else {
os << "Male";
}
return os;
}
class Person{
//to do
private:
string name_;
int number_;
Gender gender_;
public:
Person() {
name_ = "";
gender_ = Male;
number_ = 0;
}
Person(string name, Gender gender, int number) {
name_ = name;
gender_ = gender;
number_ = number;
}
~Person() {}
void Print() const {
cout << "姓名:" << name_ + " " << "性别:" << gender_ << " 编号:" << number_ << endl;
}
};
class Student : public Person{
//to do
private:
string faculty_;
int score_;
public:
Student() {
faculty_ = "";
score_ = 0;
}
Student(string name, Gender gender, int number, string faculty, int score) : Person(name, gender, number) {
faculty_ = faculty;
score_ = score;
}
~Student() {}
void Print() const {
Person::Print();
cout << "学院:" << faculty_ + " " << "成绩:" << score_ << endl;
}
};
class Teacher : public Person{
//to do
private:
string title_;
string department_;
public:
Teacher() {
title_ = "";
department_ = "";
}
Teacher(string name, Gender gender, int number, string title, string department) : Person(name, gender, number) {
title_ = title;
department_ = department;
}
~Teacher() {}
void Print() const {
Person::Print();
cout << "职称:" << title_ + " " << "部门:" << department_ + " " << endl;
}
};
int main()
{
Person person("王维维", Male, 1007);
Student student("李君瑞", Male, 1007,"Information Technology", 100);
Teacher teacher("童振", Male, 1007, "Professor", "Teaching Affairs");
person.Print();
student.Print();
teacher.Print();
return 0;
}
?
|