Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <conio.h>
- using namespace std;
- typedef enum {activ = 0, inactiv = 1, defect = 2}stare;
- typedef enum {V5,V12,V24,V220}tensiune_comanda;
- class Lista;
- class Modul
- {
- private :
- int id_modul = rand() % 4000;
- string denumire;
- int tip;
- public:
- int valoare;
- Modul *urm;
- public :
- Modul(int tp,int id, string den, int val)
- {
- tip = tp;
- id_modul = id;
- denumire = den;
- valoare = val;
- urm = NULL;
- }
- 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 tp,int id, string den, int val, tensiune_comanda ten, stare st) : Modul(tp,id, den, val)
- {
- t = ten;
- s = st;
- }
- virtual void afisare()
- {
- Modul::afisare();
- if (s == 0)
- {
- cout << "ACTIV" << endl;
- }
- if (s == 1)
- cout << "INACTIV" << endl;
- if (s == 2)
- cout << "DEFECT" << endl;
- if (t == 0)
- cout << "5 volti" << endl;
- if (t == 1)
- cout << "12 volti" << endl;
- if (t == 2)
- cout << "24volti" << endl;
- if (t == 3)
- cout << "220volti" << endl;
- }
- friend class Lista;
- };
- class Senzor : public Modul
- {
- float factor_calibrare, factor_translatie;
- float val_reala;
- int tip;
- public:
- Senzor(int tp,int id, string den, int val, float calib, float transl, float val_r) : Modul(tp,id, den, val)
- {
- factor_translatie = transl;
- factor_calibrare = calib;
- val_reala = val_r;
- }
- virtual void afisare()
- {
- Modul::afisare();
- cout << "factor calibrare :" << factor_calibrare<<endl;
- cout << "factor translatie :" << factor_translatie << endl;
- cout << "valoarea reala :" << val_reala << endl;
- }
- friend class Lista;
- };
- class Lista
- {
- public :
- Modul *head;
- void adaugare(Modul *m);
- void afisare_lista();
- void stergere(string den);
- void cautare();
- };
- void Lista::adaugare(Modul *a)
- {
- Modul *m;
- if (head == NULL)
- head = a;
- else {
- m = head;
- while (m->urm != NULL)
- m = m->urm;
- m->urm = a;
- }
- }
- void Lista::afisare_lista()
- {
- Modul *q;
- if (head == NULL)
- cout << "nu exista nod in lista";
- else
- {
- q = head;
- while (q!= NULL)
- {
- q->afisare();
- q = q->urm;
- }
- }
- }
- class Myexception
- {
- public :
- string s;
- int i;
- Myexception()
- {
- s = "0";
- i = 0;
- }
- Myexception(string x,int y)
- {
- x = s;
- y = i;
- }
- };
- void inserare(Lista &l, int x)
- {
- Modul *m;
- 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<0", valoare);
- }
- catch (Myexception y)
- {
- do {
- cout << "introdu valoare pozitiva";
- cin >> valoare;
- } while (valoare < 0);
- }
- if (x == 0)
- {
- 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);
- m = el;
- l.adaugare(m);
- }
- if (x == 1)
- {
- 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);
- m = sen;
- l.adaugare(m);
- }
- }
- void Lista::stergere(string denumire1)
- {
- Modul *p;
- p = head;
- if (p)
- {
- if (head->denumire.compare(denumire1) == 0)
- head = head->urm;
- else while (p->urm && p->urm->denumire.compare(denumire1) != 0)
- p = p->urm;
- if (p->urm != NULL)
- p->urm = p->urm->urm;
- }
- }
- void Lista::cautare()
- {
- Modul *q;
- Element_executie *el;
- q = head;
- while (q!=NULL)
- {
- if (q->tip == 1)
- {
- el = (Element_executie *)q;
- if (el->s == 2)
- el->afisare();
- }
- q = q->urm;
- }
- }
- int main()
- {
- int opt;
- string nume1;
- Lista l;
- l.head = NULL;
- do
- {
- cout << "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:
- inserare(l, 0);
- break;
- case 2:
- inserare(l, 1);
- break;
- case 3:
- l.afisare_lista();
- break;
- case 4 :
- cout << "introdu numele";
- cin >> nume1;
- l.stergere(nume1);
- l.afisare_lista();
- break;
- case 5 :
- l.cautare();
- break;
- }
- } while (opt != 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement