Advertisement
Alx09

Untitled

Dec 4th, 2020
651
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.14 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.  
  8. #define _CRT_SECURE_NO_WARNING
  9. using namespace std;
  10. class Cadou {
  11. private:
  12.     static Cadou *head;
  13.     Cadou *next;
  14.     string nume;
  15.     double pret;
  16. public:
  17.     Cadou(string nume, double pret) {
  18.         this->nume = nume;
  19.         this->pret = pret;
  20.         this->next = NULL;
  21.         if (head == NULL) {
  22.             head = this;
  23.             return;
  24.         }
  25.         if (head->nume > this->nume) {
  26.             this->next = head;
  27.             head = this;
  28.             return;
  29.         }
  30.         Cadou *q = head;
  31.         while (q->next && q->next->nume < this->nume) q = q->next;
  32.         this->next = q->next;
  33.         q->next = this;
  34.  
  35.     }
  36.  
  37.     virtual void afisare() {
  38.         cout << nume << " " << pret << " ";
  39.     }
  40.     static void ShowList() { // afisarea pentru implementare cu pointeri
  41.         Cadou *q = head;
  42.         while (q) {
  43.             q->afisare();
  44.             q = q->next;
  45.         }
  46.     }
  47.     string get_nume() { return nume; }
  48.     double get_pret() { return pret; }
  49.  
  50. };
  51. Cadou * Cadou::head = NULL;
  52.  
  53.  
  54. class Bijuteri :public Cadou {
  55. private:
  56.     string carate;
  57.  
  58. public:
  59.     Bijuteri(string nume, double pret, string carate) : Cadou(nume, pret) {
  60.         this->carate = carate;
  61.  
  62.     }
  63.     void afisare() {
  64.         Cadou::afisare();
  65.         cout << carate << endl;
  66.     }
  67.  
  68.  
  69.  
  70. };
  71.  
  72. class Jucarie : public Cadou
  73. {
  74. protected:
  75.     string brand;
  76. public:
  77.     Jucarie(string nume, double pret, string brand) : Cadou(nume, pret) {
  78.         this->brand = brand;
  79.     }
  80.     void afisare() {
  81.         Cadou::afisare();
  82.         cout << brand << endl;
  83.     }
  84. };
  85.  
  86. list <Cadou *> listaCadou;
  87. list <Cadou *>::iterator it;
  88.  
  89.  
  90.  
  91.  
  92. void showSTL() {
  93.     cout << "------------------------" << endl;
  94.     for (it = listaCadou.begin(); it != listaCadou.end(); it++)
  95.         (*it)->afisare();
  96.  
  97.  
  98.  
  99. }
  100.  
  101. istream &operator>>(istream &in, Bijuteri *b) {
  102.  
  103.     double pret;
  104.     string nume, carate;
  105.  
  106.  
  107.     cout << "Nume: "; in >> nume;
  108.     cout << "Pret: "; in >> pret;
  109.  
  110.     cout << "Carate: "; in >> carate;
  111.     if (listaCadou.empty())
  112.         listaCadou.push_back(new Bijuteri(nume, pret, carate));
  113.     else {
  114.         it = listaCadou.begin();
  115.         while (it != listaCadou.end() && (*it)->get_nume() < nume)
  116.             advance(it, 1);
  117.         listaCadou.emplace(it, new Bijuteri(nume, pret, carate));
  118.     }
  119.     return in;
  120. }
  121. istream &operator>>(istream &in, Jucarie *j) {
  122.  
  123.     double pret;
  124.     string nume, brand;
  125.  
  126.  
  127.     cout << "Nume: "; in >> nume;
  128.     cout << "Pret: "; in >> pret;
  129.  
  130.     cout << "Brand: "; in >> brand;
  131.     if (listaCadou.empty())
  132.         listaCadou.push_back(new Bijuteri(nume, pret, brand));
  133.     else {
  134.         it = listaCadou.begin();
  135.         while (it != listaCadou.end() && (*it)->get_nume() < nume)
  136.             advance(it, 1);
  137.         listaCadou.emplace(it, new Bijuteri(nume, pret, brand));
  138.     }
  139.     return in;
  140. }
  141.  
  142. int main() {
  143.     Bijuteri *bijuterie = NULL;
  144.     Jucarie *jucarie = NULL;
  145.     bool help;
  146.     int opt;
  147.     do {
  148.         cout << "\n\n";
  149.         cout << "1.Adaugare Cadou\n";
  150.         cout << "2.Afis cadouri \n";
  151.         cout << "0.Iesire \n";
  152.         cout << "Dati optiunea dvs: ";
  153.         cin >> opt;
  154.         system("cls");
  155.         switch (opt) {
  156.         case 1:
  157.             cout << "Este jucarie - 1 sau Bijuterie-0 : "; cin >> help;
  158.             if (help) cin >> jucarie;
  159.             else cin >> bijuterie;
  160.             break;
  161.         case 2:
  162.             showSTL();
  163.             break;
  164.  
  165.         case 0:
  166.             break;
  167.  
  168.         }
  169.     } while (opt != 0);
  170.     return 0;
  171. }
  172.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement