Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- #include <iostream>
- using namespace std;
- // Человек
- class Person {
- public:
- void SetName(string name) {
- name_ = name;
- }
- void SetGender(string gender) {
- gender_ = gender;
- }
- void SetAge(int age) {
- age_ = age;
- }
- string GetName() const {
- return name_;
- }
- int GetAge() const {
- return age_;
- }
- string GetGender() const {
- return gender_;
- }
- string name_;
- string gender_;
- int age_;
- };
- // Рабочий
- class Worker : public virtual Person {
- public:
- void SetSpeciality(string speciality) {
- speciality_ = speciality;
- }
- string GetSpeciality() const {
- return speciality_;
- }
- void Speak() {
- cout << "Привет, я рабочий" << endl;
- }
- private:
- string speciality_;
- };
- // Студент
- class Student : public virtual Person {
- public:
- void SetFaculty(string faculty) {
- faculty_ = faculty;
- }
- string GetFaculty() const {
- return faculty_;
- }
- void Speak() {
- cout << "Привет, я студент" << endl;
- }
- private:
- string faculty_;
- };
- //
- class ExternalStudent : public Worker, public Student {
- };
- int main() {
- setlocale(LC_ALL, "ru");
- ExternalStudent ex;
- ex.SetSpeciality("Builder");
- ex.SetFaculty("Programming");
- cout << ex.GetSpeciality() << " " << ex.GetFaculty() << endl;
- ex.SetName("Иван"); // теперь это работает
- cout << ex.GetName() << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement