Untitled

 avatar
unknown
plain_text
a year ago
3.3 kB
5
Indexable
#include <iostream>
#include <string>
using namespace std;

class Human {
protected:
    string last_name;
    string first_name;
    string patronymic;
    string gender;
    int birth_year;
    string address;
public:
    // Конструктор класса
    Human(string last_name, string first_name, string patronymic, string gender, int birth_year, string address) {
        this->last_name = last_name;
        this->first_name = first_name;
        this->patronymic = patronymic;
        this->gender = gender;
        this->birth_year = birth_year;
        this->address = address;
    }

    // Методы для вывода и задания значений полей
    void displayInfo() {
        cout << "Фамилия: " << last_name << endl;
        cout << "Имя: " << first_name << endl;
        cout << "Отчество: " << patronymic << endl;
        cout << "Пол: " << gender << endl;
        cout << "Год рождения: " << birth_year << endl;
        cout << "Прописка: " << address << endl;
    }

    void setLastName(string last_name) {
        this->last_name = last_name;
    }

    void setFirstName(string first_name) {
        this->first_name = first_name;
    }

    void setPatronymic(string patronymic) {
        this->patronymic = patronymic;
    }

    void setGender(string gender) {
        this->gender = gender;
    }

    void setBirthYear(int birth_year) {
        this->birth_year = birth_year;
    }

    void setAddress(string address) {
        this->address = address;
    }
};

class Student : public Human {
private:
    int korpus;
    string faculty;
    int group;
public:
    Student(string last_name, string first_name, string patronymic, string gender, int birth_year, string address, int korpus, string faculty, int group)
        : Human(last_name, first_name, patronymic, gender, birth_year, address) {
        this->korpus = korpus;
        this->faculty = faculty;
        this->group = group;
    }

    void Print() {
        displayInfo();
        cout << "Корпус: " << korpus << endl;
        cout << "Факультет: " << faculty << endl;
        cout << "Группа: " << group << endl;
    }

    void setKorpus(int korpus) {
        this->korpus = korpus;
    }

    void setFaculty(string faculty) {
        this->faculty = faculty;
    }

    void setGroup(int group) {
        this->group = group;
    }
};

int main() {
    setlocale(LC_ALL, "rus");
    // Создание объекта класса Human
    Human person("Иванов", "Иван", "Иванович", "Мужской", 1990, "Москва");

    // Вывод информации о человеке
    person.displayInfo();
       cout<<"------------------"<<endl;
    // Изменение значения поля "Фамилия"
    person.setLastName("Петров");

    // Вывод обновленной информации о человеке
    person.displayInfo();
        cout<<"------------------"<<endl;
    // Создание объекта класса Student
    Student student("Куранов", "Егор", "Дмитриевич", "Мужской", 2006, "Саратов", 9, "ОИБ", 932);

    // Вывод информации о студенте
    student.Print();

    return 0;
}

Editor is loading...
Leave a Comment