-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
186 lines (170 loc) · 7.46 KB
/
main.cpp
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
// Main.cpp
// Jonathan Bouchard & Pierre-Anthony Houle
// 04 novembre 2016
// Créer une file de clients dans une instance de Quincaillerie
#include "Constantes.h"
#include "Quincaillerie.h"
#include "ClientParticulier.h"
#include "ClientPrivilégié.h"
#include "ClientCommercial.h"
#include "SourceLecture.h"
#include "Prototype.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
int main()
{
locale::global(locale("")); // Permet les charactères français
vector<Client*> vecClients; // Vecteur contenant les clients
SourceLecture fichierClients; // Le fichier des clients
SourceLecture fichierOpérations; // Le fichier des opérations
Quincaillerie magasin(NBCAISSES); // La quincaillerie
ofstream fichierEcriture; // Le fichier du rapport final
// Traiter le fichier client
DemanderFichier(CLIENT, fichierClients, fichierEcriture);
LireFichier(CLIENT, fichierClients, magasin, vecClients, fichierEcriture);
// Traiter le fichier opération
DemanderFichier(OPERATIONS, fichierOpérations, fichierEcriture);
LireFichier(OPERATIONS, fichierOpérations, magasin, vecClients, fichierEcriture);
// Écrire le rapport final
EcrireStatsFinales(magasin, fichierEcriture);
}
Client* GetClientByNum(vector<Client*> vecClients, int Num)
{
Client* client;
for (int i = 0; i < vecClients.size(); i++)
{
if (vecClients.at(i)->GetNumClient() == Num) client = vecClients.at(i);
}
return client;
}
#pragma region WriteFile
void StatusCaisse(Quincaillerie& magasin, ofstream& flux)
{
for (int i = 0; i < magasin.GetVectorCaisse().size(); i++)
{
flux << "******************** Caisse " << i + 1 << " ********************" << endl;
magasin.GetCaisse(i).AfficherCaisse(flux);
flux << endl;
}
}
void EcrireStatsFinales(Quincaillerie& magasin, ofstream& flux)
{
int index;
flux << "@@@@@@@@@@@@@@@@@@@@@ STATS @@@@@@@@@@@@@@@@@@@@@@" << endl;
index = distance(magasin.GetVectorCaisse().begin(), magasin.GetCaissePlusClients()) + 1;
flux << "Caisse qui a eu le plus grand nombre de clients: Caisse " << index << endl;
magasin.GetVectorCaisse().begin(), magasin.GetCaissePlusClients()->AfficherCaisse(flux);
index = distance(magasin.GetVectorCaisse().begin(), magasin.GetCaissePlusAttente()) + 1;
flux << "Caisse où il y a eu le plus d’attente: Caisse " << index << endl;
magasin.GetVectorCaisse().begin(), magasin.GetCaissePlusAttente()->AfficherCaisse(flux);
index = distance(magasin.GetVectorCaisse().begin(), magasin.GetCaissePlusArgent()) + 1;
flux << "Caisse qui à encaissé le plus d’argent: Caisse " << index << endl;
magasin.GetVectorCaisse().begin(), magasin.GetCaissePlusArgent()->AfficherCaisse(flux);
flux << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" << endl;
}
#pragma endregion
#pragma region Quincaillerie
void CreerClient(vector<string> vectorElems, vector<Client*>& vecClient)
{
if (vectorElems.at(1) == TYPEPARTICULIER) vecClient.push_back(new ClientParticulier(stoi(vectorElems.at(0)), vectorElems.at(1), vectorElems.at(2)));
else if (vectorElems.at(1) == TYPEPRIVILEGIE) vecClient.push_back(new ClientPrivilégié(stoi(vectorElems.at(0)), vectorElems.at(1), vectorElems.at(2), vectorElems.at(3)));
else if (vectorElems.at(1) == TYPECOMMERCIAL) vecClient.push_back(new ClientCommercial(stoi(vectorElems.at(0)), vectorElems.at(1), vectorElems.at(2), vectorElems.at(3), vectorElems.at(4), vectorElems.at(5), stoi(vectorElems.at(6))));
}
void ExecuterOperations(vector<string> vectorElems, Quincaillerie& magasin, vector<Client*> vecClient, ofstream& flux)
{
try
{
if (vectorElems.at(0) == OUVRIRCAISSE) OuvrirCaisse(vectorElems, magasin, flux);
else if (vectorElems.at(0) == AJOUTERCLIENT) AjouterClient(vectorElems, magasin, vecClient, flux);
else if (vectorElems.at(0) == QUITTERCAISSE) QuitterCaisse(vectorElems, magasin, flux);
else if (vectorElems.at(0) == FERMERCAISSE) FermerCaisse(vectorElems, magasin, flux);
else throw exception("Type d'opération inconnu...");
StatusCaisse(magasin, flux);
}
catch (exception e) { flux << e.what() << endl; }
}
void DemanderFichier(TypeFichier typeFichier, SourceLecture& fichier, ofstream& fecriture)
{
string nomFichier; // Variable qui retient le nom du fichier
do
{
cout << "------------------------------------" << endl;
if (typeFichier == CLIENT) cout << "Entrez un nom de fichier de clients: " << endl;
else if (typeFichier == OPERATIONS) cout << "Entrez un nom de fichier d'opérations: " << endl;
cout << "------------------------------------" << endl;
cin >> nomFichier;
fichier.SetNomSourceLecture(nomFichier);
} while (!fichier.EstCapableDeLire());
if (typeFichier == OPERATIONS) fecriture.open("Journal_" + nomFichier);
}
void LireFichier(TypeFichier i, SourceLecture& fichier, Quincaillerie& magasin, vector<Client*>& vecClient, ofstream& flux)
{
do
{
vector<string> vecElems;
fichier.Lire(vecElems);
if (i == CLIENT) CreerClient(vecElems, vecClient);
else if (i == OPERATIONS) ExecuterOperations(vecElems, magasin, vecClient, flux);
} while (fichier.PeutEncoreLire());
}
#pragma endregion
#pragma region Operations
void OuvrirCaisse(vector<string> vectorElems, Quincaillerie& magasin, ofstream& flux)
{
if (stoi(vectorElems.at(1)) - 1 >= 0 && stoi(vectorElems.at(1)) - 1 < NBCAISSES)
{
if (magasin.GetCaisse((stoi(vectorElems.at(1)) - 1)).GetStatus() != OUVERT)
{
magasin.GetCaisse((stoi(vectorElems.at(1)) - 1)).OuvrirCaisse();
magasin.GetCaisse((stoi(vectorElems.at(1)) - 1)).SetEteOuvert(true);
flux << "--OUVERTURE DE LA CAISSE #" << vectorElems.at(1) << endl;
}
else flux << "CAISSE #" << vectorElems.at(1) << " DÉJÀ OUVERTE" << endl;
}
else throw exception("Le numéro de la caisse est invalide!");
}
void AjouterClient(vector<string> vectorElems, Quincaillerie& magasin, vector<Client*> vecClient, ofstream& flux)
{
Caisse* plusRapide;
if (stoi(vectorElems.at(1)) - 1 >= 0 && stoi(vectorElems.at(1)) - 1 < vecClient.size())
{
Client* client = GetClientByNum(vecClient, stoi(vectorElems.at(1)));
//// Ajoute le temps d'attente dans le client
client->SetTempsClient(magasin.ConvertirMinuteEnSeconde(vectorElems.at(2)));
//// Modifie la caisse (ajoute un client / ajoute le temps d'attente / **faire quelque chose avec le montant**)
if (client->GetTypeClient() == TYPECOMMERCIAL) plusRapide = magasin.GetCaissePlusRapide(true);
else plusRapide = magasin.GetCaissePlusRapide(false);
plusRapide->AjouterClientFile(client, stof(vectorElems.at(3)));
flux << "--AJOUT CLIENT #" << vectorElems.at(1) << endl;
}
else throw exception("Client Invalide!");
}
void QuitterCaisse(vector<string> vectorElems, Quincaillerie& magasin, ofstream& flux)
{
if (stoi(vectorElems.at(1)) - 1 >= 0 && stoi(vectorElems.at(1)) - 1 < NBCAISSES)
{
if (magasin.GetCaisse(stoi(vectorElems.at(1)) - 1).GetFile().size() != 0)
{
magasin.GetCaisse(stoi(vectorElems.at(1)) - 1).RetirerClientFile();
flux << "--TERMINER CAISSE #" << vectorElems.at(1) << endl;
}
else throw exception("Caisse Vide!");
}
else throw exception("Le numéro de la caisse est invalide!");
}
void FermerCaisse(vector<string> vectorElems, Quincaillerie& magasin, ofstream& flux)
{
if (stoi(vectorElems.at(1)) - 1 >= 0 && stoi(vectorElems.at(1)) - 1 < NBCAISSES)
{
if (magasin.GetCaisse((stoi(vectorElems.at(1)) - 1)).GetStatus() != FERMÉ)
{
magasin.GetCaisse((stoi(vectorElems.at(1)) - 1)).FermerCaisse();
flux << "--FERMETURE DE LA CAISSE #" << vectorElems.at(1) << endl;
}
else flux << "CAISSE #" << vectorElems.at(1) << " DÉJÀ FERMÉ" << endl;
}
else throw exception("Le numéro de la caisse est invalide!");
}
#pragma endregion