Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.06 KB | None | 0 0
  1. #include<iostream>
  2. #include<string.h>
  3. #include<conio.h>
  4. using namespace std;
  5.  
  6. //struct adresa
  7. //{
  8. // char *localitate, *tara, *strada;
  9. // int cod_postal, numar;
  10. //};
  11. //
  12. //struct date_contact
  13. //{
  14. // long int nr_telefon;
  15. // char *email, *site, *facebook;
  16. //};
  17. //
  18. //typedef enum { piscina = 0, restaurant = 1, sala_conf = 2, sala_sport = 3 }dotari;
  19.  
  20.  
  21. class lista;
  22. class produs_magazin
  23.  
  24. {
  25.  
  26. private:
  27. int tip_derivat;
  28. char*producator;
  29. int cod_produs;
  30. char*rezolutie;
  31. char*dimensiune;
  32. produs_magazin*urm;
  33. public:
  34. produs_magazin(int t, char*prod, int cod, char*rez, char*dim)
  35. {
  36. producator = new char[strlen(prod) + 1];
  37. strcpy(producator, prod);
  38. rezolutie = new char[strlen(rez) + 1];
  39. strcpy(rezolutie, rez);
  40. dimensiune = new char[strlen(dim) + 1];
  41. strcpy(dimensiune, dim);
  42. tip_derivat = t;
  43. cod_produs = cod;
  44. urm = NULL;
  45. }
  46.  
  47. virtual void afisare()
  48. {
  49. cout << "----------------------\n";
  50. cout << "producator" << producator << endl;
  51. cout << "cod produs" << cod_produs << endl;
  52. cout << "rezolutie" << rezolutie << endl;
  53. cout << "dimensiune" << dimensiune << endl;
  54. }
  55. friend class lista;
  56. };
  57.  
  58. class scaner:public produs_magazin
  59. {
  60. private:
  61. char*soft_inclus;
  62. int viteza_scaner;
  63. public:
  64. scaner(int t, char*prod, int cod, char*rez, char*dim, char*soft, int viteza):produs_magazin(t, prod, cod, rez, dim)
  65. {
  66. soft_inclus = new char[strlen(soft) + 1];
  67. strcpy(soft_inclus, soft);
  68. viteza_scaner= viteza;
  69. }
  70.  
  71. void afisare()
  72. {
  73. produs_magazin::afisare();
  74. cout << "soft inclus:" << soft_inclus << endl;
  75. cout << "viteza_scaner:" << viteza_scaner << endl;
  76. }friend class lista;
  77. };
  78.  
  79. class imprimanta :public produs_magazin
  80. {
  81. private:
  82. char*format;
  83. char*tip;
  84. public:
  85. imprimanta(int t, char*prod, int cod, char*rez, char*dim, char*form, char*tp) :produs_magazin(t, prod, cod, rez, dim)
  86. {
  87. format = new char[strlen(form) + 1];
  88. strcpy(format, form);
  89. tip = new char[strlen(tp) + 1];
  90. strcpy(tip, tp);
  91. }
  92.  
  93. void afisare()
  94. {
  95. produs_magazin::afisare();
  96. cout << "format:" << format << endl;
  97. cout << "tip:" << tip << endl;
  98.  
  99. }friend class lista;
  100.  
  101. };
  102.  
  103. class lista
  104. {
  105. public:
  106. produs_magazin*head;
  107. void adaugare(produs_magazin *prod);
  108. void afisare();
  109. void cautare(char*prod);
  110. void stergere(char *prod);
  111. };
  112.  
  113.  
  114.  
  115. void lista::adaugare(produs_magazin*a)
  116. {
  117. produs_magazin*p;
  118. p = head;
  119. if (p)
  120. {
  121. if (strcmp(a->producator, p->producator) < 0)
  122. {
  123. a->urm = head;
  124. head = a;
  125. }
  126. else
  127. {
  128. while (p->urm && strcmp((p->urm)->producator, a->producator) < 0)
  129. p = p->urm;
  130. a->urm = p->urm;
  131. p->urm = a;
  132. }
  133. }
  134. else
  135. head = a;
  136. }
  137.  
  138. void lista::afisare()
  139. {
  140. produs_magazin*a;
  141. a = head;
  142. if (!a)
  143. cout << "lista este goala";
  144. else
  145. while (a)
  146. {
  147. a->afisare();
  148. a = a->urm;
  149. }
  150.  
  151. }
  152.  
  153. void introducere(lista&l, int x)
  154. {
  155. int tip_derivat;
  156. char producator[50];
  157. int cod_produs;
  158. char rezolutie[50];
  159. char dimensiune[50];
  160. char soft_inclus[50];
  161. int viteza_scaner;
  162. char format[50];
  163. char tip[50];
  164. produs_magazin*prodMag;
  165.  
  166. cout << "Introduceti producator:";
  167. cin >> producator;
  168. cout << "Introduceti cod produs:";
  169. cin >> cod_produs;
  170. cout << "Introduceti rezolutia:";
  171. cin >> rezolutie;
  172. cout << "Introduceti dimensiunea:";
  173. cin >> dimensiune;
  174.  
  175. if (x == 0)
  176. {
  177. scaner *Sc;
  178. cout << "introduceti softul";
  179. cin >> soft_inclus;
  180. cout << "Introduceti viteza:";
  181. cin >> viteza_scaner;
  182.  
  183. Sc = new scaner(1, producator, cod_produs, rezolutie, dimensiune, soft_inclus, viteza_scaner);
  184. prodMag = Sc;
  185. l.adaugare(prodMag);
  186. }
  187.  
  188. else if (x == 1)
  189. {
  190. imprimanta*imprim;
  191. cout << "introduceti format";
  192. cin >> format;
  193. cout << "introduceti tip";
  194. cin >> tip;
  195.  
  196. imprim = new imprimanta(2, producator, cod_produs, rezolutie, dimensiune, format, tip);
  197. prodMag = imprim;
  198. l.adaugare(prodMag);
  199. }
  200.  
  201. }
  202.  
  203.  
  204. void lista::cautare(char*prod)
  205. {
  206. produs_magazin*a;
  207. a = head;
  208. if (!a)
  209. cout << "lista este goala";
  210. else
  211. {
  212. while (a)
  213. {
  214. if (strcmp(a->urm->producator, prod) == 0)
  215. a->afisare();
  216. a = a->urm;
  217. }
  218.  
  219. }
  220. }
  221.  
  222. void lista::stergere(char*prod)
  223. {
  224. produs_magazin*p,*q;
  225. p = q = head;
  226. if (p)
  227. {
  228. while (p&& strcmp(p->producator, prod) != 0)
  229. {
  230. q = p;
  231. p = p->urm;
  232. }
  233. if (p)
  234. {
  235. if (p != q)
  236. {
  237. q->urm = p->urm;
  238. delete p;
  239. }
  240. else
  241. {
  242. head = p->urm;
  243. delete p;
  244. }
  245. }
  246. else
  247. cout << "producatorul nu exista in lista ";
  248. }
  249. else
  250. cout << "lista este vida";
  251.  
  252. }
  253.  
  254. void main()
  255. {
  256. int opt;
  257. lista l;
  258. l.head = NULL;
  259. do
  260. {
  261. system("cls");
  262. cout << "1.adaugare scaner in lista.\n";
  263. cout << "2.adaugare imprimanta in lista.\n";
  264. cout << "3.afisare articol din lista.\n";
  265. cout << "4.cautare.\n";
  266. cout << "5.stergere.\n";
  267. cout << "0.iesire.\n";
  268. cin >> opt;
  269. switch (opt)
  270. {
  271. case 1:introducere(l, 0);
  272. break;
  273. case 2:introducere(l, 1);
  274. break;
  275. case 3:l.afisare();
  276. break;
  277. case 4:char prod[20];
  278. cout << "\Dati prod dupa care se cauta";
  279. cin >> prod;
  280. l.cautare(prod);
  281. cout << "apasati pt continuare";
  282. _getch;
  283. break;
  284. case 5:char produc[20];
  285. cout << "\Dati prod dupa care se sterge";
  286. cin >> produc;
  287. l.stergere(produc);
  288. cout << "apasati pt continuare";
  289. _getch;
  290. break;
  291. case 0:
  292. break;
  293. default :cout << "comanda gresita";
  294.  
  295. }
  296.  
  297. } while (opt != 0);
  298. }
  299.  
  300.  
  301. //------------------------------------------------------------------------------------
  302. /*void Lista::Adaugare_Fata(Agentie *a) //adaugare in fata listei (pusa in comentarii pt ca folosim adaugarea ordonata)
  303. {
  304. if (head == NULL)
  305. {
  306. head = a;
  307. }
  308. else
  309. {
  310. a->urm = head;
  311. head = a;
  312. }
  313. }
  314.  
  315. //--------------------------------------------------------------------------
  316. void Lista::Adaugare_Spate(Agentie *a) //adaugare la sfarsitul listei (pusa in comentarii pt ca folosim adaugarea ordonata)
  317. {
  318. Agentie *p;
  319. if (head == NULL)
  320. {
  321. head = a;
  322. }
  323. else
  324. {
  325. p = head;
  326. while (p->urm != NULL)
  327. p = p->urm;
  328. p->urm = a;
  329. }
  330. }*/
  331. //------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement