Advertisement
Patey

Untitled

Oct 21st, 2021
976
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.72 KB | None | 0 0
  1. #include<iostream>
  2. #include<string.h>
  3.  
  4. using namespace std;
  5.  
  6. class monitor
  7. {
  8.     int diagonala,pret;
  9.     friend class LED;
  10.     friend class LCD;
  11.     friend void stergere_LED();
  12. public:
  13.     string producator;
  14.     monitor(string producator, int diagonala, int pret)
  15.     {
  16.         this->diagonala = diagonala;
  17.         this->producator = producator;
  18.         this->pret = pret;
  19.     }
  20.     void afisare_monitor()
  21.     {
  22.         cout << "Producator: ";
  23.         cout << producator << endl;
  24.         cout << "Diagonala:";
  25.         cout << diagonala << endl;
  26.         cout << "Pret:";
  27.         cout << pret << endl;
  28.     }
  29.     /*void adaugare_monitor()
  30.     {
  31.         cout << "Producator: ";
  32.         cin >> producator;
  33.         cout << "Diagonala: ";
  34.         cin >> diagonala;
  35.         cout << "Pret: ";
  36.         cin >> pret;
  37.     }*/
  38. };
  39.  
  40. class LED :public monitor
  41. {
  42.     int timp_raspuns;
  43.     LED* next;
  44.     LED* head;
  45. public:
  46.     LED(string producator, int diagonala, int pret, int timp_raspuns) :monitor(producator, diagonala, pret)
  47.     {
  48.         this->timp_raspuns = timp_raspuns;
  49.         head = NULL;
  50.     }
  51.  
  52.     void afisare_LED()
  53.     {
  54.         LED* p = head;
  55.         while (p != NULL)
  56.         {
  57.             cout << "Producator: ";
  58.             cout << p->producator << endl;
  59.             cout << "Diagonala:";
  60.             cout << p->diagonala << endl;
  61.             cout << "Pret:";
  62.             cout << p->pret << endl;
  63.             cout << "Timp raspuns: ";
  64.             cout << p->timp_raspuns << endl << endl;
  65.             p = p->next;
  66.         }
  67.     }
  68.  
  69.     void adaugare_LED()
  70.     {
  71.         cout << "Producator: ";
  72.         cin >> producator;
  73.         cout << "Diagonala: ";
  74.         cin >> diagonala;
  75.         cout << "Pret: ";
  76.         cin >> pret;
  77.         cout << "Timp raspuns: ";
  78.         cin >> timp_raspuns;
  79.         LED* p = new LED(producator, diagonala, pret, timp_raspuns);
  80.         p->next = head;
  81.         head = p;
  82.     }
  83.  
  84.     void stergere_LED()
  85.     {
  86.         char prod[20];
  87.         cout << "Dati producatorul LED-ului pentru stergere: ";
  88.         cin >> prod;
  89.         cout << endl;
  90.         LED* comp = head;
  91.         LED* del;
  92.         if (strcmp(comp->producator.c_str(), prod) == 0)
  93.         {
  94.             del = comp;
  95.             head = comp->next;
  96.             delete del;
  97.         }
  98.         else
  99.         {
  100.             while (strcmp(comp->next->producator.c_str(), prod) != 0 && comp->next)
  101.             {
  102.                 comp = comp->next;
  103.             }
  104.             del = comp->next;
  105.             comp->next = comp->next->next;
  106.             //c->urm = del->urm;
  107.             delete del;
  108.         }
  109.         afisare_LED();
  110.     }
  111.  
  112.     void cautare_LED()
  113.     {
  114.         string prod;
  115.         cout << "Dati producatorul LED-ului pentru cautare: ";
  116.         cin >> prod;
  117.         LED* comp = head;
  118.         while (comp)
  119.         {
  120.             if (strcmp(comp->producator.c_str(), prod.c_str()) == 0)
  121.             {
  122.                 cout << endl;
  123.                 afisare_LED();
  124.                 break;
  125.             }
  126.         }
  127.     }
  128.  
  129. };
  130.  
  131. class LCD :public monitor
  132. {
  133.     int boxe,format;
  134.     LCD* head;
  135.     LCD* next;
  136. public:
  137.     LCD(string producator, int diagonala, int pret,int format,int boxe) :monitor(producator, diagonala, pret)
  138.     {
  139.         this->format = format;
  140.         this->boxe = boxe;
  141.         head = NULL;
  142.     }
  143.  
  144.     void afisare_LCD()
  145.     {
  146.         LCD* p=head;
  147.         while (p != NULL)
  148.         {
  149.             cout << "Producator: ";
  150.             cout <<p->producator << endl;
  151.             cout << "Diagonala:";
  152.             cout <<p->diagonala << endl;
  153.             cout << "Pret:";
  154.             cout <<p->pret << endl;
  155.             cout << "Format: ";
  156.             cout <<p->format << endl;
  157.             cout << "Boxe: ";
  158.             cout << p->boxe << endl << endl;
  159.             p = p->next;
  160.         }
  161.     }
  162.  
  163.     void adaugare_LCD()
  164.     {
  165.         cout << "Producator: ";
  166.         cin >> producator;
  167.         cout << "Diagonala: ";
  168.         cin >> diagonala;
  169.         cout << "Pret: ";
  170.         cin >> pret;
  171.         cout << "Format: ";
  172.         cin >> format;
  173.         cout << "Boxe: ";
  174.         cin >> boxe;
  175.         LCD* p = new LCD(producator, diagonala, pret, format,boxe);
  176.         p->next = head;
  177.         head = p;
  178.     }
  179.  
  180.     void stergere_LCD()
  181.     {
  182.         char prod[20];
  183.         cout << "Dati producatorul LCD-ului pentru stergere: ";
  184.         cin >> prod;
  185.         cout << endl;
  186.         LCD* comp = head;
  187.         LCD* del;
  188.         if (strcmp(comp->producator.c_str(), prod) == 0)
  189.         {
  190.             del = comp;
  191.             head = comp->next;
  192.             delete del;
  193.         }
  194.         else
  195.         {
  196.             while (strcmp(comp->producator.c_str(), prod) != 0 && comp->next)
  197.             {
  198.                 comp = comp->next;
  199.             }
  200.             del = comp->next;
  201.             comp->next = comp->next->next;
  202.             //c->urm = del->urm;
  203.             delete del;
  204.         }
  205.         afisare_LCD();
  206.     }
  207.  
  208.     void cautare_LCD()
  209.     {
  210.         string prod;
  211.         cout << "Dati producatorul LCD-ului pentru cautare: ";
  212.         cin >> prod;
  213.         LCD* comp = head;
  214.         while (comp)
  215.         {
  216.             if (strcmp(comp->producator.c_str(), prod.c_str()) == 0)
  217.             {
  218.                 cout << endl;
  219.                 afisare_LCD();
  220.                 break;
  221.             }
  222.         }
  223.     }
  224.  
  225. };
  226.  
  227.  
  228. int main()
  229. {
  230.     LED* a = new LED(" ", 0, 0, 0);
  231.     LCD* b=new LCD(" ",0,0,0,0);
  232.  
  233.     string producator;
  234.     int diagonala, pret, boxe, timp_raspuns,n,n2,format;
  235.     enum{iesire, citire, afisare, stergere, cautare, ordonare}opt;
  236.     do {
  237.         cout << "0. Iesire" << endl;
  238.         cout << "1. Citire" << endl;
  239.         cout << "2. Afisare" << endl;
  240.         cout << "3. Stergere" << endl;
  241.         cout << "4. Cautare" << endl;
  242.         cout << "5. Ordonare" << endl;
  243.         cout << "opt= ";
  244.         cin >> n;
  245.         switch (n)
  246.         {
  247.         case iesire:exit(0);
  248.             break;
  249.         case citire:cout <<endl<< "1.Led" << endl;
  250.             cout << "2.Lcd" << endl;;
  251.             cout << "opt= ";
  252.             cin >> n2;
  253.             if (n2 == 1)
  254.             {
  255.                 a->adaugare_LED();
  256.             }
  257.             else
  258.             {
  259.                 b->adaugare_LCD();
  260.             }
  261.             cout << endl;
  262.             break;
  263.         case afisare:
  264.             cout << endl<<"1.Led" << endl;
  265.             cout << "2.Lcd" << endl;;
  266.             cout << "opt= ";
  267.             cin >> n2;
  268.             cout << endl;
  269.             if (n2 == 1)
  270.             {
  271.                 a->afisare_LED();
  272.             }
  273.             else
  274.             {
  275.                 b->afisare_LCD();
  276.             }
  277.             cout << endl;
  278.             break;
  279.         case stergere:
  280.             cout << endl << "1.Led" << endl;
  281.             cout << "2.Lcd" << endl;;
  282.             cout << "opt= ";
  283.             cin >> n2;
  284.             if (n2 == 1)
  285.             {
  286.                 a->stergere_LED();
  287.             }
  288.             else
  289.             {
  290.                 b->stergere_LCD();
  291.             }
  292.             cout << endl;
  293.             break;
  294.         case cautare:
  295.             cout << endl << "1.Led" << endl;
  296.             cout << "2.Lcd" << endl;;
  297.             cout << "opt= ";
  298.             cin >> n2;
  299.             if (n2 == 1)
  300.             {
  301.                 a->cautare_LED();
  302.             }
  303.             else
  304.             {
  305.                 b->cautare_LCD();
  306.             }
  307.             break;
  308.         case ordonare:
  309.             break;
  310.         default:
  311.             break;
  312.         }
  313.     } while (1);
  314. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement