Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string.h>
- using namespace std;
- class Lista;
- class obj
- {
- int a;
- char *b;
- obj *urm;
- public:
- obj(int a1, char *b1)
- {
- a = a1;
- strcpy(b, b1);
- urm = NULL;
- }
- virtual void afisare()
- {
- if (a == 1)
- cout << "obiect1" << endl;
- if (a == 2)
- cout << "obiect2" << endl;
- cout << "Nume" << b << endl;
- }
- friend class Lista;
- };
- class lucru : public obj
- {
- private:
- char *greutate;
- public:
- lucru(int a1, char *b1, char *g) : obj(a1, b1)
- {
- greutate = new char[strlen(g) + 1];
- strcpy(greutate, g);
- }
- void afisare()
- {
- obj::afisare();
- cout << "Greutate:" << greutate << endl;
- }
- friend class Lista;
- };
- class chestie : public obj
- {
- int lung;
- public:
- chestie(int a1, char *b1, int l) : obj(a1, b1)
- {
- lung = l;
- }
- void afisare()
- {
- obj::afisare();
- cout << "Lungime" << lung << endl;
- }
- friend class Lista;
- };
- class Lista
- {
- public:
- obj *head;
- void adaugare(obj *a);
- void afisare();
- void cautare();
- };
- void Lista::adaugare(obj *a)
- {
- obj *p;
- if (head == NULL)
- {
- head = a;
- }
- else
- {
- p = head;
- while (p->urm != NULL)
- p = p->urm;
- p->urm = a;
- }
- }
- void Lista::afisare()
- {
- obj *p;
- p = head;
- if (!p)
- {
- cout << "Lista vida!";
- }
- else
- {
- while (p)
- {
- p->afisare();
- p = p->urm;
- system("pause");
- }
- }
- }
- void introducere(Lista &l, int a)
- {
- obj *p;
- char *b;
- int lung;
- char *greutate;
- cout << "Dati nume" << endl;
- cin >> b;
- if (a == 1)
- {
- lucru *i;
- cout << "Greutate:" << endl;
- cin >> greutate;
- i = new lucru(a, b, greutate);
- p = i;
- l.adaugare(p);
- }
- if (a == 2)
- {
- chestie *i;
- cout << "Lungime:" << endl;
- cin >> lung;
- i = new chestie(a, b, lung);
- p = i;
- l.adaugare(p);
- }
- }
- int main()
- {
- Lista l;
- l.head = NULL;
- introducere(l, 1);
- introducere(l, 2);
- l.afisare();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement