Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <conio.h>
- #include <iostream>
- #include <string>
- using namespace std;
- typedef enum { activ = 0, inactiv = 1, defect = 2 }stare;
- typedef enum { V5, V12, V14, V220 }tensiune_comanda;
- class Lista;
- class Modul
- {
- int tip;
- int id_modul = rand() % 4000;
- string denumire;
- public:
- int valoare;
- Modul *urm;
- Modul(int tip, int id_modul, string denumire, int valoare)
- {
- this->tip = tip;
- this->id_modul = id_modul;
- this->denumire = denumire;
- this->valoare = valoare;
- }
- virtual void afisare()
- {
- if (tip == 1)
- cout << "Element executie: " << endl;
- if (tip == 2)
- cout << "Senzor " << endl;
- cout << "ID_modul: " << id_modul << endl;
- cout << "Denumire: " << denumire << endl;
- }
- friend class Lista;
- };
- class Element_executie :public Modul
- {
- tensiune_comanda t;
- stare s;
- public:
- Element_executie(int tip, int id_modul, string denumire, int valoare, tensiune_comanda t, stare s) :Modul(tip, id_modul, denumire, valoare)
- {
- this->t = t;
- this->s = s;
- }
- void afisare()
- {
- Modul::afisare();
- if (s == 0) cout << "Activ";
- if (s == 1) cout << "Inactiv";
- if (s == 2) cout << "Defect";
- cout << endl;
- if (t == 0) cout << "5 Volti";
- if (t == 1) cout << "12 Volti";
- if (t == 2) cout << "24 Volti";
- if (t == 3) cout << "220 Volti";
- cout << endl;
- cout << endl;
- }
- friend class Lista;
- };
- class Senzor :public Modul
- {
- float factor_calibrare;
- float factor_translatie;
- float val_reala;
- int tip;
- public:
- Senzor(int tip, int id_modul, string denumire, int valoare, float factor_calibrare, float factor_translatie, float val_reala) :Modul(tip, id_modul, denumire, valoare)
- {
- this->factor_calibrare = factor_calibrare;
- this->factor_translatie = factor_translatie;
- this->val_reala = val_reala;
- }
- void afisare()
- {
- Modul::afisare();
- cout << "Factor calibrare: " << factor_calibrare << endl;
- cout << "Factor translatie: " << factor_translatie << endl;
- cout << "Valoare reala: " << val_reala<<endl<<endl;
- }
- friend class Lista;
- };
- class Lista
- {
- public:
- Modul *head;
- void adaugare(Modul *m);
- void afisare_lista();
- void stergere();
- void cautare();
- };
- class MyException
- {
- public:
- string s;
- int i;
- MyException(string s, int i)
- {
- s = this->s;
- i = this->i;
- }
- };
- void Lista::adaugare(Modul *a)
- {
- Modul *p;
- p = head;
- if (!p)
- {
- head = a;
- }
- else
- {
- if (a->denumire.compare(p->denumire) < 0)
- {
- a->urm = head;
- head = a;
- }
- else
- {
- while (p->urm && p->urm->denumire.compare(a->denumire) > 0)
- p = p->urm;
- a->urm = p->urm;
- p->urm = a;
- }
- }
- }
- void introd(Lista &m, int x)
- {
- Modul *mod;
- int id_modul = rand() % 4000;
- string denumire;
- int valoare;
- int star;
- int tensiune;
- float factor_calibrare, factor_translatie;
- float val_reala;
- cout << "Dati denumirea: ";
- cin >> denumire;
- try
- {
- cout << "Dati valoarea: ";
- cin >> valoare;
- if (valoare < 0)
- throw MyException("Valoare negativa ", valoare);
- }
- catch (MyException y)
- {
- do {
- cout << "Introdu val pozitiva ";
- cin >> valoare;
- } while (valoare < 0);
- }
- if (x == 1)
- {
- Element_executie *el;
- cout << "dati starea : 0-activ 1-inactiv 2-defect :";
- cin >> star;
- stare st = static_cast<stare>(star);
- cout << "dati tensiunea de comanda : 0-5v, 1-12v 2-24v,3-220v";
- cin >> tensiune;
- tensiune_comanda t = static_cast<tensiune_comanda>(tensiune);
- el = new Element_executie(1, id_modul, denumire, valoare, t, st);
- mod = el;
- m.adaugare(mod);
- }
- if (x == 2)
- {
- Senzor *sen;
- cout << "dati factorul de calibrare";
- cin >> factor_calibrare;
- cout << "dati factorul de translatie";
- cin >> factor_translatie;
- val_reala = valoare*factor_calibrare + factor_translatie;
- sen = new Senzor(2, id_modul, denumire, valoare, factor_calibrare, factor_translatie, val_reala);
- mod = sen;
- m.adaugare(mod);
- }
- }
- void Lista::afisare_lista()
- {
- Modul *p;
- p = head;
- if (!p)
- cout << "Lista vida!";
- else
- {
- while (p != NULL)
- {
- p->afisare();
- p = p->urm;
- _getch();
- }
- }
- }
- void Lista::stergere()
- {
- Modul *p,*q;
- p = head;
- q = head;
- string nume;
- cout << "Denumire de sters: ";
- cin >> nume;
- if (p)
- {
- while (p && p->denumire.compare(nume))
- {
- q = p;
- p = p->urm;
- }
- if (p)
- {
- if (q != p)
- {
- q->urm = p->urm;
- delete p;
- }
- else
- {
- head = p->urm;
- delete p;
- }
- }
- else cout << "Negasit" << endl;
- }
- }
- void Lista::cautare()
- {
- Modul *p;
- p = head;
- if (!p)
- cout << "Lista vida!";
- else
- {
- while (p != NULL)
- {
- if (p->tip == 1)
- {
- Element_executie *el;
- el = (Element_executie *)p;
- if (el->s == 2)
- el->afisare();
- }
- p = p->urm;
- }
- }
- }
- int main()
- {
- int opt;
- string nume1;
- Lista l;
- l.head = NULL;
- do
- {
- cout << endl << "1.Adaugare element de executie" << endl;
- cout << "2.adaugare senzor" << endl;
- cout << "3.afisare modul" << endl;
- cout << "4.sterge modul" << endl;
- cout << "5.Cautare elemente de executie defecte" << endl;
- cout << "introduceti optiunea" << endl;
- cin >> opt;
- switch (opt)
- {
- case 1:
- introd(l, 1);
- break;
- case 2:
- introd(l, 2);
- break;
- case 3:
- l.afisare_lista();
- break;
- case 4:
- l.stergere();
- l.afisare_lista();
- break;
- case 5:
- l.cautare();
- break;
- }
- } while (opt != 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement