Bob103

Sort paste

May 22nd, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. #include<string>
  4. #include<iomanip>
  5.  
  6. using namespace std;
  7.  
  8. ifstream in("Input.txt");
  9. ofstream out("Output.txt");
  10.  
  11.  
  12. struct Student
  13. {
  14. string name, secondname, fam;
  15. int year;
  16. int mark[5];
  17. int key;
  18. void print();
  19. };
  20.  
  21. void Student::print()
  22. {
  23. out<< setw(12) << left << fam << setw(10) << name << setw(15) << secondname << setw(5) << year;;
  24.  
  25. for (int i = 0; i < 5; i++)
  26. {
  27. out << setw(3) << mark[i];
  28. }
  29. out << setw(5) << key<<endl;
  30. }
  31.  
  32. void sort(Student *a, int n)
  33. {
  34. Student temp;
  35. int i, j;
  36. for (i = 2; i <= n; i++)
  37. {
  38. j = i;
  39. while (a[j].key < a[j - 1].key)
  40. {
  41. temp = a[j];
  42. a[j] = a[j - 1];
  43. a[j - 1] = temp;
  44. j--;
  45. }
  46. }
  47. }
  48.  
  49. int main()
  50. {
  51. int n = 0, m, i;
  52. Student stud[10];
  53.  
  54. if (!in)
  55. cout << "Error,file Input.txt doesn't open";
  56.  
  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].year;
  66. for (int i = 0; i < 5; i++)
  67. {
  68. in >> stud[n].mark[i];
  69. stud[n].key += stud[n].mark[i];
  70. }
  71.  
  72. n++;
  73. }
  74. sort(stud, n);
  75. out << m << endl;
  76. for (int i = 3; i >= 0; i--)
  77. stud[i].print();
  78. }
  79. in.close();
  80. out.close();
  81. return 0;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment