SHARE
TWEET

Untitled

a guest Mar 19th, 2019 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Employee
  2. {
  3. public:
  4.     int get_salary() const { return m_salary; }
  5.     int get_balance() const { return m_balance; }
  6.     void pay_salary() { m_balance += m_salary; }
  7.    
  8.     bool operator== (const Employee& rhs) const
  9.     {
  10.         return m_name == rhs.m_name &&
  11.                m_age == rhs.m_age &&
  12.                m_salary == rhs.m_salary &&
  13.                m_balance == rhs.m_balance;
  14.     }
  15.  
  16. private:
  17.     std::string m_name;
  18.     int         m_age;
  19.     int         m_salary;
  20.     int         m_balance;
  21. };
  22.  
  23. int main()
  24. {
  25.     // ...
  26.     auto employee_less_than = [] (const Employee& lhs, const Employee& rhs)
  27.             {
  28.                 return lhs.get_balance() < rhs.get_balance();
  29.             };
  30.     std::multiset<Employee, decltype(employee_less_than)> employees_sorted(employee_less_than);
  31.     // ...
  32.     int total_funds /* = ... */;
  33.     for (auto& e : employees_sorted) {
  34.         if (e.get_salary() <= total_funds) {
  35.             total_funds -= e.get_salary();
  36.             const_cast<Employee&>(e).pay_salary();
  37.         }
  38.     }
  39.     // ...
  40. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top