Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <iostream>
- #include <conio.h>
- #include <time.h>
- #include <random>
- #include <string>
- using namespace std;
- template <typename x>
- void Sort_insert(x*a, int n)
- {
- int j;
- for (int i = 1; i < n; i++)
- {
- j = i;
- while (a[j - 1] > a[j] && j > 0)
- {
- swap(a[j - 1], a[j]);
- j--;
- }
- }
- }
- template <typename x>
- void ShellSort(x*a, int n)
- {
- int i, j, step;
- x tmp;
- for (step = n / 2; step > 0; step /= 2)
- for (i = step; i < n; i++)
- {
- tmp = a[i];
- for (j = i; j >= step; j -= step)
- {
- if (tmp < a[j - step])
- a[j] = a[j - step];
- else
- break;
- }
- a[j] = tmp;
- }
- }
- struct student
- {
- string name, surname;
- int marks[5];
- bool operator < (student b)
- {
- if (surname != b.surname)
- return surname < b.surname;
- else return name < b.name;
- }
- bool operator > (student b)
- {
- if (surname != b.surname)
- return surname > b.surname;
- else return name > b.name;
- }
- bool operator == (student b)
- {
- return name == b.name && surname == b.surname;
- }
- void print()
- {
- cout << surname << " " << name << " ";
- for (int i = 0; i < 5; i++)
- cout << marks[i] << " ";
- cout << endl;
- }
- };
- void random_students(student*c, int n)
- {
- string names[] = { "Andrey", "Sergey", "Nastya", "Alena", "Misha", "Sasha", "Vanya","Elena" };
- string surnames[] = { "Brown", "Green", "Yellow", "Black", "White", "Vaselenko", "Poroshenko", "Glinko", "Vasilisko", "Potter", "Portenko" };
- srand(time(0));
- for (int i = 0; i < n; i++)
- {
- c[i].name = names[rand() % 8];
- c[i].surname = surnames[rand() % 11];
- for (int j = 0; j < 5; j++)
- {
- c[i].marks[j] = 1 + rand() % 5;
- }
- }
- }
- template <typename x>
- void random_numbers(x*a, int size) //рандом чисел
- {
- srand(time(NULL)); // инициализируем рандом
- int i; //переменные цикла, кол-во элементов массива
- x *list = new x[size]; // целевой массив
- for (i = 0; i < size; i++)
- list[i] = (rand() % RAND_MAX);
- for (i = 0; i < size; i++)
- cout << list[i] << " ";
- cout << endl;
- }
- void random_string(string*b, int n) //рандом стринга
- {
- srand(time(0));
- for (int i = 0; i < n; ++i)
- for (int j = 0; j < 1 + rand() % 5; j++)
- {
- b[i] += 97 + rand() % 25;
- }
- for (int i = 0; i < n; i++)
- cout << b[i] << " ";
- cout << endl;
- }
- int main()
- {
- int n;
- cin >> n;
- int* a = new int[n];
- string* b = new string[n];
- student* c = new student[n];
- random_numbers(a, n);
- random_string(b, n);
- random_students(c, n);
- for (int i = 0; i < n; i++)
- c[i].print();
- cout << endl;
- /* Sort_insert(c, n);
- for (int i = 0; i < n; i++)
- c[i].print();*/
- ShellSort(c, n);
- for (int i = 0; i < n; i++)
- c[i].print();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement