Advertisement
Guest User

Untitled

a guest
May 26th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. #include <fstream>
  2. #include <iostream>
  3. #include <string>
  4. #include <iomanip>
  5. using namespace std;
  6. ifstream in("input.txt");
  7. ofstream out("output.txt");
  8.  
  9. struct mas {
  10. string fam, name, secondname, date;
  11. int ses[5];
  12. int key;
  13. void print();
  14. };
  15.  
  16. void mas::print() {
  17. out << setw(12) << left << fam << setw(10) << name << setw(15) << secondname << setw(5) << date << ' ';
  18. for (int i = 0; i < 5; i++)
  19. {
  20. out << setw(3) << ses[i];
  21. }
  22. out << setw(5) << key << endl;
  23. }
  24.  
  25. void Shell(mas *a, int n)
  26. {
  27. mas temp;
  28. int i, j, incr = n / 2;
  29. while (incr > 0)
  30. {
  31. for (i = incr; i < n; i++)
  32. {
  33. j = i - incr;
  34. while (j >= 0)
  35. if (a[j].name > a[j + incr].name)
  36. {
  37. temp = a[j];
  38. a[j] = a[j + incr];
  39. a[j + incr] = temp;
  40. j = j - incr;
  41. }
  42. else j = -1;
  43. }
  44. incr = incr / 2;
  45. }
  46. }
  47.  
  48.  
  49. int main() {
  50. int m, i;
  51. if (!in) {
  52. cout << "Error message here!\n";
  53. }
  54. else
  55. {
  56. int k; cout << "Enter the number of students";
  57. cin >> k;
  58. mas *stud = new mas[k];
  59. in >> m;
  60. for (int m = 0; m < k; ++m)
  61. {
  62. in >> stud[m].fam;
  63. in >> stud[m].name;
  64. in >> stud[m].secondname;
  65. in >> stud[m].date;
  66. in >> stud[m].ses[m];
  67. }
  68. Shell(stud, k);
  69.  
  70. for (i = 0; i < k; ++i)
  71. stud[i].print();
  72. delete[] stud;
  73. }
  74. in.close();
  75. out.close();
  76. system("pause");
  77. return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement