Untitled
unknown
plain_text
2 years ago
3.3 kB
12
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();
// Изменение значения поля "Фамилия"
person.setLastName("Петров");
// Вывод обновленной информации о человеке
person.displayInfo();
// Создание объекта класса Student
Student student("Губанов", "Ильдар", "Шавкетович", "Мужской", 2005, "Саратов", 9, "ОИБ", 932);
// Вывод информации о студенте
student.Print();
return 0;
}Editor is loading...
Leave a Comment