fork download
  1. class IEmployee
  2. {
  3. public:
  4. virtual double salary() const = 0;
  5. };
  6.  
  7. class Employee : public IEmployee
  8. {
  9. public:
  10. Employee(unsigned id);
  11. double salary() const override;
  12.  
  13. private:
  14. double baseRate() const;
  15. double workExperience() const;
  16. double extraPercents() const;
  17. double percentsPerYear() const;
  18. double extraPay(double base, double percents) const;
  19.  
  20. unsigned id;
  21. };
  22.  
  23.  
  24. Employee::Employee(unsigned id)
  25. : id(id)
  26. {
  27.  
  28. }
  29.  
  30. double Employee::extraPay(double baseRate, double extraPayPercents) const
  31. {
  32. static const double EXTRA_PAY_LIMIT = 0.3;
  33.  
  34. if (extraPayPercents < EXTRA_PAY_LIMIT)
  35. return baseRate * extraPayPercents;
  36. else
  37. return baseRate * EXTRA_PAY_LIMIT;
  38. }
  39.  
  40. double Employee::percentsPerYear() const
  41. {
  42. return 0.03;
  43. }
  44.  
  45. double Employee::extraPercents() const
  46. {
  47. return percentsPerYear() * workExperience();
  48. }
  49.  
  50. double Employee::salary() const
  51. {
  52. double rate = baseRate();
  53. return rate + extraPay(rate, extraPercents());
  54. }
  55.  
  56. double Employee::baseRate() const
  57. {
  58. QSqlQuery q("SELECT base_rate FROM employee WHERE id = " + QString::number(id));
  59. if (q.next())
  60. {
  61. return q.value(0).toInt();
  62. }
  63. return 0.0;
  64. }
  65.  
  66. double Employee::workExperience() const
  67. {
  68. QSqlQuery q("SELECT DATE('now') - (SELECT hire_date FROM employee " \
  69. " WHERE id = " + QString::number(id) + ")");
  70. if (q.next())
  71. {
  72. return q.value(0).toInt();
  73. }
  74. return 0.0;
  75. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In member function ‘double Employee::baseRate() const’:
prog.cpp:58:2: error: ‘QSqlQuery’ was not declared in this scope
  QSqlQuery q("SELECT base_rate FROM employee WHERE id = " + QString::number(id));
  ^~~~~~~~~
prog.cpp:59:6: error: ‘q’ was not declared in this scope
  if (q.next())
      ^
prog.cpp: In member function ‘double Employee::workExperience() const’:
prog.cpp:68:2: error: ‘QSqlQuery’ was not declared in this scope
  QSqlQuery q("SELECT DATE('now') - (SELECT hire_date FROM employee " \
  ^~~~~~~~~
prog.cpp:70:6: error: ‘q’ was not declared in this scope
  if (q.next())
      ^
stdout
Standard output is empty