Другие языки программирования и технологии

Упорядочить сведения о сотрудниках, имеющих рабочий стаж более 20 лет, в порядке возрастания их возраста С++

Здравствуйте, помогите пожалуйста написать программу с помощью структур. Спасибо )
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <algorithm>
#include <iomanip>
#include <ctime>
using namespace std;
struct Employee {
Employee(const string& n, int b, int d, char s) : name(n), birthday(b), edate(d), sex(s) {}
string name;
int birthday;
int edate;
char sex;
friend ostream& operator<<(ostream& out, const Employee& emp) {
out << left << setw(18) << emp.name
<< right << setw(4) << emp.sex
<< right << setw(7) << emp.birthday
<< right << setw(7) << emp.edate;
return out;
}
};
struct Employees {
Employees() = default;
Employees(const vector<Employee>& emps) : box(emps) {}
vector<Employee> box;
void add(const Employee& emp) {
box.push_back(emp);
}
void add(Employee&& emp) {
box.emplace_back(emp);
}
void show()const noexcept {
auto n = 0;
for (const auto& emp : box) cout << setw(3) << ++n << ". " << emp << '\n';
}
Employees select(function<bool(const Employee&)> fn) noexcept {
Employees tmp;
for (const auto& emp : box) if (fn(emp)) tmp.add(emp);
return tmp;
}
void order_by_age() {
auto comp = [](Employee& a, Employee& b) {
return a.birthday > b.birthday;
};
sort(box.begin(), box.end(), comp);
}
};
int sys_year() {
tm sys_time;
__time64_t time;
_time64(&time);
_localtime64_s(&sys_time, &time);
return sys_time.tm_year + 1900;
}
vector<Employee> data() {
return vector<Employee>{
{ "Анисимов Ю. П.", 1940, 1957, 'М' },
{ "Иванов Р. З.", 1950, 1975, 'М' },
{ "Махова З. Э.", 1960, 1980, 'Ж' },
{ "Огарев Р. Х.", 1945, 1961, 'М' },
{ "Егорова И. Т.", 1955, 1977, 'Ж' },
{ "Голикова У. Л.", 1962, 1980, 'Ж' },
{ "Сотников П. С.", 1943, 1960, 'М' },
{ "Комов В. Ф.", 1947, 1964, 'М' },
{ "Лебедев Н. В.", 1959, 1981, 'М' },
{ "Димова С. Ш.", 1965, 1985, 'Ж' },
{ "Шангина Д. Ж.", 1974, 1996, 'Ж' },
{ "Беликова К. З.", 1980, 2005, 'Ж' },
{ "Михайлов П. А.", 1982, 2005, 'М' },
{ "Феоктистов В. Р.", 1976, 1990, 'М' },
{ "Яковлева В. Д.", 1994, 2012, 'Ж' },
{ "Юндина Е. М.", 1950, 1970, 'М' },
{ "Борисенко Ф. Л.", 1986, 2000, 'М' },
{ "Мясникова М. Т.", 1979, 1999, 'Ж' },
{ "Зотова Г. М.", 1982, 2005, 'Ж' },
{ "Жарникова М. Л.", 1974, 1996, 'Ж' },
{ "Семенова М. Д.", 1995, 2012, 'Ж' }
};
}
int main() {
system("chcp 1251 > nul");
auto table = data();
Employees box(table);
box.show();
cout.put('\n');
const auto experience = 20;
const auto year = sys_year();
auto predicate = [experience, year](const Employee& emp) {
return year - emp.edate > experience;
};
auto selection = box.select(predicate);
selection.order_by_age();
selection.show();
cout.put('\n');
system("pause");
}
ДН
Дима Никитин
59 004
Лучший ответ
Алексей Аистов Большое спасибо )

Похожие вопросы