kokokozhina

datasort_16

Feb 18th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.18 KB | None | 0 0
  1. #include <iostream>//bug
  2. #include <string>
  3. #include <fstream>
  4. #include <vector>
  5. #include <algorithm>
  6. #include <iomanip>
  7. //По дате рождения с помощью сортировки блочной сортировки (Bucket sort).
  8. using namespace std;
  9. //В файле содержатся данные о сотрудниках предприятия: ФИО, должность,
  10. //дата рождения, стаж работы, зарплата (не менее 20 человек). В новый файл вывести
  11. //данные, отсортированные по какому-либо ключу
  12.  
  13. struct worker
  14. {
  15.     string surname;
  16.     string name;
  17.     string patronymic;
  18.     string position;
  19.     string birth_date;
  20.     string exp;
  21.     string salary;
  22.     string birth_year;
  23.     string birth_month;
  24.     string birth_day;
  25. };
  26.  
  27. void birthTime(vector<worker> &vec)
  28. {
  29.     for(int i = 0; i < vec.size(); i++)
  30.     {
  31.         vec[i].birth_day = vec[i].birth_date.substr(vec[i].birth_date.length() - 10, 2);
  32.         vec[i].birth_month = vec[i].birth_date.substr(vec[i].birth_date.length() - 7, 2);
  33.         vec[i].birth_year = vec[i].birth_date.substr(vec[i].birth_date.length() - 4, 4);
  34.     }
  35. }
  36.  
  37. void bucketSort(vector<worker> &vec)
  38. {
  39.     /*int maxValue = 0;
  40.     int minValue = 0;
  41.     for(int i = 1; i < vec.size(); i++)
  42.     {
  43.         if (vec[i] > maxValue)
  44.             maxValue = items[i];
  45.  
  46.         if (items[i] < minValue)
  47.             minValue = items[i];
  48.     }*/
  49. }
  50.  
  51.  
  52. int main()
  53. {
  54.     ifstream in("in.txt");
  55.     ofstream out("out.txt");
  56.     vector<worker> vec;
  57.     while(in.peek() != EOF)
  58.     {
  59.         worker result;
  60.         in >> result.surname >> result.name >> result.patronymic >> result.position >> result.birth_date >> result.exp >> result.salary;
  61.         vec.push_back(result);
  62.     }
  63.     birthTime(vec);
  64.  
  65.     for(int i = 0; i < vec.size(); i++)
  66.     {
  67.         cout << vec[i].birth_day << " " << vec[i].birth_month << " " << vec[i].birth_year << endl;
  68.         out << left << setw(20) << vec[i].surname << setw(20) << vec[i].name << setw(20) << vec[i].patronymic << setw(20) << vec[i].position << setw(20) << vec[i].birth_date << setw(20) << vec[i].exp << setw(20) << vec[i].salary << endl;
  69.     }
  70.     system("pause");
  71. }
Add Comment
Please, Sign In to add comment