Untitled
unknown
plain_text
2 years ago
2.1 kB
10
Indexable
#include <iostream>
#include <string>
using namespace std;
class Human {
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;
}
private:
string last_name;
string first_name;
string patronymic;
string gender;
int birth_year;
string address;
};
int main() {
// Создание объекта класса Human
Human person("Иванов", "Иван", "Иванович", "Мужской", 1990, "Москва");
// Вывод информации о человеке
person.displayInfo();
// Изменение значения поля "Фамилия"
person.setLastName("Петров");
// Вывод обновленной информации о человеке
person.displayInfo();
return 0;
}Editor is loading...
Leave a Comment