Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<stdio.h>
- #include<stdlib.h>
- #include<list>
- #include<iterator>
- #include<string>
- #define _CRT_SECURE_NO_WARNING
- using namespace std;
- class Persoana {
- private:
- string nume;
- int varsta;
- public:
- Persoana(string nume, int varsta) {
- this->nume = nume;
- this->varsta = varsta;
- }
- virtual void afisare() {
- cout << nume << " " << varsta << " ";
- }
- string get_nume() { return nume; }
- };
- class Fotbalist:public Persoana {
- private:
- int nrGoluri;
- string pozitie;
- public:
- Fotbalist(string nume, int varsta, string pozitie, int nrGoluri) : Persoana(nume, varsta) {
- this->nrGoluri = nrGoluri;
- this->pozitie = pozitie;
- }
- void afisare() {
- Persoana::afisare();
- cout << pozitie << " " <<nrGoluri<< endl;
- }
- };
- class Cantaret : public Persoana
- {
- protected:
- int nrPiese;
- public:
- Cantaret(string nume, int varsta, int nrPiese) : Persoana(nume, varsta) {
- this->nrPiese = nrPiese;
- }
- void afisare() {
- Persoana::afisare();
- cout << nrPiese << endl;
- }
- };
- list <Persoana *> listaCadou;
- list <Persoana *>::iterator it;
- void showSTL() {
- cout << "------------------------" << endl;
- for (it = listaCadou.begin(); it != listaCadou.end(); it++)
- (*it)->afisare();
- }
- istream &operator>>(istream &in, Fotbalist *f) {
- string nume, pozitie;
- int varsta, nrGoluri;
- cout << "Nume: "; in >> nume;
- cout << "Varsta: "; in >> varsta;
- cout << "Pozitie: "; in >> pozitie;
- cout << "Numar de goluri: "; in >> nrGoluri;
- if (listaCadou.empty())
- listaCadou.push_back(new Fotbalist(nume, varsta, pozitie, nrGoluri));
- else {
- it = listaCadou.begin();
- while (it != listaCadou.end() && (*it)->get_nume() < nume)
- advance(it, 1);
- listaCadou.emplace(it, new Fotbalist(nume, varsta, pozitie, nrGoluri));
- }
- return in;
- }
- istream &operator>>(istream &in, Cantaret *C) {
- string nume;
- int varsta, nrPiese;
- cout << "Nume: "; in >> nume;
- cout << "varsta: "; in >> varsta;
- cout << "NrPiese: "; in >> nrPiese;
- if (listaCadou.empty())
- listaCadou.push_back(new Cantaret(nume, varsta, nrPiese));
- else {
- it = listaCadou.begin();
- while (it != listaCadou.end() && (*it)->get_nume() < nume)
- advance(it, 1);
- listaCadou.emplace(it, new Cantaret(nume, varsta, nrPiese));
- }
- return in;
- }
- int main() {
- Fotbalist *F = NULL;
- Cantaret *C = NULL;
- bool help;
- int opt;
- do {
- cout << "\n\n";
- cout << "1.Adaugare Persoana\n";
- cout << "2.Afis persoane \n";
- cout << "0.Iesire \n";
- cout << "Dati optiunea dvs: ";
- cin >> opt;
- system("cls");
- switch (opt) {
- case 1:
- cout << "Este fotbalist - 1 sau cantaret-0 : "; cin >> help;
- if (help) cin >> F;
- else cin >> C;
- break;
- case 2:
- showSTL();
- break;
- case 0:
- break;
- }
- } while (opt != 0);
- return 0;
- }
RAW Paste Data