Alx09

Untitled

Oct 20th, 2020
586
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include    <iostream>
  2. #include    <string>
  3.  
  4. using namespace std;
  5.  
  6. class Monitor {
  7. private:
  8.     string *producator;
  9.     double diagonala, pret;
  10. public:
  11.     Monitor(string &producator, double diagonala, double pret) {
  12.         this->producator = new string;
  13.         *this->producator = producator;
  14.         this->diagonala = diagonala;
  15.         this->pret = pret;
  16.     }
  17.     ~Monitor() { delete producator; }
  18.     string ReturnProducator() { return *producator; }
  19.     void Show() {
  20.         cout << "\nDetalii despre Monitor:";
  21.         cout << "\nProducator: " << *producator;
  22.         cout << "\nDiagonala: " << diagonala << " cm";
  23.         cout << "\nPret: " << pret << " lei";
  24.     }
  25. };
  26.  
  27. class LCD : public Monitor {
  28. private:
  29.     string *tipEcran, *conectori;
  30.     double timpRaspuns;
  31.     LCD *next;
  32.     static LCD *headLCD;
  33. public:
  34.     LCD(string &, double, double, double, string &, string &);
  35.     ~LCD() { delete tipEcran, conectori;}
  36.     static void ShowLCD();
  37.     void Show() {
  38.         Monitor::Show();
  39.         cout << "\nTimp de raspuns: " << timpRaspuns << " s";
  40.         cout << "\nTip ecran: " << *tipEcran;
  41.         cout << "\nConectori: " << *conectori << endl;
  42.     }
  43. };
  44.  
  45. LCD *LCD::headLCD = NULL;
  46.  
  47. LCD::LCD(string &producator, double diagonala, double timpRaspuns, double pret, string &tipEcran, string &conectori) :  Monitor(producator, diagonala, pret) {
  48.     this->tipEcran = new string;
  49.     *this->tipEcran = tipEcran;
  50.     this->conectori = new string;
  51.     *this->conectori = conectori;
  52.     this->timpRaspuns = timpRaspuns;
  53.     next = NULL;
  54.     if (headLCD == NULL) {
  55.         headLCD = this;
  56.         return;
  57.     }
  58.     if (headLCD->ReturnProducator() > this->ReturnProducator()) {
  59.         this->next = headLCD;
  60.         headLCD = this;
  61.         return;
  62.     }
  63.     LCD *q = headLCD;
  64.     while (q->next != NULL && q->next->ReturnProducator() < this->ReturnProducator()) q = q->next;
  65.     this->next = q->next;
  66.     q->next = this;
  67.  
  68.  
  69. }
  70. void LCD::ShowLCD() {
  71.     LCD * q = headLCD;
  72.     while (q)
  73.     {
  74.         q->Show();
  75.         q = q->next;
  76.     }
  77. }
  78.  
  79. int main() {
  80.    
  81.     string producator, tipEcran, conectori;
  82.     double pret, diagonala, timpRaspuns;
  83.     unsigned opt;
  84.     int isLCD;
  85.     do {
  86.         cout << "\n1. Adaugare monitor LCD/LED";
  87.         cout << "\n2. Afisare monitoare LCD/LED";
  88.         cout << "\n6. Iesire.";
  89.         cout << "\nOptiunea dorita: "; cin >> opt;
  90.         system("cls");
  91.         switch (opt)
  92.         {
  93.         case 1:
  94.             cout << "\nTip monitor (1-LCD/ 0-LED): "; cin >> isLCD;
  95.        
  96.             cout << "\nProducator: "; cin >> producator;
  97.             cout << "Diagonala: "; cin >> diagonala;
  98.             cout << "Pret: "; cin >> pret;
  99.             if (isLCD) {
  100.                 cout << "Timp de raspuns: "; cin >> timpRaspuns;
  101.                 cout << "Tip ecran: "; cin >> tipEcran;
  102.                 cout << "Conectori: "; cin >> conectori;
  103.                 new LCD(producator, diagonala,timpRaspuns, pret, tipEcran, conectori);
  104.             }
  105.             break;
  106.         case 2:
  107.             cout << "\nTip monitor (1-LCD/ 0-LED): "; cin >> isLCD;
  108.             if (isLCD) LCD::ShowLCD();
  109.         default:
  110.             break;
  111.         }
  112.     } while (true);
  113.     return 0;
  114. }
  115.  
RAW Paste Data