Advertisement
JouJoy

Untitled

Mar 4th, 2020
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.24 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <fstream>
  4. using namespace std;
  5. struct abit
  6. {
  7.     char fio[40];
  8.     int mark[3];
  9.     int summ;
  10. };
  11.  
  12. int main()
  13. {
  14.     setlocale(LC_ALL, "ru");
  15.     ifstream in("arb.txt");
  16.     ofstream outbin("abit.bin", ios::binary);
  17.     if (!in)
  18.     {
  19.         cout << "file not found" << endl;
  20.         system("pause");
  21.         exit(-1);
  22.     }
  23.     int k = 0;
  24.     abit x;
  25.     while (in >> x.fio >> x.mark[0] >> x.mark[1] >> x.mark[2])
  26.     {
  27.         if ((x.mark[0] >= 40) && (x.mark[1] >= 40) && (x.mark[2] >= 40))
  28.         {
  29.             x.summ = x.mark[0] + x.mark[1] + x.mark[2];
  30.             outbin.write((char*)&x, sizeof(struct abit));
  31.             k++;
  32.         }
  33.     }
  34.     in.close();
  35.     outbin.close();
  36.     ifstream inbin("abit.bin", ios::binary);
  37.         if (!inbin)
  38.         {
  39.             cout << "file not found" << endl;
  40.             system("pause");
  41.             exit(-1);
  42.         }
  43.         cout << "Абитуриенты, подавшие заявления и прошедшие на конкурс:" << endl;
  44.         while (inbin.read((char*)&x, sizeof(struct abit)))
  45.         {
  46.             cout << x.fio << setw(6) << x.summ << endl;
  47.         }
  48.         inbin.close();
  49.         abit* a = new abit[k];
  50.         inbin.open("abit.bin");
  51.         int i = 0;
  52.         while (inbin.read((char*)&x, sizeof(struct abit)))
  53.         {
  54.             a[i] = x;
  55.             i++;
  56.         }
  57.         int j;
  58.         int r;
  59.         for (i = 0; i < k - 1; i++)
  60.             for (j = i + 1; j < k; j++)
  61.                 if (a[i].summ < a[j].summ)
  62.                 {
  63.                     x = a[i];
  64.                     a[i] = a[j];
  65.                     a[j] = x;
  66.                 }
  67.         int p;
  68.         cout << "Введите количество вакантных мест:";
  69.         cin >> p;
  70.         if (p > k)
  71.         {
  72.             cout << "Прошедшие:" << endl;
  73.             for (i = 0; i < k; i++)
  74.                 cout << a[i].fio << setw(5) << a[i].summ << endl;
  75.         }
  76.         if (k > p)
  77.         {
  78.             cout << "Прошедшие:" << endl;
  79.             for (i = 0; i < p; i++)
  80.                 cout << a[i].fio << setw(5) << a[i].summ<<endl;
  81.         }
  82.         cout << "Максимальный балл:" << a[0].summ << endl;
  83.         if (k < p)
  84.             cout << "Проходной балл:" << a[p - 1].summ << endl;
  85.         else cout << "Проходной балл:" << a[k - 1].summ << endl;
  86.         int l = a[p - 1].summ;
  87.         int dop = 0;
  88.         i = p;
  89.         while (a[i].summ == l)
  90.         {
  91.             i++;
  92.             dop++;
  93.         }
  94.         cout << "Количество дополнительных требуемых мест:" << ' ' << dop << endl;
  95.         inbin.close();
  96.         system("pause");
  97.         return 0;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement