Advertisement
cacodemon665

Лаба 7 Вариант 3

Dec 11th, 2018
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.11 KB | None | 0 0
  1. #include "pch.h" //для версий вижлы старше последних версий 2017 здесь должно быть #include "stdafx.h"
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. struct StudentData
  7. {
  8.     char fio[50];
  9.     int group;
  10.     int average_assessment;
  11.     int income;
  12. };
  13.  
  14.  
  15. int main()
  16. {
  17.     int n, min_pay;
  18.     cout << "Enter number of people:";
  19.     cin >> n;
  20.     cout << "Enter minimal pay:";
  21.     cin >> min_pay;
  22.  
  23.     StudentData first[1000], second[1000];
  24.     int first_size = 0, second_size = 0;
  25.  
  26.  
  27.     for (int i = 0; i < n; i++)
  28.     {
  29.         cout << i + 1 << endl;
  30.  
  31.         StudentData temp;
  32.  
  33.         cin.ignore(1, '\n');
  34.  
  35.         cout << "Enter full name: ";
  36.         cin.getline(temp.fio, 50);
  37.         cout << "Enter group: ";
  38.         cin >> temp.group;
  39.         cout << "Enter average assessment: ";
  40.         cin >> temp.average_assessment;
  41.         cout << "Enter income: ";
  42.         cin >> temp.income;
  43.  
  44.         if (temp.income < 2 * min_pay)
  45.             first[first_size++] = temp;
  46.         else
  47.             second[second_size++] = temp;
  48.     }
  49.  
  50.     for (int i = first_size - 1; i >= 0; i--)
  51.     {
  52.         for (int j = 0; j < i; j++)
  53.         {
  54.             if (first[j].average_assessment < first[j + 1].average_assessment)
  55.             {
  56.                 StudentData temp = first[j];
  57.                 first[j] = first[j + 1];
  58.                 first[j + 1] = temp;
  59.             }
  60.         }
  61.     }
  62.  
  63.     for (int i = second_size - 1; i >= 0; i--)
  64.     {
  65.         for (int j = 0; j < i; j++)
  66.         {
  67.             if (second[j].average_assessment < second[j + 1].average_assessment)
  68.             {
  69.                 StudentData temp = second[j];
  70.                 second[j] = second[j + 1];
  71.                 second[j + 1] = temp;
  72.             }
  73.         }
  74.     }
  75.  
  76.     cout << endl;
  77.  
  78.     for (int i = 0; i < first_size; i++)
  79.     {
  80.         cout << "Full name: " << first[i].fio << endl;
  81.         cout << "Group: " << first[i].group << endl;
  82.         cout << "Average assessment: " << first[i].average_assessment << endl;
  83.         cout << "Income: " << first[i].income << endl;
  84.         cout << endl;
  85.     }
  86.  
  87.     cout << endl;
  88.  
  89.     for (int i = 0; i < second_size; i++)
  90.     {
  91.         cout << "Full name: " << second[i].fio << endl;
  92.         cout << "Group: " << second[i].group << endl;
  93.         cout << "Average assessment: " << second[i].average_assessment << endl;
  94.         cout << "Income: " << second[i].income << endl;
  95.         cout << endl;
  96.     }
  97.  
  98.     return 0;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement