Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<list>
- #include<iterator>
- using namespace std;
- int tip;
- class persoana
- {
- string nume,facultate;
- int varsta;
- public:
- persoana(string nume, string facultate, int varsta)
- {
- this->nume = nume;
- this->facultate = facultate;
- this->varsta = varsta;
- }
- persoana()
- {}
- virtual void afisare()
- {
- cout << endl;
- cout << "Nume: " << nume << endl;
- cout << "Facultate: " << facultate << endl;
- cout << "Varsta: " << varsta << endl;
- }
- };
- class student :public persoana
- {
- string absolvent;
- public:
- student(string nume, string facultate, int varsta, string absolvent) :persoana(nume, facultate, varsta)
- {
- this->absolvent = absolvent;
- }
- student()
- {}
- void afisare()
- {
- persoana::afisare();
- cout << "Absolvent: " << absolvent << endl;
- }
- };
- class profesor :public persoana
- {
- int nr_pub;
- int n;
- enum ab{asistent=1,sef_lucrari,profesor1,profesor_emerit}opt;
- public:
- profesor(string nume, string facultate, int varsta, int nr_pub, int n) :persoana(nume, facultate, varsta)
- {
- this->nr_pub = nr_pub;
- this->n = n;
- }
- profesor()
- {}
- void afisare()
- {
- persoana::afisare();
- cout << "Nr. publicatii: " << nr_pub << endl;
- cout << "Tip profesor: ";
- switch (n)
- {
- case profesor::asistent:
- cout << "Asistent" << endl;
- break;
- case profesor::sef_lucrari:
- cout << "Sef lucrari" << endl;
- break;
- case profesor::profesor1:
- cout << "Profesor" << endl;
- break;
- case profesor::profesor_emerit:
- cout << "Profesor emerit" << endl;
- break;
- default:
- break;
- }
- }
- };
- auto p1 = new student();
- auto p2 = new profesor();
- auto el = new persoana();
- istream& operator>>(istream& intrare,student &p)
- {
- string nume, facultate, absolvent;
- int varsta, nr_pub, n;
- cout << endl;
- cout << "Nume: ";
- intrare >> nume;
- cout << "Facultate: ";
- intrare >> facultate;
- cout << "Varsta: ";
- intrare >> varsta;
- cout << "Absolvent (Da sau Nu): ";
- intrare >> absolvent;
- p = student(nume, facultate, varsta, absolvent);
- return intrare;
- }
- istream& operator>>(istream& intrare, profesor& p)
- {
- string nume, facultate, absolvent;
- int varsta, nr_pub, n;
- cout << endl;
- cout << "Nume: ";
- intrare >> nume;
- cout << "Facultate: ";
- intrare >> facultate;
- cout << "Varsta: ";
- intrare >> varsta;
- cout << "Nr. publicatii: ";
- intrare >> nr_pub;
- cout << "Tip profesor: " << endl;
- cout << "1.Asistent" << endl;
- cout << "2.Sef Lucrari" << endl;
- cout << "3.Profesor" << endl;
- cout << "4.Profesor emerit" << endl;
- cout << "Numarul tipului de profesor: ";
- intrare >> n;
- p = profesor(nume, facultate, varsta, nr_pub,n);
- return intrare;
- }
- void adaugare_membru(list<persoana*>& lista_persoane)
- {
- if (tip == 1)
- {
- el = p1;
- lista_persoane.push_back(el);
- }
- else
- {
- el = p2;
- lista_persoane.push_back(el);
- }
- }
- ostream& operator<<(ostream& iesire, list<persoana*> lista_persoane)
- {
- for (auto i = lista_persoane.begin(); i != lista_persoane.end(); i++)
- {
- persoana* p = *i;
- p->afisare();
- iesire << endl;
- }
- return iesire;
- }
- int main()
- {
- list<persoana*> lista_persoane;
- enum{iesire,adaugare_elev,adaugare_profesor,afisare}opt1;
- int n1;
- do {
- cout << "0.Iesire" << endl;
- cout << "1.Adaugare elev" << endl;
- cout << "2.Adaugare profesor" << endl;
- cout << "3.Afisare" << endl;
- cout << "opt= ";
- cin >> n1;
- switch (n1)
- {
- case iesire:exit(0);
- break;
- case adaugare_elev:
- tip = 1;
- cin >> *p1;
- adaugare_membru(lista_persoane);
- break;
- case adaugare_profesor:
- tip = 2;
- cin >> *p2;
- adaugare_membru(lista_persoane);
- break;
- case afisare:
- cout << lista_persoane;
- cout << endl;
- break;
- default:
- break;
- }
- } while (1);
- }
Advertisement
Add Comment
Please, Sign In to add comment