Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <fstream>
- using namespace std;
- struct abit
- {
- char fio[40];
- int mark[3];
- int summ;
- };
- int main()
- {
- setlocale(LC_ALL, "ru");
- ifstream in("arb.txt");
- ofstream outbin("abit.bin", ios::binary);
- if (!in)
- {
- cout << "file not found" << endl;
- system("pause");
- exit(-1);
- }
- int k = 0;
- abit x;
- while (in >> x.fio >> x.mark[0] >> x.mark[1] >> x.mark[2])
- {
- if ((x.mark[0] >= 40) && (x.mark[1] >= 40) && (x.mark[2] >= 40))
- {
- x.summ = x.mark[0] + x.mark[1] + x.mark[2];
- outbin.write((char*)&x, sizeof(struct abit));
- k++;
- }
- }
- in.close();
- outbin.close();
- ifstream inbin("abit.bin", ios::binary);
- if (!inbin)
- {
- cout << "file not found" << endl;
- system("pause");
- exit(-1);
- }
- cout << "Абитуриенты, подавшие заявления и прошедшие на конкурс:" << endl;
- while (inbin.read((char*)&x, sizeof(struct abit)))
- {
- cout << x.fio << setw(6) << x.summ << endl;
- }
- inbin.close();
- abit* a = new abit[k];
- inbin.open("abit.bin");
- int i = 0;
- while (inbin.read((char*)&x, sizeof(struct abit)))
- {
- a[i] = x;
- i++;
- }
- int j;
- int r;
- for (i = 0; i < k - 1; i++)
- for (j = i + 1; j < k; j++)
- if (a[i].summ < a[j].summ)
- {
- x = a[i];
- a[i] = a[j];
- a[j] = x;
- }
- int p;
- cout << "Введите количество вакантных мест:";
- cin >> p;
- if (p > k)
- {
- cout << "Прошедшие:" << endl;
- for (i = 0; i < k; i++)
- cout << a[i].fio << setw(5) << a[i].summ << endl;
- }
- if (k > p)
- {
- cout << "Прошедшие:" << endl;
- for (i = 0; i < p; i++)
- cout << a[i].fio << setw(5) << a[i].summ<<endl;
- }
- cout << "Максимальный балл:" << a[0].summ << endl;
- if (k < p)
- cout << "Проходной балл:" << a[p - 1].summ << endl;
- else cout << "Проходной балл:" << a[k - 1].summ << endl;
- int l = a[p - 1].summ;
- int dop = 0;
- i = p;
- while (a[i].summ == l)
- {
- i++;
- dop++;
- }
- cout << "Количество дополнительных требуемых мест:" << ' ' << dop << endl;
- inbin.close();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement