Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.02 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <conio.h>
  4. using namespace std;
  5. typedef enum {activ = 0, inactiv = 1, defect = 2}stare;
  6. typedef enum {V5,V12,V24,V220}tensiune_comanda;
  7.  
  8. class Lista;
  9. class Modul
  10. {
  11. private :
  12. int id_modul = rand() % 4000;
  13. string denumire;
  14. int tip;
  15. public:
  16. int valoare;
  17. Modul *urm;
  18.  
  19. public :
  20. Modul(int tp,int id, string den, int val)
  21. {
  22. tip = tp;
  23. id_modul = id;
  24. denumire = den;
  25. valoare = val;
  26. urm = NULL;
  27. }
  28. virtual void afisare()
  29. {
  30. if (tip == 1)
  31. cout << "element executie :" << endl;
  32. if (tip == 2)
  33. cout << "senzor" << endl;
  34. cout << "ID MODUL :" << id_modul << endl;
  35. cout << "DENUMIRE : " << denumire << endl;
  36. }
  37. friend class Lista;
  38. };
  39. class Element_executie : public Modul
  40. {
  41. tensiune_comanda t;
  42. stare s;
  43. public:
  44. Element_executie(int tp,int id, string den, int val, tensiune_comanda ten, stare st) : Modul(tp,id, den, val)
  45. {
  46. t = ten;
  47. s = st;
  48. }
  49. virtual void afisare()
  50. {
  51. Modul::afisare();
  52. if (s == 0)
  53. {
  54. cout << "ACTIV" << endl;
  55.  
  56. }
  57. if (s == 1)
  58. cout << "INACTIV" << endl;
  59. if (s == 2)
  60. cout << "DEFECT" << endl;
  61. if (t == 0)
  62. cout << "5 volti" << endl;
  63. if (t == 1)
  64. cout << "12 volti" << endl;
  65. if (t == 2)
  66. cout << "24volti" << endl;
  67. if (t == 3)
  68. cout << "220volti" << endl;
  69. }
  70.  
  71. friend class Lista;
  72. };
  73. class Senzor : public Modul
  74. {
  75. float factor_calibrare, factor_translatie;
  76. float val_reala;
  77. int tip;
  78.  
  79. public:
  80. Senzor(int tp,int id, string den, int val, float calib, float transl, float val_r) : Modul(tp,id, den, val)
  81. {
  82. factor_translatie = transl;
  83. factor_calibrare = calib;
  84. val_reala = val_r;
  85.  
  86. }
  87. virtual void afisare()
  88. {
  89. Modul::afisare();
  90. cout << "factor calibrare :" << factor_calibrare<<endl;
  91. cout << "factor translatie :" << factor_translatie << endl;
  92. cout << "valoarea reala :" << val_reala << endl;
  93. }
  94.  
  95. friend class Lista;
  96. };
  97. class Lista
  98. {
  99. public :
  100. Modul *head;
  101. void adaugare(Modul *m);
  102. void afisare_lista();
  103. void stergere(string den);
  104. void cautare();
  105. };
  106. void Lista::adaugare(Modul *a)
  107. {
  108. Modul *m;
  109.  
  110. if (head == NULL)
  111. head = a;
  112. else {
  113. m = head;
  114. while (m->urm != NULL)
  115. m = m->urm;
  116. m->urm = a;
  117. }
  118.  
  119. }
  120. void Lista::afisare_lista()
  121. {
  122. Modul *q;
  123.  
  124. if (head == NULL)
  125. cout << "nu exista nod in lista";
  126. else
  127. {
  128. q = head;
  129. while (q!= NULL)
  130. {
  131. q->afisare();
  132. q = q->urm;
  133.  
  134. }
  135.  
  136. }
  137. }
  138. class Myexception
  139. {
  140. public :
  141. string s;
  142. int i;
  143. Myexception()
  144. {
  145. s = "0";
  146. i = 0;
  147. }
  148. Myexception(string x,int y)
  149. {
  150. x = s;
  151. y = i;
  152.  
  153. }
  154.  
  155. };
  156. void inserare(Lista &l, int x)
  157. {
  158. Modul *m;
  159. int id_modul = rand() % 4000;
  160. string denumire;
  161. int valoare;
  162. int star;
  163. int tensiune;
  164. float factor_calibrare, factor_translatie;
  165. float val_reala;
  166. cout << "dati denumirea";
  167. cin >> denumire;
  168. try {
  169. cout << "dati valoarea:";
  170. cin >> valoare;
  171. if (valoare<0)
  172. throw Myexception("valoare<0", valoare);
  173. }
  174. catch (Myexception y)
  175. {
  176. do {
  177. cout << "introdu valoare pozitiva";
  178. cin >> valoare;
  179. } while (valoare < 0);
  180.  
  181. }
  182. if (x == 0)
  183. {
  184. Element_executie *el;
  185. cout << "dati starea : 0-activ 1-inactiv 2-defect :";
  186. cin >> star;
  187. stare st = static_cast<stare>(star);
  188. cout << "dati tensiunea de comanda : 0-5v, 1-12v 2-24v,3-220v";
  189. cin >> tensiune;
  190. tensiune_comanda t = static_cast<tensiune_comanda>(tensiune);
  191. el = new Element_executie(1, id_modul, denumire, valoare,t,st);
  192. m = el;
  193. l.adaugare(m);
  194. }
  195. if (x == 1)
  196. {
  197. Senzor *sen;
  198. cout << "dati factorul de calibrare";
  199. cin >> factor_calibrare;
  200. cout << "dati factorul de translatie";
  201. cin >> factor_translatie;
  202. val_reala = valoare*factor_calibrare + factor_translatie;
  203. sen = new Senzor(2, id_modul, denumire, valoare, factor_calibrare, factor_translatie, val_reala);
  204. m = sen;
  205. l.adaugare(m);
  206. }
  207. }
  208. void Lista::stergere(string denumire1)
  209. {
  210. Modul *p;
  211. p = head;
  212. if (p)
  213. {
  214. if (head->denumire.compare(denumire1) == 0)
  215. head = head->urm;
  216. else while (p->urm && p->urm->denumire.compare(denumire1) != 0)
  217. p = p->urm;
  218. if (p->urm != NULL)
  219. p->urm = p->urm->urm;
  220.  
  221. }
  222. }
  223. void Lista::cautare()
  224. {
  225. Modul *q;
  226. Element_executie *el;
  227. q = head;
  228. while (q!=NULL)
  229. {
  230. if (q->tip == 1)
  231. {
  232. el = (Element_executie *)q;
  233. if (el->s == 2)
  234. el->afisare();
  235. }
  236. q = q->urm;
  237. }
  238.  
  239.  
  240. }
  241. int main()
  242. {
  243. int opt;
  244. string nume1;
  245. Lista l;
  246. l.head = NULL;
  247. do
  248. {
  249. cout << "1.Adaugare element de executie" << endl;
  250. cout << "2.adaugare senzor" << endl;
  251. cout << "3.afisare modul" << endl;
  252. cout << "4.sterge modul" << endl;
  253. cout << "5.Cautare elemente de executie defecte" << endl;
  254. cout << "introduceti optiunea" << endl;
  255. cin >> opt;
  256. switch (opt)
  257. {
  258. case 1:
  259. inserare(l, 0);
  260. break;
  261. case 2:
  262. inserare(l, 1);
  263. break;
  264. case 3:
  265. l.afisare_lista();
  266. break;
  267. case 4 :
  268. cout << "introdu numele";
  269. cin >> nume1;
  270. l.stergere(nume1);
  271. l.afisare_lista();
  272. break;
  273. case 5 :
  274. l.cautare();
  275. break;
  276. }
  277. } while (opt != 0);
  278. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement