Advertisement
Patey

Untitled

Jan 16th, 2022
1,235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.83 KB | None | 0 0
  1. #include<iostream>
  2. #include<list>
  3. #include<iterator>
  4.  
  5. using namespace std;
  6.  
  7. class adancime
  8. {
  9.     int nota;
  10. public:
  11.     adancime(int nota)
  12.     {
  13.         this->nota = nota;
  14.     }
  15.     void afisare_clasa()
  16.     {
  17.         cout << "Nota: " << nota << endl;
  18.     }
  19. };
  20.  
  21. adancime* citire_adancime()
  22. {
  23.     int nota;
  24.     cout << "Nota: ";
  25.     cin >> nota;
  26.     auto a = new adancime(nota);
  27.     return a;
  28. }
  29.  
  30. class baza
  31. {
  32. public:
  33.     list<adancime*>lista_adancime;
  34.     string materie;
  35.     baza(string materie)
  36.     {
  37.         this->materie = materie;
  38.     }
  39.     void afisare()
  40.     {
  41.         cout << "Materie: " << materie << endl;
  42.     }
  43.     void adaugare_adancime()
  44.     {
  45.         lista_adancime.push_back(citire_adancime());
  46.     }
  47.     void afisare_adancime()
  48.     {
  49.         for (auto i : lista_adancime)
  50.         {
  51.             i->afisare_clasa();
  52.         }
  53.         cout << endl;
  54.     }
  55. };
  56.  
  57. baza* citire_baza()
  58. {
  59.     string nume;
  60.     cout << "Nume: ";
  61.     cin >> nume;
  62.     auto b = new baza(nume);
  63.     return b;
  64. }
  65.  
  66. baza* cautare(list<baza*>listc, string nume)
  67. {
  68.     for (auto i: listc)
  69.     {
  70.         if (i->materie == nume)
  71.         {
  72.             baza* c;
  73.             c = i;
  74.             return c;
  75.         }
  76.     }
  77.     return NULL;
  78. }
  79.  
  80. void afisare_baza(list<baza*>lista_baza)
  81. {
  82.     for (auto i : lista_baza)
  83.     {
  84.         cout << "Nume: " << i->materie << endl;
  85.         i->afisare_adancime();
  86.     }
  87. }
  88.  
  89. int main()
  90. {
  91.     list<baza*>lista_baza;
  92.     int opt;
  93.     string materie;
  94.     do {
  95.         cout << "1. Citire" << endl;
  96.         cout << "2. Afisare" << endl;
  97.         cout << "opt= ";
  98.         cin >> opt;
  99.         switch (opt)
  100.         {
  101.         case 1:
  102.             cout << "1.Baza" << endl;
  103.             cout << "2.Adancime" << endl;
  104.             cout << "opt= ";
  105.             cin >> opt;
  106.             if (opt == 1)
  107.             {
  108.                 lista_baza.push_back(citire_baza());
  109.                 cout << endl;
  110.             }
  111.             else
  112.             {
  113.                 cout << "Materie: ";
  114.                 cin >> materie;
  115.                 auto c = cautare(lista_baza, materie);
  116.                 c->adaugare_adancime();
  117.             }
  118.             break;
  119.         case 2:
  120.             afisare_baza(lista_baza);
  121.             break;
  122.         default:
  123.             break;
  124.         }
  125.     } while (1);
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement