Advertisement
Potap

Работает

Dec 14th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.72 KB | None | 0 0
  1. #include <string>
  2. #include <sstream>
  3. #include <cstdlib>
  4. #include <iostream>
  5.  
  6. using namespace std;
  7.  
  8. class human {
  9.     private:
  10.         string name; // имя
  11.         int age; // возраст
  12.         int number; // номер паспорта
  13.         string gender; // пол
  14.     public:
  15.         // Конструктор класса human
  16.         human(string name, int age, int number, string gender)
  17.         {
  18.             this->name = name;
  19.             this->age = age;
  20.             this->number = number;
  21.             this->gender = gender;
  22.         }
  23.  
  24.         // Получение данных человека
  25.         virtual string get_access()
  26.         {
  27.             ostringstream access;
  28.             access << "ФИО: " << this->name << "\n"
  29.                 << "Возраст: " << this->age << "\n"
  30.                 << "Номер паспорта: " <<this->number << "\n"
  31.                 << "Пол:" << this->gender;
  32.             return access.str();
  33.         }
  34. };
  35.  
  36. class student : public human {
  37.     private:
  38.         int course; // курс
  39.         string university; // университет
  40.         string faculty; // факультет
  41.     public:
  42.         // Конструктор класса Student
  43.         student(
  44.             string name,
  45.             int age,
  46.             int number,
  47.             string gender,
  48.             int course,
  49.             string university,
  50.             string faculty
  51.         ) : human(
  52.             name,
  53.             age,
  54.             number,
  55.             gender
  56.         ) {
  57.             this->course = course;
  58.             this->university = university;
  59.             this->faculty = faculty;
  60.         }
  61.  
  62.         // Получение данных студента
  63.         virtual string get_student_access()
  64.         {
  65.             ostringstream acces;
  66.             acces << "Курс: " << this->course << "\n"
  67.                 << "Университет: " << this->university << "\n"
  68.                 << "Факультет: " << this->faculty;
  69.             return acces.str();
  70.         }
  71. };
  72.  
  73. int main(int argc, char* argv[])
  74. {
  75.     // Создание объекта класса student
  76.     student *stud = new student("Потапов Иван Афанасьевич", 20, 471709, "мужской", 2, "Северо-восточный федеральный университет", "Институт математики и информатики");
  77.     // Вывод данных про студента (используется унаследованный метод класса human)
  78.     cout << stud->get_access() << std::endl;
  79.     // Вывод данных про студента
  80.     cout << stud->get_student_access() << std::endl;
  81.  
  82.     return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement