Commiting all files connected to the project

This commit is contained in:
KUchy 2021-08-05 16:08:15 +02:00
commit ceeff16103
9 changed files with 1977 additions and 0 deletions

206
employee.cpp Executable file
View File

@ -0,0 +1,206 @@
#ifndef EMPLOYEE_CPP
#define EMPLOYEE_CPP
#ifndef DIMENSION
#define DIMENSION 3
#endif // DIMENSION
#ifndef HAZARDS
#define HAZARDS 3
#endif // HAZARDS
#ifndef STATE
#define STATE 3
#endif // STATE
#ifndef CERTIFICATES
#define CERTIFICATES 10
#endif // CERTIFICATES
#include "employee.hpp"
#include "equipment.hpp"
#include <iostream>
Employee::Employee(): equipmentTraining(CERTIFICATES), hazardTraining(HAZARDS),
statesTraining(STATE)
{
for(int i = 0; i < CERTIFICATES; i++)
{
equipmentTraining[i] = 0;
}
for(int i = 0; i < HAZARDS; i++)
{
hazardTraining[i] = 0;
}
for(int i = 0; i < STATE; i++)
{
statesTraining[i] = 0;
}
canRepair = 0;
Equipment assignedEquipment;
}
std::vector <bool> Employee::getEquipmentTraining() const
{
return equipmentTraining;
}
std::vector <bool> Employee::getHazardTraining() const
{
return hazardTraining;
}
std::vector <bool> Employee::getStatesTraining() const
{
return statesTraining;
}
Equipment Employee::getAssignedEquipment() const
{
return assignedEquipment;
}
bool Employee::getCanRepair() const
{
return canRepair;
}
void Employee::trainEquipment(int certificateNumber)
{
if(certificateNumber >= 0 && certificateNumber <= CERTIFICATES - 1)
{
equipmentTraining[certificateNumber] = 1;
}
}
void Employee::trainHazard(int certificateNumber)
{
if(certificateNumber >= 0 && certificateNumber <= HAZARDS - 1)
{
hazardTraining[certificateNumber] = 1;
}
}
void Employee::trainStates(int certificateNumber)
{
if(certificateNumber >= 0 && certificateNumber <= STATE - 1)
{
statesTraining[certificateNumber] = 1;
}
}
void Employee::trainRepair()
{
canRepair = 1;
}
bool Employee::canAssignEquipment(Equipment toBeAssigned) const
{
std::vector <bool> trainingNeeded = toBeAssigned.getTrainingRequired();
for(int i = 0; i < CERTIFICATES - 1; i++)
{
if((equipmentTraining[i] == 0) && (trainingNeeded[i] == 1)) return false;
}
return true;
}
void Employee::assignEquipment(Equipment &newEquipment)
{
if(canAssignEquipment(newEquipment)) assignedEquipment = newEquipment;
}
void Employee::removeEquipment()
{
Equipment emptyEquipment;
assignedEquipment = emptyEquipment;
}
bool Employee::canEmployeeMoveGoodState(Good &goodToMove) const
{
int goodState = goodToMove.getStateOfMatter();
return statesTraining[goodState];
}
bool Employee::canEmployeeMoveGoodHazard(Good &goodToMove) const
{
std::vector <bool> goodHazard = goodToMove.getHazard();
for(int i = 0; i < HAZARDS; i++)
{
if(hazardTraining[i] == 0 && goodHazard[i] == 1) return false;
}
return true;
}
bool Employee::canEmployeeMoveGood(Good &goodToMove) const
{
if(!canEmployeeMoveGoodState(goodToMove))
{
std::cout << "Employee can't move the state of this good" << std::endl;
return false;
}
if(!canEmployeeMoveGoodHazard(goodToMove))
{
std::cout << "Employee can't move the hazards of this good" << std::endl;
return false;
}
return true;
}
bool Employee::canMoveGood(Good &goodToMove, Equipment &toWhichMove, Equipment &fromWhichMove) const
{
if(!toWhichMove.canMoveGood(goodToMove))
{
std::cout << "Equipment toWhichWeMove cannot hold this good" << std::endl;
return false;
}
if(!fromWhichMove.canMoveGood(goodToMove))
{
std::cout << "Equipment fromWhichMove cannot move this good" << std::endl;
return false;
}
if(!canEmployeeMoveGood(goodToMove))
{
std::cout << "Employee cannot move this good" << std::endl;
return false;
}
if(!canAssignEquipment(fromWhichMove))
{
std::cout << "Employee cannot be assigned equipment fromWhichMove" << std::endl;
return false;
}
return true;
}
bool Employee::moveGood(Good &goodToMove, Equipment &toWhichMove, Equipment &fromWhichMove) const
{
if(canMoveGood(goodToMove, toWhichMove, fromWhichMove))
{
toWhichMove.setTimesUsed(toWhichMove.getTimesUsed() + 1);
fromWhichMove.setTimesUsed(fromWhichMove.getTimesUsed() + 1);
toWhichMove.occupySpaceGood(goodToMove);
return true;
}
return false;
}
void Employee::moveGoodOverride(Good &goodToMove, Equipment &toWhichMove) const
{
toWhichMove.setTimesUsed(toWhichMove.getTimesUsed() + 1);
toWhichMove.occupySpaceGood(goodToMove);
}
bool Employee::repairEquipment(Equipment &toRepair) const
{
if(getCanRepair() && toRepair.needsRepair())
{
toRepair.setTimesUsed(0);
return true;
}
return false;
}
#endif // EMPLOYE_CPP

46
employee.hpp Executable file
View File

@ -0,0 +1,46 @@
#ifndef EMPLOYEE_HPP
#define EMPLOYEE_HPP
#include <vector>
#include "equipment.hpp"
class Employee
{
private:
std::vector <bool> equipmentTraining;
std::vector <bool> hazardTraining;
std::vector <bool> statesTraining;
bool canRepair;
Equipment assignedEquipment;
public:
Employee();
std::vector <bool> getEquipmentTraining() const;
std::vector <bool> getHazardTraining() const;
std::vector <bool> getStatesTraining() const;
Equipment getAssignedEquipment() const;
bool getCanRepair() const;
void trainEquipment(int certificateNumber);
void trainHazard(int certificateNumber);
void trainStates(int certificateNumber);
void trainRepair();
void assignEquipment(Equipment &newEquipment);
void removeEquipment();
bool canAssignEquipment(Equipment toBeAssigned) const;
bool canEmployeeMoveGoodState(Good &goodToMove) const;
bool canEmployeeMoveGoodHazard(Good &goodToMove) const;
bool canEmployeeMoveGood(Good &goodToMove) const;
bool canMoveGood(Good &goodToMove, Equipment &toWhichMove, Equipment &fromWhichMove) const;
bool moveGood(Good &goodToMove, Equipment &toWhichMove, Equipment &fromWhichMove) const;
void moveGoodOverride(Good &goodToMove, Equipment &toWhichMove) const;
bool repairEquipment(Equipment &toRepair) const;
};
#endif

260
equipment.cpp Executable file
View File

@ -0,0 +1,260 @@
#ifndef EQUIPMENT_CPP
#define EQUIPMENT_CPP
#include "equipment.hpp"
#ifndef DIMENSION
#define DIMENSION 3
#endif // DIMENSION
#ifndef HAZARDS
#define HAZARDS 3
#endif // HAZARDS
#ifndef STATE
#define STATE 3
#endif // STATE
#ifndef CERTIFICATES
#define CERTIFICATES 10
#endif // CERTIFICATES
#include <iostream>
Equipment::Equipment(): canTransportHazard(HAZARDS), canTransportState(STATE), sizeLimit(DIMENSION), sizeLeft(DIMENSION), trainingRequired(CERTIFICATES)
{
for(int i = 0; i < HAZARDS; i++)
{
canTransportHazard[i] = 0;
}
for(int i = 0; i < STATE; i++)
{
canTransportState[i] = 0;
}
for(int i = 0; i < DIMENSION; i++)
{
sizeLimit[i] = 0;
}
sizeLeft = sizeLimit;
for(int i = 0; i < CERTIFICATES; i++)
{
trainingRequired[i] = 0;
}
timesUsed = 0;
timesUsedLimit = 0;
weightLimit = 0;
weightLeft = 0;
}
std::vector<bool> Equipment::getCanTranportHazard() const
{
return canTransportHazard;
}
void Equipment::setCanTransportHazard(std::vector <bool> newHazard)
{
canTransportHazard = newHazard;
}
std::vector<bool> Equipment::getCanTransportState() const
{
return canTransportState;
}
void Equipment::setCanTransportState(std::vector <bool> newState)
{
canTransportState = newState;
}
std::vector<int> Equipment::getSizeLimit() const
{
return sizeLimit;
}
void Equipment::setSizeLimit(std::vector<int> newSize)
{
for(int i = 0; i < DIMENSION; i++)
{
if(newSize[i] >= 0)
{
int sizeOccupied = sizeLimit[i] - sizeLeft[i];
sizeLeft[i] = newSize[i] - sizeOccupied;
sizeLimit[i] = newSize[i];
}
}
}
std::vector<int> Equipment::getSizeLeft() const
{
return sizeLeft;
}
void Equipment::setSizeLeft(std::vector<int> newSizeLeft)
{
for(int i = 0; i < DIMENSION; i++)
{
if(newSizeLeft[i] >= 0 && newSizeLeft <= sizeLimit) sizeLeft[i] = newSizeLeft[i];
}
}
void Equipment::occupySpaceGood(Good &someGood)
{
std::vector<int> goodSize = someGood.getSize_();
for(int i = 0; i < DIMENSION; i++)
{
if(goodSize[i] <= sizeLeft[i]) sizeLeft[i] -= goodSize[i];
}
}
int Equipment::getTimesUsed() const
{
return timesUsed;
}
void Equipment::setTimesUsed(int newTimesUsed)
{
if(newTimesUsed >= 0) timesUsed = newTimesUsed;
}
int Equipment::getTimesUsedLimit() const
{
return timesUsedLimit;
}
void Equipment::setTimesUsedLimit(int newTimesUsedLimit)
{
if(newTimesUsedLimit >= 0) timesUsedLimit = newTimesUsedLimit;
}
std::vector<bool> Equipment::getTrainingRequired() const
{
return trainingRequired;
}
void Equipment::setTrainingRequired(int trainingNumber)
{
if(trainingNumber >= 0 && trainingNumber <= CERTIFICATES - 1) trainingRequired[trainingNumber] = 1;
}
int Equipment::getWeightLimit() const
{
return weightLimit;
}
void Equipment::setWeightLimit(int newWeightLimit)
{
if(newWeightLimit >= 0) weightLimit = newWeightLimit;
}
int Equipment::getWeightLeft() const
{
return weightLeft;
}
void Equipment::setWeightLeft(int newWeightLeft)
{
if(newWeightLeft >= 0) weightLeft = newWeightLeft;
}
bool Equipment::canMoveHazard(Good &someGood)
{
std::vector <bool> Hazard = someGood.getHazard();
for(int i = 0; i < HAZARDS; i++)
{
if(canTransportHazard[i] == 0 && Hazard[i] == 1) return 0;
}
return 1;
}
bool Equipment::canMoveState(Good &someGood)
{
if(canTransportState[someGood.getStateOfMatter()]) return true;
return false;
}
bool Equipment::canMoveSize(Good &someGood)
{
std::vector <int> goodSize = someGood.getSize_();
for(int i = 0; i < DIMENSION; i++)
{
if(sizeLimit[i] < goodSize[i]) return false;
}
return true;
}
bool Equipment::needsRepair() const
{
if(timesUsed > timesUsedLimit) return true;
return false;
}
bool Equipment::canMoveGood(Good &someGood)
{
if(!canMoveHazard(someGood))
{
std::cout << "This equipment cannot move good with this hazard" << std::endl;
return false;
}
if(!canMoveState(someGood))
{
std::cout << "This equipment cannot move good with this state" << std::endl;
return false;
}
if(!canMoveSize(someGood))
{
std::cout << "This equipment cannot move good of this size" << std::endl;
return false;
}
if(needsRepair())
{
std::cout << "This equipment needs repair" << std::endl;
return false;
}
if(someGood.getWeight() > getWeightLeft())
{
std::cout << "This good is too heavy to be moved by this equipment" << std::endl;
}
return true;
}
int Equipment::volumeLimit() const
{
int volume = 1;
for(int i = 0; i < DIMENSION; i++)
{
volume *= sizeLimit[i];
}
return volume;
}
int Equipment::volumeLeft() const
{
int volume = 1;
for(int i = 0; i < DIMENSION; i++)
{
volume *= sizeLeft[i];
}
return volume;
}
void Equipment::operator = (Equipment const &otherEquipment)
{
this -> canTransportHazard = otherEquipment.getCanTranportHazard();
this -> canTransportState = otherEquipment.getCanTransportState();
this -> sizeLimit = otherEquipment.getSizeLimit();
this -> timesUsed = otherEquipment.getTimesUsed();
this -> timesUsedLimit = otherEquipment.getTimesUsedLimit();
this -> trainingRequired = otherEquipment.getTrainingRequired();
}
#endif // EQUIPMENT_CPP

58
equipment.hpp Executable file
View File

@ -0,0 +1,58 @@
#ifndef EQUIPMENT_HPP
#define EQUIPMENT_HPP
#include <vector>
#include "good.hpp"
class Equipment
{
private:
std::vector <bool> canTransportHazard;
std::vector <bool> canTransportState;
std::vector <int> sizeLimit;
std::vector <int> sizeLeft;
std::vector <bool> trainingRequired;
int timesUsed;
int timesUsedLimit;
int weightLimit;
int weightLeft;
public:
Equipment();
bool canMoveHazard(Good &someGood);
bool canMoveState(Good &someGood);
bool canMoveSize(Good &someGood);
bool canMoveGood(Good &someGood);
void occupySpaceGood(Good &someGood);
bool needsRepair() const;
int volumeLimit() const;
int volumeLeft() const;
void setCanTransportState(std::vector<bool> newState);
void setCanTransportHazard(std::vector <bool> newHazard);
void setSizeLimit(std::vector <int> newSize);
void setSizeLeft (std::vector <int> newSizeLeft);
void setTimesUsed(int newTimesUsed);
void setTimesUsedLimit(int newTimesUsedLimit);
void setTrainingRequired(int trainingNumber);
void setWeightLimit(int newWeightLimit);
void setWeightLeft(int newWeightLeft);
std::vector <int> getSizeLimit() const;
std::vector <int> getSizeLeft() const;
std::vector <bool> getCanTransportState() const;
std::vector<bool> getCanTranportHazard() const;
int getTimesUsed() const;
int getTimesUsedLimit() const;
int getWeightLimit() const;
int getWeightLeft() const;
std::vector<bool> getTrainingRequired() const;
void operator = (Equipment const &otherEquipment);
};
#endif // EQUIPMENT

84
good.cpp Executable file
View File

@ -0,0 +1,84 @@
#ifndef GOOD_CPP
#define GOOD_CPP
#include "good.hpp"
#ifndef DIMENSION
#define DIMENSION 3
#endif // DIMENSION
#ifndef HAZARDS
#define HAZARDS 3
#endif // HAZARDS
#ifndef STATE
#define STATE 3
#endif // STATE
#ifndef CERTIFICATES
#define CERTIFICATES 10
#endif // CERTIFICATES
#include <iostream>
Good::Good(): size_(DIMENSION), hazard(HAZARDS)
{
size_ = {0, 0, 0};
hazard = {0, 0, 0, 0};
stateOfMatter = 0;
weight = 0;
}
std::vector <int> Good::getSize_() const
{
return size_;
}
std::vector <bool> Good::getHazard() const
{
return hazard;
}
int Good::getStateOfMatter() const
{
return stateOfMatter;
}
int Good::getWeight() const
{
return weight;
}
void Good::setHazard(std::vector <bool> newHazard)
{
hazard = newHazard;
}
void Good::setStateOfMatter(int newState)
{
if(newState >= 0 && newState <= 2) stateOfMatter = newState;
else std::cout << "newState must be a number between 0 and 2!" << std::endl;
}
void Good::setWeight(int newWeight)
{
if(newWeight > 0) weight = newWeight;
}
void Good::setSize_(std::vector <int> newSize)
{
if(newSize.size() > DIMENSION) return;
for(int i = 0; i < DIMENSION; i++)
{
if(newSize[i] < 0) return;
}
size_ = newSize;
}
int Good::volume()
{
return size_[0] * size_[1] * size_[2];
}
#endif // GOOD_CPP

34
good.hpp Executable file
View File

@ -0,0 +1,34 @@
#ifndef GOOD_HPP
#define GOOD_HPP
#include <vector>
class Good
{
private:
std::vector<int> size_;
std::vector<bool> hazard;
int stateOfMatter;
unsigned int weight;
public:
Good();
std::vector <int> getSize_() const;
std::vector <bool> getHazard() const;
int getStateOfMatter() const;
int getWeight() const;
void setSize_(std::vector <int> newSize);
void setHazard(std::vector <bool> newHazard);
void setStateOfMatter(int newState);
void setWeight(int newWeight);
int volume();
};
#endif // GOOD

1046
main.cpp Executable file

File diff suppressed because it is too large Load Diff

202
warehouse.cpp Executable file
View File

@ -0,0 +1,202 @@
#ifndef WAREHOUSE_CPP
#define WAREHOUSE_CPP
#ifndef DIMENSION
#define DIMENSION 3
#endif // DIMENSION
#ifndef HAZARDS
#define HAZARDS 3
#endif // HAZARDS
#ifndef STATE
#define STATE 3
#endif // STATE
#ifndef CERTIFICATES
#define CERTIFICATES 10
#endif // CERTIFICATES
#include "warehouse.hpp"
#include <vector>
#include <iostream>
Warehouse::Warehouse(): size_(DIMENSION)
{
for(int i = 0; i < DIMENSION; i++)
{
size_[i] = 0;
}
}
std::vector <Employee> Warehouse::getAllEmployees() const
{
std::vector<Employee> returnEmployees;
int howManyEmployees = allEmployees.size();
for(int i = 0; i < howManyEmployees; i++)
{
returnEmployees.push_back(*allEmployees[i]);
}
return returnEmployees;
}
std::vector <Equipment> Warehouse::getAllEquipment() const
{
std::vector<Equipment> returnEquipment;
int howMuchEquipment = allEquipment.size();
for(int i = 0; i < howMuchEquipment; i++)
{
returnEquipment.push_back(*allEquipment[i]);
}
return returnEquipment;
}
std::vector <Good> Warehouse::getAllGoods() const
{
std::vector<Good> returnGoods;;
int howMuchGoods = allGoods.size();
for(int i = 0; i < howMuchGoods; i++)
{
returnGoods.push_back(*allGoods[i]);
}
return returnGoods;
}
std::vector <int> Warehouse::findSuitableEmployees(Good &goodToShip)
{
int howManyEmployees = allEmployees.size();
if(howManyEmployees == 0) return {-1};
std::vector <int> goodEmployeesID(howManyEmployees);
goodEmployeesID[0] = -1;
for(int i = 0; i < howManyEmployees; i++)
{
if(allEmployees[i] -> canEmployeeMoveGood(goodToShip)) goodEmployeesID.push_back(i);
}
return goodEmployeesID;
}
std::vector <int> Warehouse::findSuitableEquipments(Good &goodToShip)
{
int howMuchEquipment = allEquipment.size();
if(howMuchEquipment == 0) return {-1};
std::vector <int> goodEquipmentID(howMuchEquipment);
goodEquipmentID[0] = -1;
for(int i = 0; i < howMuchEquipment; i++)
{
if(allEquipment[i] -> canMoveGood(goodToShip)) goodEquipmentID.push_back(i);
}
return goodEquipmentID;
}
std::vector <int> Warehouse::equipmentAndEmployees(std::vector<int> goodEmployeesID, std::vector<int> goodEquipmentID)
{
std::vector <int> equipmentEmployeeCombo = {-1, -1};
int goodEmployeesSize = goodEmployeesID.size();
int goodEquipmentSize = goodEquipmentID.size();
for(int i = 0; i < goodEmployeesSize; i++)
{
for(int j = 0; j < goodEquipmentSize; j++)
{
if(allEmployees[i] -> canAssignEquipment(*allEquipment[j]))
{
equipmentEmployeeCombo[0] = i;
equipmentEmployeeCombo[1] = j;
return equipmentEmployeeCombo;
}
}
}
return equipmentEmployeeCombo;
}
std::vector<int> Warehouse::canAddGood(Good &goodToAdd)
{
std::vector <int> goodEmployees = findSuitableEmployees(goodToAdd);
if(goodEmployees.size() == 1)
{
std::cout << "No employee can move this good" << std::endl;
return {-1};
}
std::vector <int> goodEquipment = findSuitableEquipments(goodToAdd);
if(goodEquipment.size() == 1)
{
std::cout << "No equipment can move this good" << std::endl;
return {-1};
}
std::vector <int> employeeAndEquipment = equipmentAndEmployees(goodEmployees, goodEquipment);
if(employeeAndEquipment[0] == -1)
{
std::cout << "Employee and equipment that can move this good are not compatible" << std::endl;
return {-1};
}
return employeeAndEquipment;
}
bool Warehouse::addGood(Good &goodToShip)
{
std::vector <int> employeeAndEquipment = canAddGood(goodToShip);
if(employeeAndEquipment[0] != -1)
{
allEmployees[employeeAndEquipment[0]] -> moveGoodOverride(goodToShip, *allEquipment[employeeAndEquipment[1]]);
allGoods.push_back(&goodToShip);
return true;
}
return false;
}
bool Warehouse::shipGoods(std::vector <Good> &goodsToShip)
{
int howMuchGoods = goodsToShip.size();
for(int i = 0; i < howMuchGoods; i++)
{
if(!addGood(goodsToShip[i])) return false;
}
return true;
}
int Warehouse::calculateVolume() const
{
int volume = 1;
for(int i = 0; i < DIMENSION; i++)
{
volume += size_[i];
}
return volume;
}
std::vector <int> Warehouse::capacityLeft() const
{
int equipmentNumber = allEquipment.size();
std::vector <int> capacity(DIMENSION);
for(int i = 0; i < equipmentNumber; i++)
{
capacity[i] += allEquipment[i] -> getSizeLeft()[i];
}
return capacity;
}
std::vector <int> Warehouse::capacityTotal() const
{
int equipmentNumber = allEquipment.size();
std::vector <int> capacity(DIMENSION);
for(int i = 0; i < equipmentNumber; i++)
{
capacity[i] += allEquipment[i] -> getSizeLimit()[i];
}
return capacity;
}
void Warehouse::addEmployee(Employee &newEmployee)
{
allEmployees.push_back(&newEmployee);
}
void Warehouse::addEquipment(Equipment &equipmentToAdd)
{
allEquipment.push_back(&equipmentToAdd);
}
#endif // WAREHOUSE_CPP

41
warehouse.hpp Executable file
View File

@ -0,0 +1,41 @@
#ifndef WAREHOUSE_HPP
#define WAREHOUSE_HPP
#include <vector>
#include "employee.hpp"
#include "equipment.hpp"
#include "good.hpp"
class Warehouse
{
private:
std::vector <Employee*> allEmployees;
std::vector <Equipment*> allEquipment;
std::vector <Good*> allGoods;
std::vector <int> size_;
public:
Warehouse();
std::vector <Employee> getAllEmployees() const;
std::vector<Equipment> getAllEquipment() const;
std::vector<Good> getAllGoods() const;
std::vector <int> findSuitableEmployees(Good &goodToShip);
std::vector <int> findSuitableEquipments(Good &goodToShip);
std::vector <int> equipmentAndEmployees(std::vector<int> goodEmployeesID, std::vector<int> goodEquipmentID);
bool canShipGoods(std::vector <Good> &goodToShip);
bool shipGoods(std::vector <Good> &goodsToShip);
int calculateVolume() const;
std::vector <int> capacityLeft() const;
std::vector <int> capacityTotal() const;
void addEmployee(Employee &newEmployee);
void addEquipment(Equipment &equipmentToAdd);
std::vector<int> canAddGood(Good &goodToAdd);
bool addGood(Good &goodToShip);
void addGoodOverride(Good &goodToShip);
};
#endif // WAREHOUSE