Răspuns :
Răspuns:
#include <iostream>
#include <vector>
namespace Utils
{
namespace Constants
{
const char* UNKNOWN_STRING = "UNKOWN";
}
namespace Enums
{
enum Departments
{
DEPARTMENT_UNKOWN = -1,
DEPARTMENT_FINANCE,
DEPARTMENT_SALES,
DEPARTMENT_PRODUCTION,
DEPARTMENT_HR,
NUM_DEPARTMENTS
};
}
namespace Classes
{
class HelpfulClass
{
public:
static float GetWorkerSalary(const float hourlyWage, const float timeSpent)
{
return hourlyWage * timeSpent;
}
static void PrintSalaries(const float financeSalary, const float salesSalary, const float productionSalary, const float HRSalaries, const float wholeSalaries)
{
std::cout << "==========================Cost salarii personal==========================" << std::endl;
std::cout << "Cost departamentul de finante: " << financeSalary << std::endl;
std::cout << "Cost departamentul de vanzari: " << salesSalary << std::endl;
std::cout << "Cost departamentul de productie: " << productionSalary << std::endl;
std::cout << "Cost departamentul de HR: " << HRSalaries << std::endl;
std::cout << std::endl;
std::cout << "Cost total salarii: " << wholeSalaries << std::endl;
}
};
}
}
class Worker
{
public:
Worker() :
mName(Utils::Constants::UNKNOWN_STRING),
mSurname(Utils::Constants::UNKNOWN_STRING),
mDepartment(Utils::Enums::Departments::DEPARTMENT_UNKOWN),
mHourlyWage(0),
mWorkSpent(0),
mSalary(0)
{}
Worker(const char* name, const char* surname, Utils::Enums::Departments department, float hourlyWage, float workSpent) :
mName(name),
mSurname(surname),
mDepartment(department),
mHourlyWage(hourlyWage),
mWorkSpent(workSpent)
{}
// Copy constructor
Worker(const Worker& other) :
mName(other.mName),
mSurname(other.mSurname),
mDepartment(other.mDepartment),
mHourlyWage(other.mHourlyWage),
mWorkSpent(other.mWorkSpent),
mSalary(other.mSalary)
{}
// nu e necesar, mie-mi place sa-l pun ca sa-l diferentiez usor metode de constructori si alte chestii
public:
Utils::Enums::Departments GetDepartment() const { return mDepartment; }
float GetHourlyWage() const { return mHourlyWage; }
float GetWorkSpent() const { return mWorkSpent; }
float GetSalary() const { return mSalary; }
void CalculateSalary(float wage, float hours)
{
mSalary = Utils::Classes::HelpfulClass::GetWorkerSalary(wage, hours);
}
private:
std::string mName;
std::string mSurname;
Utils::Enums::Departments mDepartment;
float mHourlyWage;
float mWorkSpent; // in hours
float mSalary;
};
class Factory // I cringe so hard at this name.... It's not the Design Pattern Factory
{
public:
Factory(const std::vector<Worker>& workers) :
mWorkers(workers)
{}
Factory(const Factory& other) = delete;
std::vector<Worker> GetWorkers() { return mWorkers; }
int GetNumberOfWorkers() { return mWorkers.size(); }
void CalculateFactorySalaryCosts()
{
float financeSalariesCosts = 0.0f;
float salesSalariesCosts = 0.0f;
float productionSalariesCosts = 0.0f;
float HRSalariesCosts = 0.0f;
float wholeSalariesCosts = 0.0f;
for (auto& worker : mWorkers)
{
worker.CalculateSalary(worker.GetHourlyWage(), worker.GetWorkSpent());
float workerSalary = worker.GetSalary();
Utils::Enums::Departments workerDepartment = worker.GetDepartment();
switch (workerDepartment)
{
case Utils::Enums::DEPARTMENT_FINANCE:
{
financeSalariesCosts += workerSalary;
wholeSalariesCosts += workerSalary;
break;
}
case Utils::Enums::DEPARTMENT_SALES:
{
salesSalariesCosts += workerSalary;
wholeSalariesCosts += workerSalary;
break;
}
case Utils::Enums::DEPARTMENT_PRODUCTION:
{
productionSalariesCosts += workerSalary;
wholeSalariesCosts += workerSalary;
break;
}
case Utils::Enums::DEPARTMENT_HR:
{
HRSalariesCosts += workerSalary;
wholeSalariesCosts += workerSalary;
break;
}
default:
std::cout << "Err: department not found!. Department: " << static_cast<int>(workerDepartment);
break;
}
}
Utils::Classes::HelpfulClass::PrintSalaries(financeSalariesCosts, salesSalariesCosts, productionSalariesCosts, HRSalariesCosts, wholeSalariesCosts);
}
private:
std::vector<Worker> mWorkers;
};
int main()
{
using Utils::Enums::Departments;
Worker worker1 = Worker("Alex", "Popescu", Departments::DEPARTMENT_FINANCE, 30.5, 40);
Worker worker2 = Worker("Traian", "Basescu", Departments::DEPARTMENT_SALES, 22.5, 70);
Worker worker3 = Worker("Dani", "Mocanu", Departments::DEPARTMENT_PRODUCTION, 29.5, 80);
Worker worker4 = Worker("Gabriela", "Firea", Departments::DEPARTMENT_HR, 20, 10);
std::vector<Worker> workers;
workers.push_back(worker1);
workers.push_back(worker2);
workers.push_back(worker3);
workers.push_back(worker4);
Factory factory(workers);
factory.CalculateFactorySalaryCosts();
}
Explicație:
Vă mulțumim că ați ales să vizitați site-ul nostru dedicat Informatică. Sperăm că informațiile disponibile v-au fost utile. Dacă aveți întrebări sau aveți nevoie de asistență suplimentară, vă rugăm să ne contactați. Revenirea dumneavoastră ne va bucura, iar pentru acces rapid, nu uitați să ne salvați la favorite!