Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Employee
- {
- public:
- int get_salary() const { return m_salary; }
- int get_balance() const { return m_balance; }
- void pay_salary() { m_balance += m_salary; }
- bool operator== (const Employee& rhs) const
- {
- return m_name == rhs.m_name &&
- m_age == rhs.m_age &&
- m_salary == rhs.m_salary &&
- m_balance == rhs.m_balance;
- }
- private:
- std::string m_name;
- int m_age;
- int m_salary;
- int m_balance;
- };
- int main()
- {
- // ...
- auto employee_less_than = [] (const Employee& lhs, const Employee& rhs)
- {
- return lhs.get_balance() < rhs.get_balance();
- };
- std::multiset<Employee, decltype(employee_less_than)> employees_sorted(employee_less_than);
- // ...
- int total_funds /* = ... */;
- for (auto& e : employees_sorted) {
- if (e.get_salary() <= total_funds) {
- total_funds -= e.get_salary();
- const_cast<Employee&>(e).pay_salary();
- }
- }
- // ...
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement