Advertisement
mitkonikov

techcompany

Apr 2nd, 2023
488
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.27 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. class Employee {
  6. private:
  7.     string name;
  8.     string surname;
  9.     int salary;
  10.  
  11. public:
  12.     Employee() { }
  13.  
  14.     Employee(string n, string s, int plata) {
  15.         name = n;
  16.         surname = s;
  17.         salary = plata;
  18.     }
  19.  
  20.     Employee(const Employee& e) {
  21.         name = e.getName();
  22.         surname = e.getSurname();
  23.         salary = e.getSalary();
  24.     }
  25.  
  26.     void setName(string s) {
  27.         name = s;
  28.     }
  29.     void setSurname(string s) {
  30.         surname = s;
  31.     }
  32.     void setSalary(int s) {
  33.         salary = s;
  34.     }
  35.     string getName() const { return name; }
  36.     string getSurname() const { return surname; }
  37.     int getSalary() const { return salary; }
  38.  
  39.     void print() {
  40.         cout << "Employee name: " << name << endl;
  41.         cout << "Employee surname: " << surname << endl;
  42.         cout << "Employee salary: " << salary << endl;
  43.     }
  44. };
  45.  
  46. class TechCompany {
  47. private:
  48.     string name;
  49.     Employee* employees;
  50.     int numOfEmployees = 0;
  51.  
  52. public:
  53.     TechCompany() {
  54.         name = "";
  55.         employees = new Employee[100];
  56.         numOfEmployees = 0;
  57.     }
  58.  
  59.     TechCompany(string s, Employee* e, int n) {
  60.         name = s;
  61.         employees = e;
  62.         numOfEmployees = n;
  63.     }
  64.  
  65.     ~TechCompany() {
  66.         delete employees;
  67.     }
  68.  
  69.     string getName() {
  70.         return name;
  71.     }
  72.     int getNumOfEmployees() {
  73.         return numOfEmployees;
  74.     }
  75.  
  76.     void print() {
  77.         cout << "Tech company name: " << name << endl;
  78.         cout << "Number of employees: " << numOfEmployees << endl;
  79.     }
  80.  
  81.     double getAverageOfEmployeesSalary() {
  82.         double result = 0;
  83.         for (int i = 0; i < numOfEmployees; i++) {
  84.             result += employees[i].getSalary();
  85.         }
  86.         return result / numOfEmployees;
  87.     }
  88. };
  89.  
  90. TechCompany printCompanyWithHighestAverageSalary(TechCompany companies[], int numCompanies) {
  91.     int best_index = 0;
  92.     for (int i = 0; i < numCompanies; i++) {
  93.         if (companies[i].getAverageOfEmployeesSalary() > companies[best_index].getAverageOfEmployeesSalary()) {
  94.             best_index = i;
  95.         }
  96.     }
  97.     return companies[best_index];
  98. }
  99.  
  100. int main() {
  101.     // KE VI BIDE DADENA
  102.     return 0;
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement