Advertisement
Proff_Ust

Lab3_new

Dec 25th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.97 KB | None | 0 0
  1. #include <iostream>
  2. #include <clocale>
  3. #define MARKS_NUM 10
  4.  
  5. using namespace std;
  6.  
  7. class Tman
  8. {
  9. protected:
  10.     string name;
  11.     string surname;
  12.     string patronymic;
  13.     int dayOfBirth;
  14.     int mounthOfBirth;
  15.     int yearOfBirth;
  16.  
  17. public:
  18.     Tman()
  19.     {
  20.         this->name = "";
  21.         this->surname = "";
  22.         this->patronymic = "";
  23.         this->dayOfBirth = 0;
  24.         this->mounthOfBirth = 0;
  25.         this->yearOfBirth = 0;
  26.     }
  27.  
  28.     Tman(string newSurname, string newName, string newPatronymic,
  29.         int newDayOfBirth, int newMounthOfBirth, int newYearOfBirth)
  30.     {
  31.         this->name = newName;
  32.         this->surname = newSurname;
  33.         this->patronymic = newPatronymic;
  34.         this->dayOfBirth = newDayOfBirth;
  35.         this->mounthOfBirth = newMounthOfBirth;
  36.         this->yearOfBirth = newYearOfBirth;
  37.     }
  38.  
  39.     int modifyMan()
  40.     {
  41.         cout<<"Новая фамилия ";
  42.         cin>>this->surname;
  43.         cout<<"Новое имя ";
  44.         cin>>this->name;
  45.         cout<<"Новое отчество ";
  46.         cin>>this->patronymic;
  47.  
  48.         cout<<"Новый день рождения ";
  49.         cin>>this->dayOfBirth;
  50.         cout<<"Новый месяц рождения ";
  51.         cin>>this->mounthOfBirth;
  52.         cout<<"Новый год рождения ";
  53.         cin>>this->yearOfBirth;
  54.         return 0;
  55.     }
  56.  
  57.     friend ostream &operator<<(ostream &stream, Tman* obj);
  58.     friend istream &operator>>(istream &stream, Tman** obj);
  59. };
  60.  
  61. istream &operator>>(istream &stream, Tman** obj)
  62. {
  63.     *obj = new Tman;
  64.     cout<<"Введите имя ";
  65.     cin>>(*obj)->name;
  66.     cout<<"Введите фамилию ";
  67.     cin>>(*obj)->surname;
  68.     cout<<"Введите отчество ";
  69.     cin>>(*obj)->patronymic;
  70.  
  71.     cout<<"Введите день рождения ";
  72.     cin>>(*obj)->dayOfBirth;
  73.     cout<<"Введите месяц рождения ";
  74.     cin>>(*obj)->mounthOfBirth;
  75.     cout<<"Введите год рождения ";
  76.     cin>>(*obj)->yearOfBirth;
  77.     return stream;
  78. }
  79.  
  80. ostream &operator<<(ostream &stream, Tman* obj)
  81. {
  82.     cout<<"Фамилия "<<obj->surname<<" Имя "<<obj->name<<" Отчество "<<obj->patronymic<<endl;
  83.     cout<<"Дата рождения: "<<obj->dayOfBirth<<"-"<<obj->mounthOfBirth<<"-"<<obj->yearOfBirth<<endl;
  84.     return stream;
  85. }
  86.  
  87.  
  88. class Tstudent: Tman
  89. {
  90. private:
  91.     int kurs;
  92.     string groupName;
  93.     int marks[MARKS_NUM];
  94. public:
  95.     Tstudent()
  96.     {
  97.         this->kurs = -1;
  98.         this->groupName = "";
  99.         for(int i=0;i<MARKS_NUM;i++)
  100.             this->marks[i] = 0;
  101.     }
  102.  
  103.     Tstudent(string newSurname, string newName, string newPatronymic,
  104.         int newDayOfBirth, int newMounthOfBirth, int newYearOfBirth,
  105.         int newKurs, string newGroupName, int newMarks[MARKS_NUM]):
  106.         Tman(newSurname,newName,newPatronymic,
  107.         newDayOfBirth,newMounthOfBirth,newYearOfBirth)
  108.     {
  109.         this->kurs = newKurs;
  110.         this->groupName = newGroupName;
  111.         for(int i=0;i<MARKS_NUM;i++)
  112.             this->marks[i] = newMarks[i];
  113.     }
  114.  
  115.     float avgMarks()
  116.     {
  117.         int sum = 0;
  118.         for(int i=0;i<MARKS_NUM;i++)
  119.             sum+=this->marks[i];
  120.         return sum/MARKS_NUM;
  121.     }
  122.  
  123.     int modifyStudent()
  124.     {
  125.         this->modifyMan();
  126.         cout<<"Введите новый курс ";
  127.         cin>>this->kurs;
  128.         cout<<"Введите новую группу ";
  129.         cin>>this->groupName;
  130.         cout<<"Введите новые оценки"<<endl;
  131.         for(int i=0;i<MARKS_NUM;i++)
  132.             cin>>this->marks[i];
  133.         return 0;
  134.     }
  135.  
  136.     friend ostream &operator<<(ostream &stream, Tstudent* obj);
  137.     friend istream &operator>>(istream &stream, Tstudent** obj);
  138. };
  139.  
  140. istream &operator>>(istream &stream, Tstudent** obj)
  141. {
  142.     *obj = new Tstudent;
  143.     cout<<"Введите имя ";
  144.     cin>>(*obj)->name;
  145.     cout<<"Введите фамилию ";
  146.     cin>>(*obj)->surname;
  147.     cout<<"Введите отчество ";
  148.     cin>>(*obj)->patronymic;
  149.  
  150.     cout<<"Введите день рождения ";
  151.     cin>>(*obj)->dayOfBirth;
  152.     cout<<"Введите месяц рождения ";
  153.     cin>>(*obj)->mounthOfBirth;
  154.     cout<<"Введите год рождения ";
  155.     cin>>(*obj)->yearOfBirth;
  156.     cout<<"Введите номер курса ";
  157.     cin>>(*obj)->kurs;
  158.     cout<<"Введите название группы ";
  159.     cin>>(*obj)->groupName;
  160.     cout<<"Введите "<<MARKS_NUM<<" оценок"<<endl;
  161.     for(int i=0;i<MARKS_NUM;i++)
  162.         cin>>(*obj)->marks[i];
  163.     return stream;
  164. }
  165.  
  166. ostream &operator<<(ostream &stream, Tstudent* obj)
  167. {
  168.     cout<<"Фамилия "<<obj->surname<<" Имя "<<obj->name<<" Отчество "<<obj->patronymic<<endl;
  169.     cout<<"Дата рождения: "<<obj->dayOfBirth<<"-"<<obj->mounthOfBirth<<"-"<<obj->yearOfBirth<<endl;
  170.     cout<<"Курс: "<<obj->kurs<<endl;
  171.     cout<<"Группа: "<<obj->groupName<<endl;
  172.     cout<<"Оценки: ";
  173.     for(int i=0;i<MARKS_NUM;i++)
  174.         cout<<obj->marks[i]<<" ";
  175.     cout<<endl;
  176.     return stream;
  177. }
  178.  
  179. int main()
  180. {
  181.     setlocale(LC_ALL,"RU");
  182.     Tman* man = new Tman("ivanov","ivan","ivanovich",1,1,1991);
  183.     cout<<man;
  184.     int mark[MARKS_NUM] = {5,4,5,4,5,4,5,4,5,4};
  185.     Tstudent* student = new Tstudent("petrov","petr","petrovich",1,1,1996,3,"PMII",mark);
  186.     cout<<student;
  187.     cout<<"Средний балл: "<<student->avgMarks()<<endl;
  188.     cout<<"Изменение информации о человеке"<<endl;
  189.     man->modifyMan();
  190.     cout<<"Изменение информации о студенте"<<endl;
  191.     student->modifyStudent();
  192.  
  193.     cout<<man;
  194.     cout<<student;
  195.     cout<<"Средний балл: "<<student->avgMarks();
  196.  
  197.     Tman* newMan = new Tman;
  198.     Tstudent* newStudent = new Tstudent;
  199.     cin>>&newMan;
  200.     cin>>&newStudent;
  201.  
  202.     cout<<newMan;
  203.     cout<<newStudent;
  204.     system("pause");
  205.     return 0;
  206. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement