Advertisement
gasaichan

11

May 6th, 2018
389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.17 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <conio.h>
  4. #include <clocale>
  5.  
  6. using namespace std;
  7.  
  8. struct employee {
  9.     string surname;
  10.     string department_name;
  11.     int year_of_birth;
  12.     string speciality;
  13.     int experience;
  14.     int salary;
  15. };
  16.  
  17. void show_sorted_by_experience( employee employees [], int n ) {
  18.     int changes = 1;
  19.     employee temp_employee;
  20.     while ( changes != 0 ) {
  21.         for ( int i = 0; i < n; i++ ) {
  22.             changes = 0;
  23.             for ( int j = i + 1; j < n; j++ ) {
  24.                 if ( employees[i].experience > employees[j].experience ) {
  25.                     temp_employee = employees[i];
  26.                     employees[i] = employees[j];
  27.                     employees[j] = temp_employee;
  28.                     changes++;
  29.                 }
  30.             }
  31.         }
  32.     }
  33.  
  34.     cout << "Отсортированный массив работников по возрастанию стажа: " << endl;
  35.     for ( int i = 0; i < n; i++ ) {
  36.         cout << "Фамилия: " << employees[i].surname << "; Название отдела: " << employees[i].department_name << "; Год рождения: " << employees[i].year_of_birth << "; Стаж работы: " << employees[i].experience << "; Должность: " << employees[i].speciality << "; Оклад: " << employees[i].salary << endl;
  37.     }
  38. }
  39.  
  40. void show_by_experience( employee employees [], int n, int X) {
  41.     cout << "Работники со стажем больше " << X << " лет. " << endl;
  42.     for ( int i = 0; i < n; i++ ) {
  43.         if ( employees[i].experience > X ) {
  44.             cout << "Фамилия: " << employees[i].surname << "; Название отдела: " << employees[i].department_name << "; Год рождения: " << employees[i].year_of_birth << "; Стаж работы: " << employees[i].experience << "; Должность: " << employees[i].speciality << "; Оклад: " << employees[i].salary << endl;
  45.         }
  46.     }
  47. }
  48.  
  49. int main( )
  50. {
  51.  
  52.     setlocale( LC_ALL, "Russian" );
  53.     const int n = 4;
  54.     employee arr[n] = {
  55.         "asdasd", "dsa", 1989, "asdads", 6, 539254,
  56.         "dsadida", "dsad", 1990, "dsadsa", 2, 23923,
  57.         "dsadas", "sda", 1991, "asdfs", 10, 202222,
  58.         "dsadsadsa", "a", 1909, "dsa", 1, 200220
  59.     };
  60.  
  61.     show_sorted_by_experience( arr, n );
  62.     cout << endl << endl;
  63.     show_by_experience( arr, n, 4 );
  64.  
  65.     _getch( );
  66.     return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement