Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <conio.h>
  4. #include <time.h>
  5. #include <random>
  6. #include <string>
  7. using namespace std;
  8.  
  9. template <typename x>
  10. void Sort_insert(x*a, int n)
  11. {
  12. int j;
  13. for (int i = 1; i < n; i++)
  14. {
  15. j = i;
  16. while (a[j - 1] > a[j] && j > 0)
  17. {
  18. swap(a[j - 1], a[j]);
  19. j--;
  20. }
  21. }
  22. }
  23.  
  24. template <typename x>
  25. void ShellSort(x*a, int n)
  26. {
  27. int i, j, step;
  28. x tmp;
  29. for (step = n / 2; step > 0; step /= 2)
  30. for (i = step; i < n; i++)
  31. {
  32. tmp = a[i];
  33. for (j = i; j >= step; j -= step)
  34. {
  35. if (tmp < a[j - step])
  36. a[j] = a[j - step];
  37. else
  38. break;
  39. }
  40. a[j] = tmp;
  41. }
  42. }
  43.  
  44. struct student
  45. {
  46. string name, surname;
  47. int marks[5];
  48.  
  49. bool operator < (student b)
  50. {
  51. if (surname != b.surname)
  52. return surname < b.surname;
  53. else return name < b.name;
  54. }
  55.  
  56. bool operator > (student b)
  57. {
  58. if (surname != b.surname)
  59. return surname > b.surname;
  60. else return name > b.name;
  61. }
  62.  
  63. bool operator == (student b)
  64. {
  65. return name == b.name && surname == b.surname;
  66. }
  67.  
  68.  
  69. void print()
  70. {
  71. cout << surname << " " << name << " ";
  72. for (int i = 0; i < 5; i++)
  73. cout << marks[i] << " ";
  74. cout << endl;
  75. }
  76. };
  77.  
  78.  
  79. void random_students(student*c, int n)
  80. {
  81. string names[] = { "Andrey", "Sergey", "Nastya", "Alena", "Misha", "Sasha", "Vanya","Elena" };
  82. string surnames[] = { "Brown", "Green", "Yellow", "Black", "White", "Vaselenko", "Poroshenko", "Glinko", "Vasilisko", "Potter", "Portenko" };
  83. srand(time(0));
  84. for (int i = 0; i < n; i++)
  85. {
  86. c[i].name = names[rand() % 8];
  87. c[i].surname = surnames[rand() % 11];
  88. for (int j = 0; j < 5; j++)
  89. {
  90. c[i].marks[j] = 1 + rand() % 5;
  91. }
  92. }
  93.  
  94. }
  95.  
  96.  
  97.  
  98. template <typename x>
  99. void random_numbers(x*a, int size) //рандом чисел
  100. {
  101. srand(time(NULL)); // инициализируем рандом
  102.  
  103. int i; //переменные цикла, кол-во элементов массива
  104.  
  105. x *list = new x[size]; // целевой массив
  106. for (i = 0; i < size; i++)
  107. list[i] = (rand() % RAND_MAX);
  108.  
  109. for (i = 0; i < size; i++)
  110. cout << list[i] << " ";
  111. cout << endl;
  112.  
  113. }
  114.  
  115. void random_string(string*b, int n) //рандом стринга
  116. {
  117. srand(time(0));
  118. for (int i = 0; i < n; ++i)
  119. for (int j = 0; j < 1 + rand() % 5; j++)
  120. {
  121. b[i] += 97 + rand() % 25;
  122. }
  123. for (int i = 0; i < n; i++)
  124. cout << b[i] << " ";
  125. cout << endl;
  126. }
  127.  
  128.  
  129. int main()
  130. {
  131. int n;
  132. cin >> n;
  133. int* a = new int[n];
  134. string* b = new string[n];
  135. student* c = new student[n];
  136.  
  137. random_numbers(a, n);
  138. random_string(b, n);
  139. random_students(c, n);
  140.  
  141. for (int i = 0; i < n; i++)
  142. c[i].print();
  143. cout << endl;
  144. /* Sort_insert(c, n);
  145. for (int i = 0; i < n; i++)
  146. c[i].print();*/
  147.  
  148. ShellSort(c, n);
  149. for (int i = 0; i < n; i++)
  150. c[i].print();
  151. return 0;
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement