-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVehicle.hpp
135 lines (106 loc) · 3.14 KB
/
Vehicle.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#pragma once
#include <vector>
#include <unordered_map>
#include "Product.hpp"
class Vehicle
{
private:
int WeightCapacity = 0;
int CurrentWeightCapacity = 0;
std::vector<Product> Stored;
char VehicleName = '?';
std::vector<size_t> AverageCount;
std::vector<int> AverageWeight;
std::unordered_map<char, int> AverageName;
std::unordered_map<WrapperType, int> AverageWrapper;
public:
Vehicle() = delete;
Vehicle& operator=(const Vehicle&) = delete;
Vehicle(const Vehicle&) = delete;
Vehicle(int NewCapacity, char NewName)
: WeightCapacity(NewCapacity), VehicleName(NewName)
{
}
friend std::ostream& operator<<(std::ostream& os, const Vehicle& vehicle)
{
os << "Name: " << vehicle.VehicleName << " Capacity: " << vehicle.WeightCapacity;
return os;
}
bool Fill(Product Product)
{
if (CurrentWeightCapacity + Product.Weight > WeightCapacity)
{
return false;
}
Stored.push_back(Product);
CurrentWeightCapacity += Product.Weight;
return true;
}
const int GetWeightCapacity() const
{
return WeightCapacity;
}
const int GetCurrentWeightCapacity() const
{
return CurrentWeightCapacity;
}
void DispatchDelivery()
{
if (Stored.size() == 0)
{
return;
}
AverageCount.push_back(Stored.size());
AverageWeight.push_back(CurrentWeightCapacity);
for (const auto& Product : Stored)
{
AverageName[Product.Name]++;
AverageWrapper[Product.Wrapper]++;
}
Stored.clear();
CurrentWeightCapacity = 0;
}
void PrintAverages() const
{
if (AverageCount.size() == 0)
{
std::cout << "\nVehicle " << VehicleName << " was never used to deliver, so no stats \n";
return;
}
std::cout << "\nStats for vehicle " << VehicleName << ": \n";
size_t TempAverage = 0;
for (const auto& Count : AverageCount)
{
TempAverage += Count;
}
std::cout << "Products on average: " << TempAverage / AverageCount.size() << "\n";
int TempWeight = 0;
for (const auto& Count : AverageWeight)
{
TempWeight += Count;
}
std::cout << "Weight on average: " << TempWeight / AverageWeight.size() << "\n";
char NameKey = '?';
int NameTemp = 0;
for (const auto& Count : AverageName)
{
if (Count.second > NameTemp)
{
NameKey = Count.first;
NameTemp = Count.second;
}
}
std::cout << "Product on average: " << NameKey << "\n";
WrapperType WrapperKey = WrapperType::Cardboard;
int WrapperTemp = 0;
for (const auto& Count : AverageWrapper)
{
if (Count.second > WrapperTemp)
{
WrapperKey = Count.first;
WrapperTemp = Count.second;
}
}
std::cout << "Wrapper on average: " << WrapperKey << "\n";
}
};