Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include<conio.h>
- #include<limits>
- using namespace std;
- class persoana {
- string nume;
- int tip;
- persoana* urm;
- public:
- persoana(string n, int t) {
- nume = n;
- tip = t;
- urm = NULL;
- }
- virtual void afis() {
- cout << "\nNume: "<<nume;
- }
- friend class Lista;
- };
- class student : public persoana {
- int an;
- public:
- student(string n, int t, int a) : persoana(n, t) {
- an = a;
- }
- void afis() {
- persoana::afis();
- cout << "\nAn: " << an;
- }
- friend class Lista;
- };
- class profesor : public persoana {
- string materie;
- public:
- profesor(string n, int t, string m) : persoana(n, t) {
- materie = m;
- }
- void afis() {
- persoana::afis();
- cout << "\nMaterie: " << materie;
- }
- friend class Lista;
- };
- class Supraincarcare {
- public:
- string nume, materie;
- int s;
- int tip, an;
- friend istream& operator>>(istream& in, Supraincarcare& a);
- };
- istream& operator>>(istream& in, Supraincarcare& a) {
- cout << "Alegeti numele: "; cin >> a.nume;
- if (a.tip == 0) {
- cout << "Alegeti materia: "; cin >> a.materie;
- }
- else {
- cout << "Alegeti anul:"; cin >> a.an;
- }
- return in;
- }
- class Lista {
- public:
- persoana* head;
- void adaugare(persoana* a) {
- persoana* p;
- p = head;
- if (p == NULL) {
- head = a;
- }
- else{
- if (p->nume.compare(a->nume) > 0) {
- a->urm = head;
- head = a;
- }
- else {
- while (p->urm && p->urm->nume.compare(a->nume)<0)
- p = p->urm;
- a->urm = p->urm;
- p->urm = a;
- }
- }
- }
- void stergere(string n) {
- persoana* p, * q;
- p = q = head;
- if (p) {
- while (p && p->nume.compare(n) != 0) {
- q = p;
- p = p->urm;
- }
- if (p) {
- if (p == q) {
- head = p->urm;
- delete p;
- }
- else {
- q->urm = p->urm;
- delete p;
- }
- }
- else
- cout << "elementul nu a fost gasit";
- }
- else
- cout << "Lista e nula";
- }
- void afisare() {
- persoana* q;
- q = head;
- while (q!=NULL) {
- q->afis();
- q = q->urm;
- }
- }
- int cautaremax() {
- persoana* q = head;
- int max= q->tip;
- while (q != NULL) {
- if (q->tip > max)
- max = q->tip;
- q = q->urm;
- }
- }
- };
- void introducere(Lista &l, int t) {
- Supraincarcare supr;
- supr.tip = t;
- cin >> supr;
- if (supr.tip == 0) {
- profesor* p;
- p = new profesor(supr.nume, supr.tip, supr.materie);
- l.adaugare(p);
- }
- else {
- student* s;
- s = new student(supr.nume, supr.tip, supr.an);
- l.adaugare(s);
- }
- }
- int main() {
- Lista l;
- l.head= NULL;
- introducere(l, 0);
- introducere(l, 1);
- introducere(l, 0);
- l.stergere("3");
- l.afisare();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement