Patey

Untitled

Nov 10th, 2021
547
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<list>
  3. #include<iterator>
  4.  
  5. using namespace std;
  6.  
  7. int tip;
  8. class persoana
  9. {
  10.     string nume,facultate;
  11.     int varsta;
  12. public:
  13.     persoana(string nume, string facultate, int varsta)
  14.     {
  15.         this->nume = nume;
  16.         this->facultate = facultate;
  17.         this->varsta = varsta;
  18.     }
  19.     persoana()
  20.     {}
  21.     virtual void afisare()
  22.     {
  23.         cout << endl;
  24.         cout << "Nume: " << nume << endl;
  25.         cout << "Facultate: " << facultate << endl;
  26.         cout << "Varsta: " << varsta << endl;
  27.     }
  28. };
  29.  
  30. class student :public persoana
  31. {
  32.     string absolvent;
  33. public:
  34.     student(string nume, string facultate, int varsta, string absolvent) :persoana(nume, facultate, varsta)
  35.     {
  36.         this->absolvent = absolvent;
  37.     }
  38.     student()
  39.     {}
  40.     void afisare()
  41.     {
  42.         persoana::afisare();
  43.         cout << "Absolvent: " << absolvent << endl;
  44.     }
  45. };
  46.  
  47. class profesor :public persoana
  48. {
  49.     int nr_pub;
  50.     int n;
  51.     enum ab{asistent=1,sef_lucrari,profesor1,profesor_emerit}opt;
  52. public:
  53.     profesor(string nume, string facultate, int varsta, int nr_pub, int n) :persoana(nume, facultate, varsta)
  54.     {
  55.         this->nr_pub = nr_pub;
  56.         this->n = n;
  57.     }
  58.     profesor()
  59.     {}
  60.     void afisare()
  61.     {
  62.         persoana::afisare();
  63.         cout << "Nr. publicatii: " << nr_pub << endl;
  64.         cout << "Tip profesor: ";
  65.         switch (n)
  66.         {
  67.         case profesor::asistent:
  68.             cout << "Asistent" << endl;
  69.             break;
  70.         case profesor::sef_lucrari:
  71.             cout << "Sef lucrari" << endl;
  72.             break;
  73.         case profesor::profesor1:
  74.             cout << "Profesor" << endl;
  75.             break;
  76.         case profesor::profesor_emerit:
  77.             cout << "Profesor emerit" << endl;
  78.             break;
  79.         default:
  80.             break;
  81.         }
  82.     }
  83. };
  84. auto p1 = new student();
  85. auto p2 = new profesor();
  86. auto el = new persoana();
  87.  
  88. istream& operator>>(istream& intrare,student &p)
  89. {
  90.     string nume, facultate, absolvent;
  91.     int varsta, nr_pub, n;
  92.     cout << endl;
  93.     cout << "Nume: ";
  94.     intrare >> nume;
  95.     cout << "Facultate: ";
  96.     intrare >> facultate;
  97.     cout << "Varsta: ";
  98.     intrare >> varsta;
  99.     cout << "Absolvent (Da sau Nu): ";
  100.     intrare >> absolvent;
  101.     p = student(nume, facultate, varsta, absolvent);
  102.     return intrare;
  103. }
  104.  
  105. istream& operator>>(istream& intrare, profesor& p)
  106. {
  107.     string nume, facultate, absolvent;
  108.     int varsta, nr_pub, n;
  109.     cout << endl;
  110.     cout << "Nume: ";
  111.     intrare >> nume;
  112.     cout << "Facultate: ";
  113.     intrare >> facultate;
  114.     cout << "Varsta: ";
  115.     intrare >> varsta;
  116.     cout << "Nr. publicatii: ";
  117.     intrare >> nr_pub;
  118.     cout << "Tip profesor: " << endl;
  119.     cout << "1.Asistent" << endl;
  120.     cout << "2.Sef Lucrari" << endl;
  121.     cout << "3.Profesor" << endl;
  122.     cout << "4.Profesor emerit" << endl;
  123.     cout << "Numarul tipului de profesor: ";
  124.     intrare >> n;
  125.     p = profesor(nume, facultate, varsta, nr_pub,n);
  126.     return intrare;
  127. }
  128.  
  129. void adaugare_membru(list<persoana*>& lista_persoane)
  130. {
  131.     if (tip == 1)
  132.     {
  133.         el = p1;
  134.         lista_persoane.push_back(el);
  135.     }
  136.     else
  137.     {
  138.         el = p2;
  139.         lista_persoane.push_back(el);
  140.     }
  141. }
  142.  
  143. ostream& operator<<(ostream& iesire, list<persoana*> lista_persoane)
  144. {
  145.     for (auto i = lista_persoane.begin(); i != lista_persoane.end(); i++)
  146.     {
  147.         persoana* p = *i;
  148.         p->afisare();
  149.         iesire << endl;
  150.     }
  151.     return iesire;
  152. }
  153.  
  154.  
  155. int main()
  156. {
  157.     list<persoana*> lista_persoane;
  158.     enum{iesire,adaugare_elev,adaugare_profesor,afisare}opt1;
  159.     int n1;
  160.     do {
  161.         cout << "0.Iesire" << endl;
  162.         cout << "1.Adaugare elev" << endl;
  163.         cout << "2.Adaugare profesor" << endl;
  164.         cout << "3.Afisare" << endl;
  165.         cout << "opt= ";
  166.         cin >> n1;
  167.         switch (n1)
  168.         {
  169.         case iesire:exit(0);
  170.             break;
  171.         case adaugare_elev:
  172.             tip = 1;
  173.             cin >> *p1;
  174.             adaugare_membru(lista_persoane);
  175.             break;
  176.         case adaugare_profesor:
  177.             tip = 2;
  178.             cin >> *p2;
  179.             adaugare_membru(lista_persoane);
  180.             break;
  181.         case afisare:
  182.             cout << lista_persoane;
  183.             cout << endl;
  184.             break;
  185.         default:
  186.             break;
  187.         }
  188.     } while (1);
  189. }
Advertisement
Add Comment
Please, Sign In to add comment