#include<iostream>
#include<fstream>
#include<string>
using namespace std;
// 定义Person类
class Person {
protected: // 使用protected保护数据成员
string name;
string sex;
int age;
public:
Person(string _name = "", string _sex = "", int _age = 0) :name(_name), sex(_sex), age(_age) {};
virtual void show() {
cout << "姓名:" << name << " 性别:" << sex << " 年龄:" << age << endl;
}
};
// 定义Student类继承于Person类
class Student :public Person {
private:
string id; // 学号
string enrollment_date; // 入学日期
int enrollment_score; // 入学成绩
public:
Student(string _name = "", string _sex = "", int _age = 0, string _id = "", string _date = "", int _score = 0) :Person(_name, _sex, _age), id(_id), enrollment_date(_date), enrollment_score(_score) {};
void show() { // 重载Person类的show函数
cout << "姓名:" << name << " 性别:" << sex << " 年龄:" << age << " 学号:" << id << " 入学日期:" << enrollment_date << " 入学成绩:" << enrollment_score << endl;
}
int getScore() { // 获取学生入学成绩
return enrollment_score;
}
void setScore(int score) { // 设置学生入学成绩
enrollment_score = score;
}
};
#include<fstream>
#include<string>
using namespace std;
// 定义Person类
class Person {
protected: // 使用protected保护数据成员
string name;
string sex;
int age;
public:
Person(string _name = "", string _sex = "", int _age = 0) :name(_name), sex(_sex), age(_age) {};
virtual void show() {
cout << "姓名:" << name << " 性别:" << sex << " 年龄:" << age << endl;
}
};
// 定义Student类继承于Person类
class Student :public Person {
private:
string id; // 学号
string enrollment_date; // 入学日期
int enrollment_score; // 入学成绩
public:
Student(string _name = "", string _sex = "", int _age = 0, string _id = "", string _date = "", int _score = 0) :Person(_name, _sex, _age), id(_id), enrollment_date(_date), enrollment_score(_score) {};
void show() { // 重载Person类的show函数
cout << "姓名:" << name << " 性别:" << sex << " 年龄:" << age << " 学号:" << id << " 入学日期:" << enrollment_date << " 入学成绩:" << enrollment_score << endl;
}
int getScore() { // 获取学生入学成绩
return enrollment_score;
}
void setScore(int score) { // 设置学生入学成绩
enrollment_score = score;
}
};