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

Создать список работников предприятия C++

Создать список работников предприятия (количество запрашивается с клавиатуры), содержащий: фамилию, стаж работы и заработную плату. Вывести этот список в виде таблицы. C++
Помогите, пожалуйста.
#include <iostream>
#include <iomanip>
#include <string>
#include <list>
using namespace std;
struct Employee {
Employee()
: name("unknown"), salary(0), experience(0) {}
Employee(string& name, const double salary, const int experience)
: name(name), salary(salary), experience(experience) {
const auto length = name.length();
if (max_length < length) max_length = length;
}
string name;
double salary;
int experience;
friend ostream& operator<<(ostream& out, const Employee& employee) {
out << left << setw(max_length) << employee.name
<< right << setw(4) << employee.experience
<< right << setw(11) << employee.salary
<< '\n';
return out;
}
static streamsize max_length;
};
streamsize Employee::max_length = 7;
class Employees {
public:
Employees() = default;
Employees(const Employees&) = default;
Employees& operator=(const Employees&) = default;
~Employees() = default;
Employees(Employees&&) = default;
Employees& operator=(Employees&&) = default;
void add(const Employee& employee) { list_.emplace_back(employee); }
void add(Employee&& employee) { list_.emplace_back(employee); }
void show()const { cout << *this; }
private:
list<Employee> list_;
friend ostream& operator<<(ostream& out, const Employees& table) {
size_t num = 0;
for (const auto &row : table.list_) cout << setw(3) << ++num << ". " << row;
return out;
}
};
void input(Employees& box, const size_t size) {
for (auto i = 0u; i < size; ++i) {
cout << "Name: ";
string name;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
getline(cin, name);
cout << "Experience: ";
int experience;
cin >> experience;
cout << "Salary: ";
double salary;
cin >> salary;
box.add(Employee(name, salary, experience));
}
}
int main() {
Employees employees;
cout << "Size: ";
size_t size;
cin >> size;
input(employees, size);
system("cls");
employees.show();
system("pause");
}
ІТ
Іллюшка Ткач
55 182
Лучший ответ
#include
#include
#include
#include
using namespace std;
struct WORKER {
char F[30];
char I[30];
char O[30];
char Name[30];
int Year; };
int main(int argc, char* argv[])
{ setlocale(LC_ALL, "Russian");
const int size =2;
int i,b,c = 0;
WORKER a[size+1];
cout << "Введите искомый стаж работы: ";
cin >> b; cout << endl; for (i=0; i<=size; i++ )
{ cout << "Введите информацию об " << i + 1 << "-м работнике " << endl;
cout << "Фамилия: ";
cin >> a[i].F;
cout << "Имя: ";
cin >> a[i].I;
cout << "Отчество: ";
cin >> a[i].O;
cout << endl;
cout << "Его должность: ";
cin >> a[i].Name;
cout << endl;
cout << "Год поступления на работу: "; cin >> a[i].Year;
cout << endl; cout << "______________________________________________" << endl; }
cout << "Список работников, со стажем более " << b << " лет:" << endl;
for ( i = 0; i <=size; i++) { if ( b < (2020 - a[i].Year) )
{ c++; cout << c << ". " << a[i].F << a[i].I << a[i].O << endl;
}
} if ( c == 0 )
{ cout << " -----"; } return 0; }
Dfgd Dg
Dfgd Dg
113