
C/C++
Помогите решить задачу пожалуйста С++

#include <iostream>
#include <string>
#include <regex>
#include <vector>
using namespace std;
void flush(istream& stream = cin) {
stream.ignore(stream.rdbuf()->in_avail());
}
class Employee {
public:
Employee() : salary_(0), number_(0) {}
void salary(unsigned value) { salary_ = value; }
void number(unsigned value) { number_ = value; }
void name(string value) { name_ = value; }
void address(string value) { address_ = value; }
void date(string value) { date_ = value; }
unsigned salary()const { return salary_; }
unsigned number()const { return number_; }
string name()const { return name_; }
string address()const { return address_; }
string date()const { return date_; }
private:
unsigned salary_;
unsigned number_;
string name_;
string address_;
string date_;
friend ostream& operator<<(ostream& out, const Employee& emp) {
return out
<< emp.name_ << "\n\t"
<< emp.address_ << "\n\t"
<< emp.date_ << "\n\t"
<< emp.salary_ << "\n\t"
<< emp.number_ << "\n\t";
}
friend istream& operator>>(istream& inp, Employee& emp) {
cout << "Ф. И. О.: ";
getline(inp, emp.name_);
emp.trim_space_(emp.name_);
cout << "Адрес: ";
getline(inp, emp.address_);
emp.trim_space_(emp.address_);
cout << "Дата приёма на работу: ";
getline(inp, emp.date_);
emp.trim_space_(emp.date_);
cout << "Годовой заработок: ";
inp >> emp.salary_;
flush(inp);
cout << "Номер отдела: ";
inp >> emp.number_;
flush(inp);
return inp;
}
void trim_space_(string& line) {
line = regex_replace(line, regex(" +"), " ");
line.erase(0, line.find_first_not_of(" "));
line.erase(line.find_last_not_of(" ") + 1);
}
};
class Firm {
public:
vector<Employee> numbers(unsigned value)const {
vector<Employee> box;
for (const auto& emp : box_) {
if (emp.number() == value) {
box.push_back(emp);
}
}
return box;
}
void add(const Employee& emp) { box_.push_back(emp); }
void add(Employee&& emp) { box_.emplace_back(emp); }
void show_all()const { for (auto& emp : box_) cout << emp << '\n'; }
private:
vector<Employee> box_;
};
int main() {
system("chcp 1251 > nul");
cout << "Количество сотрудников: ";
size_t n;
cin >> n;
flush();
Firm firm;
Employee emp;
for (auto i = 0U; i < n; ++i) {
cin >> emp;
firm.add(emp);
system("cls");
}
firm.show_all();
puts("---------------------------------------------");
const auto number = 5U;
auto numbers = firm.numbers(number);
for (const auto& item : numbers) cout << item << '\n';
system("pause > nul");
}
#include <string>
#include <regex>
#include <vector>
using namespace std;
void flush(istream& stream = cin) {
stream.ignore(stream.rdbuf()->in_avail());
}
class Employee {
public:
Employee() : salary_(0), number_(0) {}
void salary(unsigned value) { salary_ = value; }
void number(unsigned value) { number_ = value; }
void name(string value) { name_ = value; }
void address(string value) { address_ = value; }
void date(string value) { date_ = value; }
unsigned salary()const { return salary_; }
unsigned number()const { return number_; }
string name()const { return name_; }
string address()const { return address_; }
string date()const { return date_; }
private:
unsigned salary_;
unsigned number_;
string name_;
string address_;
string date_;
friend ostream& operator<<(ostream& out, const Employee& emp) {
return out
<< emp.name_ << "\n\t"
<< emp.address_ << "\n\t"
<< emp.date_ << "\n\t"
<< emp.salary_ << "\n\t"
<< emp.number_ << "\n\t";
}
friend istream& operator>>(istream& inp, Employee& emp) {
cout << "Ф. И. О.: ";
getline(inp, emp.name_);
emp.trim_space_(emp.name_);
cout << "Адрес: ";
getline(inp, emp.address_);
emp.trim_space_(emp.address_);
cout << "Дата приёма на работу: ";
getline(inp, emp.date_);
emp.trim_space_(emp.date_);
cout << "Годовой заработок: ";
inp >> emp.salary_;
flush(inp);
cout << "Номер отдела: ";
inp >> emp.number_;
flush(inp);
return inp;
}
void trim_space_(string& line) {
line = regex_replace(line, regex(" +"), " ");
line.erase(0, line.find_first_not_of(" "));
line.erase(line.find_last_not_of(" ") + 1);
}
};
class Firm {
public:
vector<Employee> numbers(unsigned value)const {
vector<Employee> box;
for (const auto& emp : box_) {
if (emp.number() == value) {
box.push_back(emp);
}
}
return box;
}
void add(const Employee& emp) { box_.push_back(emp); }
void add(Employee&& emp) { box_.emplace_back(emp); }
void show_all()const { for (auto& emp : box_) cout << emp << '\n'; }
private:
vector<Employee> box_;
};
int main() {
system("chcp 1251 > nul");
cout << "Количество сотрудников: ";
size_t n;
cin >> n;
flush();
Firm firm;
Employee emp;
for (auto i = 0U; i < n; ++i) {
cin >> emp;
firm.add(emp);
system("cls");
}
firm.show_all();
puts("---------------------------------------------");
const auto number = 5U;
auto numbers = firm.numbers(number);
for (const auto& item : numbers) cout << item << '\n';
system("pause > nul");
}
for(auto i:data)if(i.num==5)cout<<i.fio<<....;
Олег Саночкин
==
Похожие вопросы
- Помогите решить задачу пожалуйста, в C++
- Помогите решить задачу, пожалуйста. (Язык Си)
- Помогите решить задачу, пожалуйста. Сам не понимаю. (Язык Си)
- Помогите решить задачу по программированию на C++
- Помогите решить задачу по C++!
- Помогите решить задачу по программированию
- Помогите решить задачу C++, пожалуйста.
- Помогите решить задачу на c++
- Помогите решить задачу на С++ (мне не совсем ясен смысл задания)
- Помогите решить задачу на С++, используя статические массивы