diff --git a/TP8/Pizzeria/CLIENT.txt b/TP8/Pizzeria/CLIENT.txt new file mode 100644 index 0000000..3c5617c --- /dev/null +++ b/TP8/Pizzeria/CLIENT.txt @@ -0,0 +1,5 @@ +4 +Leonardo;1;oignons; +Raphael;1;sauce tomate; +Donatello;3;fruits secs;champignon;poivrons; +Michel angelo;2;fromage;sauce tomate; \ No newline at end of file diff --git a/TP8/Pizzeria/Côté_La_pizzeria_VF.pdf b/TP8/Pizzeria/Côté_La_pizzeria_VF.pdf new file mode 100644 index 0000000..563d7df Binary files /dev/null and b/TP8/Pizzeria/Côté_La_pizzeria_VF.pdf differ diff --git a/TP8/Pizzeria/PIZZA_4.txt b/TP8/Pizzeria/PIZZA_4.txt new file mode 100644 index 0000000..f692b11 --- /dev/null +++ b/TP8/Pizzeria/PIZZA_4.txt @@ -0,0 +1,7 @@ +6 +Vegetarienne;4;sauce tomate;poivrons;courgette;oignons; +4 Fromages;2;creme blanche;fromage; +Prosciutto;3;sauce tomate;fromage;jambon; +Frutti di mare;3;sauce tomate;fromage;fruits de mer; +Carbonara;3;creme blanche;fromage;lardons; +Forestière;3;sauce tomate;fromage;champignon; \ No newline at end of file diff --git a/TP8/Pizzeria/Pizzeria.sln b/TP8/Pizzeria/Pizzeria.sln new file mode 100644 index 0000000..499b3da --- /dev/null +++ b/TP8/Pizzeria/Pizzeria.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.7.34221.43 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Pizzeria", "Pizzeria.vcxproj", "{2370802E-F9E9-4D3C-8733-3CF28B29D22E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2370802E-F9E9-4D3C-8733-3CF28B29D22E}.Debug|x64.ActiveCfg = Debug|x64 + {2370802E-F9E9-4D3C-8733-3CF28B29D22E}.Debug|x64.Build.0 = Debug|x64 + {2370802E-F9E9-4D3C-8733-3CF28B29D22E}.Debug|x86.ActiveCfg = Debug|Win32 + {2370802E-F9E9-4D3C-8733-3CF28B29D22E}.Debug|x86.Build.0 = Debug|Win32 + {2370802E-F9E9-4D3C-8733-3CF28B29D22E}.Release|x64.ActiveCfg = Release|x64 + {2370802E-F9E9-4D3C-8733-3CF28B29D22E}.Release|x64.Build.0 = Release|x64 + {2370802E-F9E9-4D3C-8733-3CF28B29D22E}.Release|x86.ActiveCfg = Release|Win32 + {2370802E-F9E9-4D3C-8733-3CF28B29D22E}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {CECACC32-5416-4BA7-9C0E-C88B223F18A9} + EndGlobalSection +EndGlobal diff --git a/TP8/Pizzeria/Pizzeria.vcxproj b/TP8/Pizzeria/Pizzeria.vcxproj new file mode 100644 index 0000000..0f5d147 --- /dev/null +++ b/TP8/Pizzeria/Pizzeria.vcxproj @@ -0,0 +1,139 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {2370802e-f9e9-4d3c-8733-3cf28b29d22e} + Pizzeria + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/TP8/Pizzeria/Pizzeria.vcxproj.filters b/TP8/Pizzeria/Pizzeria.vcxproj.filters new file mode 100644 index 0000000..5b37b48 --- /dev/null +++ b/TP8/Pizzeria/Pizzeria.vcxproj.filters @@ -0,0 +1,30 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Fichiers de ressources + + + Fichiers de ressources + + + + + Fichiers sources + + + \ No newline at end of file diff --git a/TP8/Pizzeria/Pizzeria.vcxproj.user b/TP8/Pizzeria/Pizzeria.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/TP8/Pizzeria/Pizzeria.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/TP8/Pizzeria/main.cpp b/TP8/Pizzeria/main.cpp new file mode 100644 index 0000000..033acd6 --- /dev/null +++ b/TP8/Pizzeria/main.cpp @@ -0,0 +1,265 @@ +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +class Base { + string nom; + vector ing; +public: + string getNom() const { return nom; } + vector getIng() { return ing; } + + bool operator=(Base b) { return b.nom == nom; } + bool operator<(Base b) const { return nom < b.nom; } + + void lecture(ifstream& f); + void saisie(); + void affichage(); +}; + +class Pizza : public Base { +public: + bool contient_allergene(string allergene); + float getPrix(); +}; + +class Client : public Base { +public: + bool est_allergique(Pizza p); +}; + + + +template +void lecture(C& c, const string name) { + ifstream f(name); + + if (!f.is_open()) { + cout << "Erreur lors de la lecture du fichier" << endl; + exit(1); + } + + int N; + f >> N; f.ignore(); + while ((N--) > 0) { + T t; + t.lecture(f); + c.push_back(t); + f.ignore(); + } +} + +void Base::lecture(ifstream& f) { + getline(f, nom, ';'); + int N; + f >> N; f.ignore(); + while ((N--) > 0) { + string t; + getline(f, t, ';'); + ing.push_back(t); + } +} + +template +void afficher(T t, int w) { + cout << left << setw(w) << t << " "; +} + +void Base::affichage() { + cout << nom << " : "; + + cout << "("; + for (int i = 0; i < ing.size()-1; i++) { + cout << ing[i] << ", "; + } + if (ing.size() > 0) + cout << ing[ing.size()-1]; + cout << ")"; +} + +void Base::saisie() { + cout << "Nom : "; + getline(cin, nom); + int N; + cout << "Nbr ing : "; + cin >> N; cin.ignore(); + for (int i = 0; i < N; i++) { + string s; + cout << "Ing" << (i + 1) << " : "; + getline(cin, s); + ing.push_back(s); + } +} + +float Pizza::getPrix() { + return getIng().size() * 2.0; +} + + +template +void affichage(C c) { + for (auto a : c) { + a.affichage(); + cout << endl; + } + cout << endl; +} + +bool Client::est_allergique(Pizza p) { + for (string ing : getIng()) { + if (p.contient_allergene(ing)) + return true; + } + + return false; +} + +bool Pizza::contient_allergene(string ing) { + for (string i : getIng()) { + if (ing == i) + return true; + } + return false; +} + +void pizza_alergenes(multimap& mp, vector pizzas, list clients) { + for (Client c : clients) { + for (Pizza p : pizzas) { + if (c.est_allergique(p)) + continue; + mp.insert(make_pair(c, p)); + } + } +} + +void affiche_map(multimap mp, list clients) { + /* auto it = mp.begin(); + while (it != mp.end()) { + Client c = it->first; + cout << c.getNom() << " : " << endl; + int i = 1; + while (it != mp.end() && it->first.getNom() == c.getNom()) { + cout << " "; + cout << "(" << i << ") : "; + it->second.affichage(); + cout << endl; + it++; i++; + } + cout << endl; + } */ + clients.sort(); + for (Client c : clients) { + cout << c.getNom() << " : " << endl; + int i = 0; + auto r = mp.equal_range(c); + for (; r.first != r.second; r.first++) { + cout << " "; + cout << "(" << i << ") : "; + r.first->second.affichage(); + cout << endl; + i++; + } + } +} + +void ajout_pizza(vector& pizzas) { + Pizza p; + char c; + cout << "Ajout au début (O/N) : "; + cin >> c; cin.ignore(); + auto it = c == 'O' ? pizzas.begin() : pizzas.end(); + + p.saisie(); + + pizzas.insert(it, p); + + cout << "Prix calculé de cette pizza = " << p.getPrix() << " euros" << endl; +} + +void del_pizza(vector& pizzas) { + string ing; + cout << "Ingr_allergie : "; + getline(cin, ing); + + auto it = pizzas.begin(); + while (it != pizzas.end()) { + if (it->contient_allergene(ing)) { + it = pizzas.erase(it); + } + it++; + } + + cout << "Il reste : "; + for (int i = 0; i < pizzas.size()-1; i++) { + cout << pizzas[i].getNom() << ", "; + } + + if (pizzas.size() > 0) { + cout << pizzas[pizzas.size() - 1].getNom(); + } + + cout << endl; +} + +int menu() { + int c; + + cout << "1. Lire Pizza(s)" << endl + << "2. Lire Client(s)" << endl + << "3. Créer multimap" << endl + << "4. Ajouter (début ou fin) pizza + prix (2euros/ing.)" << endl + << "5. Supprimer toutes les pizzas" << endl; + + cout << "Choix : "; + + cin >> c; cin.ignore(); + return c; +} + +int main() { + vector pizzas; + list clients; + + multimap mp; + + + setlocale(LC_ALL, ""); + + while (true) { + switch (menu()) { + case 1: + lecture, Pizza>(pizzas, "PIZZA_4.txt"); + affichage(pizzas); + + break; + case 2: + lecture, Client>(clients, "CLIENT.txt"); + affichage(clients); + + break; + case 3: + pizza_alergenes(mp, pizzas, clients); + affiche_map(mp, clients); + + break; + case 4: + ajout_pizza(pizzas); + affichage(pizzas); + + break; + case 5: + del_pizza(pizzas); + affichage(pizzas); + + break; + default: + return 0; + } + } +} \ No newline at end of file