Advertisement
Alx09

Untitled

Dec 4th, 2020
803
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.74 KB | None | 0 0
  1. #include<iostream>
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. #include<list>
  5. #include<iterator>
  6. #include<string>
  7. #define _CRT_SECURE_NO_WARNING
  8. using namespace std;
  9.  
  10. class masa {
  11. protected:
  12.     int nr;
  13. public:
  14.     masa(int nr) {
  15.         this->nr = nr;
  16.     }
  17.     int get_nr() { return nr; }
  18.     virtual void afisare() {
  19.         cout << "Numarul mesei: " << nr << endl;
  20.     }
  21.     virtual int get_pret() = 0;
  22.  
  23. };
  24.  
  25. class pizza : public masa {
  26. protected:
  27.     int pret;
  28.     string nume;
  29. public:
  30.     pizza(int nr, string nume, int pret) : masa(nr) {
  31.         this->pret = pret;
  32.         this->nume = nume;
  33.     }
  34.     void afisare() {
  35.         masa::afisare();
  36.         cout << "Tip comanda: Pizza" << endl;
  37.         cout << " Numele pizzei: " << nume << endl;
  38.         cout << "Pretul pizzei: " << pret << " ron" << endl;
  39.     }
  40.  
  41.     string get_nume() { return nume; }
  42.     int get_pret() { return pret; }
  43. };
  44.  
  45. class paste :public masa {
  46. protected: int pret;
  47.            string nume;
  48. public:
  49.     paste(int nr, string nume, int pret) : masa(nr) {
  50.         this->pret = pret;
  51.         this->nume = nume;
  52.     }
  53.     void afisare() {
  54.         masa::afisare();
  55.         cout << "Tip comanda: Paste" << endl;
  56.         cout << " Numele pastelor: " << nume << endl;
  57.         cout << "Pretul pastelor: " << pret << " ron" << endl;
  58.     }
  59.     string get_nume() { return nume; }
  60.     int get_pret() { return pret; }
  61.     int get_nr() { return nr; }
  62. };
  63.  
  64. class drink : public masa
  65. {
  66. protected: string brand, aroma; int pret;
  67. public:
  68.     drink(int nr, string brand, string aroma, int pret) : masa(nr) {
  69.         this->pret = pret;
  70.         this->brand = brand;
  71.         this->aroma = aroma;
  72.     }
  73.     void afisare() {
  74.         masa::afisare();
  75.         cout << "Tip comanda: Bautura" << endl;
  76.         cout << " Brandul bauturii: " << brand << endl;
  77.         cout << " Aroma bauturii: " << aroma << endl;
  78.         cout << "Pretul bauturii: " << pret << " ron" << endl;
  79.     }
  80.     string get_brand() { return brand; }
  81.     int get_pret() { return pret; }
  82.  
  83. };
  84.  
  85. list <masa*> l;
  86. list <masa*>::iterator it;
  87.  
  88. void read()
  89. {
  90.     int nr, pret, comanda;
  91.     string nume, brand, aroma;
  92.     cout << "Introduceti numarul mesei: ";
  93.     cin >> nr;
  94.     cout << "Ce doriti sa comandati? [1=Pizza; 2=Paste; 3=Bautura] : ";
  95.     cin >> comanda;
  96.     if (comanda == 1) {
  97.         cout << "Nume pizza: "; cin >> nume;
  98.         cout << "Pretul pentru pizza: ";
  99.         cin >> pret;
  100.         if (l.empty())
  101.             l.push_back(new pizza(nr, nume, pret));
  102.         else {
  103.             it = l.begin();
  104.             while (it != l.end() && (*it)->get_nr() < nr)
  105.                 advance(it, 1);
  106.             l.emplace(it, new pizza(nr, nume, pret));
  107.         }
  108.     }
  109.     else if (comanda == 2) {
  110.         cout << "Nume paste: ";
  111.         cin >> nume;
  112.         cout << "Pretul pentru paste: ";
  113.         cin >> pret;
  114.         if (l.empty())
  115.             l.push_back(new paste(nr, nume, pret));
  116.         else {
  117.             it = l.begin();
  118.             while (it != l.end() && (*it)->get_nr() < nr)
  119.                 advance(it, 1);
  120.             l.emplace(it, new paste(nr, nume, pret));
  121.         }
  122.     }
  123.     else if (comanda == 3) {
  124.         cout << "Brandul bauturii: ";
  125.         cin >> brand;
  126.         cout << "Aroma bauturii: ";
  127.         cin >> aroma;
  128.         cout << "Pretul pentru bautura: ";
  129.         cin >> pret;
  130.         if (l.empty())
  131.             l.push_back(new drink(nr, brand, aroma, pret));
  132.         else {
  133.             it = l.begin();
  134.             while (it != l.end() && (*it)->get_nr() < nr)
  135.                 advance(it, 1);
  136.             l.emplace(it, new drink(nr, brand, aroma, pret));
  137.         }
  138.     }
  139.  
  140. }
  141.  
  142. void show() {
  143.     cout << "=============================" << endl;
  144.     for (it = l.begin(); it != l.end(); it++) {
  145.         (*it)->afisare();
  146.         cout << "----------------------------- \n";
  147.     }
  148.     cout << "=============================" << endl;
  149. }
  150.  
  151. int main() {
  152.     int opt;
  153.     do {
  154.         cout << "\n\n";
  155.         cout << "1.Adaugare comanda \n";
  156.         cout << "2.Afis comenzi \n";
  157.         cout << "0.Iesire \n";
  158.         cout << "Dati optiunea dvs: ";
  159.         cin >> opt;
  160.         switch (opt) {
  161.         case 1:
  162.             read();
  163.            
  164.             break;
  165.         case 2:
  166.             show();
  167.             break;
  168.         case 3:
  169.        
  170.             break;
  171.         case 0:
  172.             break;
  173.  
  174.         }
  175.     } while (opt != 0);
  176.     return 0;
  177. }
  178.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement