Advertisement
Guest User

Untitled

a guest
May 27th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. // ConsoleApplication14.cpp : Defines the entry point for the console application.
  2.  
  3. //
  4.  
  5.  
  6.  
  7. #include<fstream>
  8.  
  9. #include<string>
  10.  
  11. #include<iostream>
  12.  
  13. #include<iomanip>
  14. using namespace std;
  15. ifstream in("input.txt");
  16. ofstream out("output.txt");
  17. struct mas
  18. {
  19. string fam, name, secondname, god;
  20. int ses[5]; //оценки по пяти предметам
  21. double key; //средняя оценка
  22. void print();
  23. };
  24. void mas::print() //вывод данных в выходной поток
  25. {
  26. out<<setw(12)<<left<<fam<<setw(15)<<name<<setw(12)<<secondname<<setw(6)<<god;
  27. for (int i=0; i<5; i++)
  28. out <<setw(3)<<ses[i];
  29. out<<setw(5)<<key<<endl;
  30. }
  31. //сортировка массива записей из n элементов методом выбора
  32. void qsort(mas *arr, int b, int e)
  33. {int l = b, r = e;
  34.  
  35. int piv = arr[(l + r) / 2].key; // Опорным элементом для примера возьмём средний
  36. while (l <= r)
  37. {
  38. while (arr[l].key > piv)
  39. l++;
  40. while (arr[r].key < piv)
  41. r--;
  42. if (l <= r) {
  43. swap(arr[l++], arr[r--]);
  44. }
  45. }
  46. if (b < r)
  47. qsort(arr, b, r);
  48. if (e > l)
  49. qsort(arr, l, e);
  50. }
  51.  
  52. int main ( )
  53. {
  54. int n=0,m,i;
  55. mas stud[1000];
  56. if(!in) cout<<"Ошибка при открытии файла input.txt\n";
  57. else
  58. {
  59. in>>m;
  60. while(in.peek()!=EOF)
  61. {
  62. in>>stud[n].fam;
  63. in>>stud[n].name;
  64. in>>stud[n].secondname;
  65. in>>stud[n].god;
  66. stud[n].key=0;
  67. for (i=0;i<5; i++)
  68. {
  69. in>>stud[n].ses[i];
  70. stud[n].key+=stud[n].ses[i];
  71. }
  72. n++;
  73.  
  74. }
  75. qsort(stud, 0, n);
  76. out<<m<<endl;
  77. for (i=0; i<n; i++)
  78. stud[i].print();
  79. }
  80. in.close();
  81. out.close();
  82. system("pause");
  83. return 0;
  84.  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement