Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication14.cpp : Defines the entry point for the console application.
- //
- #include<fstream>
- #include<string>
- #include<iostream>
- #include<iomanip>
- using namespace std;
- ifstream in("input.txt");
- ofstream out("output.txt");
- struct mas
- {
- string fam, name, secondname, god;
- int ses[5]; //оценки по пяти предметам
- double key; //средняя оценка
- void print();
- };
- void mas::print() //вывод данных в выходной поток
- {
- out<<setw(12)<<left<<fam<<setw(15)<<name<<setw(12)<<secondname<<setw(6)<<god;
- for (int i=0; i<5; i++)
- out <<setw(3)<<ses[i];
- out<<setw(5)<<key<<endl;
- }
- //сортировка массива записей из n элементов методом выбора
- void qsort(mas *arr, int b, int e)
- {int l = b, r = e;
- int piv = arr[(l + r) / 2].key; // Опорным элементом для примера возьмём средний
- while (l <= r)
- {
- while (arr[l].key > piv)
- l++;
- while (arr[r].key < piv)
- r--;
- if (l <= r) {
- swap(arr[l++], arr[r--]);
- }
- }
- if (b < r)
- qsort(arr, b, r);
- if (e > l)
- qsort(arr, l, e);
- }
- int main ( )
- {
- int n=0,m,i;
- mas stud[1000];
- if(!in) cout<<"Ошибка при открытии файла input.txt\n";
- else
- {
- in>>m;
- while(in.peek()!=EOF)
- {
- in>>stud[n].fam;
- in>>stud[n].name;
- in>>stud[n].secondname;
- in>>stud[n].god;
- stud[n].key=0;
- for (i=0;i<5; i++)
- {
- in>>stud[n].ses[i];
- stud[n].key+=stud[n].ses[i];
- }
- n++;
- }
- qsort(stud, 0, n);
- out<<m<<endl;
- for (i=0; i<n; i++)
- stud[i].print();
- }
- in.close();
- out.close();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement