Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- #include <sstream>
- #include <cstdlib>
- #include <iostream>
- using namespace std;
- class human {
- private:
- string name; // имя
- int age; // возраст
- int number; // номер паспорта
- string gender; // пол
- public:
- // Конструктор класса human
- human(string name, int age, int number, string gender)
- {
- this->name = name;
- this->age = age;
- this->number = number;
- this->gender = gender;
- }
- // Получение данных человека
- virtual string get_access()
- {
- ostringstream access;
- access << "ФИО: " << this->name << "\n"
- << "Возраст: " << this->age << "\n"
- << "Номер паспорта: " <<this->number << "\n"
- << "Пол:" << this->gender;
- return access.str();
- }
- };
- class student : public human {
- private:
- int course; // курс
- string university; // университет
- string faculty; // факультет
- public:
- // Конструктор класса Student
- student(
- string name,
- int age,
- int number,
- string gender,
- int course,
- string university,
- string faculty
- ) : human(
- name,
- age,
- number,
- gender
- ) {
- this->course = course;
- this->university = university;
- this->faculty = faculty;
- }
- // Получение данных студента
- virtual string get_student_access()
- {
- ostringstream acces;
- acces << "Курс: " << this->course << "\n"
- << "Университет: " << this->university << "\n"
- << "Факультет: " << this->faculty;
- return acces.str();
- }
- };
- int main(int argc, char* argv[])
- {
- // Создание объекта класса student
- student *stud = new student("Потапов Иван Афанасьевич", 20, 471709, "мужской", 2, "Северо-восточный федеральный университет", "Институт математики и информатики");
- // Вывод данных про студента (используется унаследованный метод класса human)
- cout << stud->get_access() << std::endl;
- // Вывод данных про студента
- cout << stud->get_student_access() << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement