Advertisement
Infiniti_Inter

19(Olya)

Dec 10th, 2019
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.51 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4.  
  5. using namespace std;
  6.  
  7.  
  8. ifstream in("input.txt");
  9. ofstream out("output.txt");
  10.  
  11.  
  12.  
  13.  
  14.  
  15. struct Student {
  16.     string Name;
  17.     string Surname;
  18.     string SecondName;
  19.     int YearOfBirth;
  20.     int mark[5];
  21.    
  22.     Student() {}
  23.  
  24.     Student(string Surname, string Name, string SecondName, int YearOfBirth, int mark[5])
  25.     {
  26.         this->Name = Name;
  27.         this->Surname = Surname;
  28.         this->SecondName = SecondName;
  29.         this->YearOfBirth = YearOfBirth;
  30.         for (int i = 0; i < 5; ++i)
  31.             this->mark[i] = mark[i];
  32.     }
  33.  
  34.     void InitStudent()//ввод данных (фамилия -> имя -> отчество -> год -> оценки
  35.     {
  36.         in >> Surname >> Name >> SecondName >> YearOfBirth;
  37.         for (int i = 0; i < 5; ++i)
  38.             in >> mark[i];
  39.     }
  40.  
  41.     void Print()//выовд в файл
  42.     {
  43.         out << "Full name : " << Surname << " " << Name << " " << SecondName << endl;
  44.         out << "Year of birth : " << YearOfBirth << endl;
  45.         out << "Marks : ";
  46.         for (int i = 0; i < 5; ++i)
  47.             out << mark[i] << " ";
  48.         out << "\n=================================================\n";
  49.     }
  50.  
  51.     bool operator <(Student a)//перегрузка оператора <
  52.     {
  53.         if (this->Surname < a.Surname)
  54.             return true;
  55.         if (this->Surname == a.Surname && this->Name < a.Name)
  56.             return true;
  57.         if (this->Surname == a.Surname && this->Name == a.Name && this->SecondName < a.SecondName)
  58.             return true;
  59.         return false;
  60.     }
  61.     bool operator >(Student a)//перегрузка оператора >
  62.     {
  63.         if (this->Surname > a.Surname)
  64.             return true;
  65.         if (this->Surname == a.Surname && this->Name > a.Name)
  66.             return true;
  67.         if (this->Surname == a.Surname && this->Name == a.Name && this->SecondName > a.SecondName)
  68.             return true;
  69.         return false;
  70.     }
  71.  
  72.    
  73. };
  74.  
  75.  
  76. void Sort(Student *arr, int size)//пузырек
  77. {
  78.     for (int i = 0; i < size - 1; i++) {
  79.         for (int j = 0; j < size - i - 1; j++) {
  80.             if (arr[j] > arr[j + 1]) {
  81.                 swap(arr[j], arr[j + 1]);
  82.             }
  83.         }
  84.     }
  85. }
  86. void InsertionSort(Student *arr, int size) // сортировка вставками
  87. {
  88.     Student temp; // временная переменная для хранения значения элемента сортируемого массива
  89.     int item; // индекс предыдущего элемента
  90.     for (int i = 1; i < size; i++)
  91.     {
  92.         temp = arr[i]; // инициализируем временную переменную текущим значением элемента массива
  93.         item = i - 1; // запоминаем индекс предыдущего элемента массива
  94.         while (item >= 0 && arr[item] > temp) // пока индекс не равен 0 и предыдущий элемент массива больше текущего
  95.         {
  96.             arr[item + 1] = arr[item]; // перестановка элементов массива
  97.             arr[item] = temp;
  98.             item--;
  99.         }
  100.     }
  101. }
  102.  
  103.  
  104.  
  105. int main()
  106. {
  107.     int size;
  108.     in >> size;
  109.     Student *a = new Student[size];
  110.     for (int i = 0; i < size; ++i)
  111.         a[i].InitStudent();
  112.     insertionSort(a, size);
  113.     //Sort(a, size);
  114.     for (int i = 0; i < size; ++i)
  115.         a[i].Print();
  116.     /*
  117. 11
  118. Bavera Eldred Boreng 2000 1 2 3 4 5
  119. Neoma Boggs Aung 2000 5 5 5 5 5
  120. Ahirlene Bode Feros 2000 3 3 3 3 3
  121. Cong Heston Unofs 2000 5 5 5 3 5
  122. Mario Beane Quri 2000 4 3 2 3 4
  123. Cheryll Balderas Roots 2000 4 2 3 4 2
  124. Shaquana Burkett Gemen 2000 5 5 5 5 4
  125. Nichole Frances Rasif 2000 3 3 3 3 3
  126. Euna Draper Daun 2000 5 5 5 5 5
  127. Carita Henriksen Colers 2000 2 3 4 5 2
  128. Treena Nicholes Samer 2000 4 3 4 5 2
  129.    
  130.     */
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement