Добавил:
Рад, если кому-то помог Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
0
Добавлен:
01.11.2025
Размер:
2.63 Кб
Скачать
#include <iostream>
#include <string>
#include <locale>
using namespace std;

class Person {
protected:
    string name;
    int age;
    string address;
public:
    Person(const string& n, int a, const string& addr = "") 
        : name(n), age(a), address(addr) {}
    
    virtual void printInfo() const {
        cout << "Имя: " << name << ", Возраст: " << age;
        if (!address.empty()) cout << ", Адрес: " << address;
    }
    
    virtual ~Person() {}
};

class Employee : public Person {
protected:
    string department;
    double salary;
public:
    Employee(const string& n, int a, const string& addr, 
             const string& dept, double sal)
        : Person(n, a, addr), department(dept), salary(sal) {}
    
    void printInfo() const override {
        Person::printInfo();
        cout << ", Отдел: " << department << ", Зарплата: " << salary << endl;
    }
};

class Student : public Person {
protected:
    string group;
    double gpa;
public:
    Student(const string& n, int a, const string& addr, 
            const string& grp, double gpa_val)
        : Person(n, a, addr), group(grp), gpa(gpa_val) {}
    
    void printInfo() const override {
        Person::printInfo();
        cout << ", Группа: " << group << ", Средний балл: " << gpa << endl;
    }
};

class GraduateStudent : public Student {
    string researchTopic;
    string supervisor;
public:
    GraduateStudent(const string& n, int a, const string& addr,
                   const string& grp, double gpa_val,
                   const string& topic, const string& sup)
        : Student(n, a, addr, grp, gpa_val), researchTopic(topic), supervisor(sup) {}
    
    void printInfo() const override {
        Student::printInfo();
        cout << "Научная тема: " << researchTopic << ", Научный руководитель: " << supervisor << endl;
    }
};

int main() {
    setlocale(LC_ALL, "ru_RU.UTF-8");
    
    Employee emp("Иван Петров", 35, "ул. Ленина, 10", "ИТ", 50000);
    Student stud("Мария Сидорова", 20, "ул. Мира, 5", "ИС-21", 4.5);
    GraduateStudent grad("Алексей Козлов", 25, "ул. Пушкина, 15", "АС-31", 4.8, 
                        "Искусственный интеллект", "д.т.н. Смирнов");
    
    cout << "Сотрудник: ";
    emp.printInfo();
    cout << "Студент: ";
    stud.printInfo();
    cout << "Аспирант: ";
    grad.printInfo();
    
    return 0;
}
Соседние файлы в папке Лаба6