alarm
Задайте вопрос
Информатика
Martha Gordon

C++Сделать на структурахНа предприятии необходимо хранить данные о работниках: фамилию, имя, отчество, дата рождения, должность, стаж. Вывести на экран данные о тех работников, которые на текущий момент времени достигли 37 лет и имеют стаж не менее 10 лет.

ответы: 1
Зарегистрируйтесь, чтобы добавить ответ
Ответ:
  • #include <iostream>
  • #include <utility>
  • #include <vector>
  • #include <list>
  • #include <ctime>
  • #include <string>
  • namespace business {
  • using namespace std;
  • struct Date {
  • int day;
  • int month;
  • int year;
  • Date() = default;
  • Date(int _day, int _month, int _year) : day(_day), month(_month), year(_year) {}
  • explicit Date(tm date) {
  • day = date. tm_mday;
  • month = date. tm_mon;
  • year = date. tm_year;
  • }
  • ~Date() = default;
  • Date operator- (Date& date) const {
  • Date diff{};
  • diff. year = year;
  • diff. month = month;
  • diff. day = day;
  • diff. day -= date. day;
  • if (diff. day <= 0) {
  • diff. day = 31 - diff. day;
  • diff. month -= 1;
  • }
  • diff. month -= date. month;
  • if (diff. month <= 0) {
  • diff. month = 12 - diff. month;
  • diff. year -= 1;
  • }
  • diff. year -= date. year;
  • return diff;
  • }
  • };
  • struct Worker {
  • string fio;
  • Date birthday{};
  • string job;
  • int stage{};
  • Worker() = default;
  • Worker(string fio, Date birthday, string job, int stage){
  • this->fio = move(fio);
  • this->birthday = birthday;
  • this->job = move(job);
  • this->stage = stage;
  • }
  • ~Worker() = default;
  • };
  • struct Business {
  • private:
  • vector<Worker> workers;
  • public:
  • Business() = default;
  • ~Business() = default;
  • void AddWorker(const Worker& worker) {
  • workers. push_back(worker);
  • }
  • vector<Worker> const& GetWorkers() const {
  • return workers;
  • }
  • };
  • struct BusinessManager {
  • private:
  • Business business;
  • public:
  • BusinessManager() {
  • business = Business();
  • }
  • ~BusinessManager() = default;
  • void AddWorker() {
  • auto worker = Worker();
  • cout << "Enter FIO: ";
  • while(worker. fio. empty()) getline(cin, worker. fio);
  • Date birthday{};
  • cout << "Enter birthday (Day Month Year): ";
  • cin >> birthday. day >> birthday. month >> birthday. year;
  • worker. birthday = birthday;
  • cout << "Enter job's name: ";
  • while (worker. job. empty()) getline(cin, worker. job);
  • cout << "Enter stage (unsig int numb): ";
  • cin >> worker. stage;
  • business. AddWorker(worker);
  • }
  • void FindWorkers() {
  • auto workers = business. GetWorkers();
  • Date today(7, 5, 2021);
  • std::vector<std::vector<Worker>::const_iterator> matches;
  • for (auto justWorker = workers. begin(); justWorker != workers. end(); ++justWorker){
  • if ((today - justWorker->birthday). year >= 37 && justWorker->stage >= 10) {
  • matches. emplace_back(justWorker);
  • }
  • }
  • for (auto & worker : matches) {
  • auto buff = *worker;
  • cout << "FIO: " << buff. fio << endl
  • << "Birthday: " << buff. birthday. day << ". " << buff. birthday. month << ". " << buff. birthday. year << endl
  • << "Job's title: " << buff. job << endl
  • << "Stage: " << buff. stage << endl << endl;
  • }
  • }
  • };
  • }
  • int main () {
  • using namespace business;
  • BusinessManager manager;
  • bool isStillRunning = true;
  • while (isStillRunning) {
  • cout << "[1] Add worker into company" << endl;
  • cout << "[2] Find workers with age >= 37 and stage >= 10" << endl;
  • cout << "[0] Exit" << endl;
  • cout << "Your decision >> ";
  • int decision = -1;
  • cin >> decision;
  • cout << endl;
  • switch (decision) {
  • case 0: isStillRunning = false; break;
  • case 1: manager. AddWorker(); break;
  • case 2: manager. FindWorkers(); break;
  • default: cout << "[Warning] You enter some trash!" << endl << endl; continue;
  • }
  • cout << endl;
  • }
  • return 0;
  • }
415
Aleksandra
Чтобы ответить необходимо зарегистрироваться.

Другие вопросы: - Информатика

5Выполняем на компьютере1. Испол

Что получится в результате дейст

Задание "Перемена"Заданы три  чи

можно ли второе задание посчитат

посчитайте С ОБЪЯСНЕНИЕМ.Звукоза

Напишіть програму, яка зчитує ці

Контакты
Реклама на сайте