Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.54 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3. #include <conio.h>
  4.  
  5. using namespace std;
  6.  
  7. class Articole
  8. {
  9. int td,cod_produs,rezolutie,dimensiuni;
  10. char *producator;
  11. Articole *urm;
  12. public:
  13. Articole(int tip_derivat,int c, char *p, int r, int d)
  14. {
  15. td=tip_derivat;
  16. producator = new char[strlen(p)+1];
  17. strcpy(producator,p);
  18. cod_produs=c;
  19. rezolutie=r;
  20. dimensiuni=d;
  21. urm=NULL;
  22. }
  23. virtual void afisare()
  24. {
  25. cout<<"----------------------------"<<endl;
  26. cout<<"Producatorul este: "<<producator<<endl;
  27. cout<<"Codul este: "<<cod_produs<<endl;
  28. cout<<"Rezolutia este: "<<rezolutie<<endl;
  29. cout<<"Dimensiunile sunt: "<<dimensiuni<<endl;
  30. }
  31. friend class Lista;
  32. };
  33.  
  34. class Scanere:public Articole
  35. {
  36. char *soft_inclus;
  37. int viteza;
  38. public:
  39. Scanere(int tip_derivat,int c, char *p,int r,int d,char *s,int v):Articole(tip_derivat,c,p,r,d)
  40. {
  41. soft_inclus = new char[strlen(s)+1];
  42. strcpy(soft_inclus,s);
  43. viteza=v;
  44. }
  45. void afisare()
  46. {
  47. Articole::afisare();
  48. cout<<"Softul este: "<<soft_inclus<<endl;
  49. cout<<"Viteza este: "<<viteza<<endl;
  50. }
  51. friend class Lista;
  52. };
  53.  
  54. class Imprimante:public Articole
  55. {
  56. char *format,*tip;
  57. public:
  58. Imprimante(int tip_derivat,int c, char *p,int r,int d,char *f,char *t):Articole(tip_derivat,c,p,r,d)
  59. {
  60. format = new char[strlen(f)+1];
  61. strcpy(format,f);
  62. tip = new char[strlen(t)+1];
  63. strcpy(tip,t);
  64. }
  65. void afisare()
  66. {
  67. Articole::afisare();
  68. cout<<"Formatul este: "<<format<<endl;
  69. cout<<"Tipul este: "<<tip<<endl;
  70. }
  71. friend class Lista;
  72. };
  73.  
  74. class Lista
  75. {
  76. public:
  77. Articole *head;
  78. void adaugare(Articole *prod);
  79. void afisare_lista();
  80. void cautare(char *soft);
  81. void stergere(char *prod);
  82. };
  83.  
  84. void Lista::adaugare(Articole *a)
  85. {
  86. Articole *p;
  87. p=head;
  88. if(!p)
  89. head=a;
  90. else
  91. if(strcmp(a->producator,p->producator)<0)
  92. {
  93. a->urm=head;
  94. head=a;
  95. }
  96. else
  97. {
  98. while(p->urm && strcmp(a->producator,p->urm->producator)>0)
  99. p=p->urm;
  100. a->urm=p->urm;
  101. p->urm=a;
  102. }
  103. }
  104.  
  105. void introducere(Lista &l, int x)
  106. {
  107. char producator[50],soft_inclus[50],format[50],tip_derivat[50],tip[50];
  108. int cod_produs,rezolutie,dimensiuni,viteza;
  109. Articole *a;
  110. cout<<"Introduceti producatorul: ";
  111. cin>>producator;
  112. cout<<"Introduceti codul: ";
  113. cin>>cod_produs;
  114. cout<<"Introduceti rezolutia: ";
  115. cin>>rezolutie;
  116. cout<<"Introduceti dimensiunea: ";
  117. cin>>dimensiuni;
  118. if(x==0)
  119. {
  120. Scanere *Sc;
  121. cout<<"Introduceti softul: ";
  122. cin>>soft_inclus;
  123. cout<<"Introduceti viteza: ";
  124. cin>>viteza;
  125. Sc = new Scanere(1,cod_produs,producator,rezolutie,dimensiuni,soft_inclus,viteza);
  126. a=Sc;
  127. l.adaugare(a);
  128. }
  129. else
  130. if(x==1)
  131. {
  132. Imprimante *Imp;
  133. cout<<"Introduceti format: ";
  134. cin>>format;
  135. cout<<"Introduceti tipul: ";
  136. cin>>tip;
  137. Imp = new Imprimante(2,cod_produs,producator,rezolutie,dimensiuni,format,tip);
  138. a=Imp;
  139. l.adaugare(a);
  140. }
  141. }
  142.  
  143. void Lista::afisare_lista()
  144. {
  145. Articole *a;
  146. a=head;
  147. if(!a)
  148. cout<<"Lista este vida";
  149. else
  150. while(a)
  151. {
  152. a->afisare();
  153. a=a->urm;
  154. }
  155. }
  156.  
  157. void Lista::cautare(char *soft)
  158. {
  159. Articole *a;
  160. Scanere *Sc;
  161. a=head;
  162. if(!a)
  163. cout<<"Lista este vida";
  164. else
  165. while(a)
  166. {
  167. if(a->td==1)
  168. {
  169. Sc = (Scanere*)a;
  170. if(strcmp(Sc->soft_inclus,soft)==0)
  171. a->afisare();
  172. }
  173. a=a->urm;
  174. }
  175. }
  176.  
  177. void Lista::stergere(char *prod)
  178. {
  179. Articole *a,*q;
  180. a=q=head;
  181. if(!a)
  182. cout<<"Lista este vida";
  183. else
  184. {
  185. while(a && strcmp(a->producator,prod)!=0)
  186. {
  187. q=a;
  188. a=a->urm;
  189. }
  190. if(!a)
  191. cout<<"Producatorul nu exista in lista";
  192. else
  193. if(a!=q)
  194. {
  195. q->urm=a->urm;
  196. delete a;
  197. }
  198. else
  199. {
  200. head=a->urm;
  201. delete a;
  202. }
  203. }
  204. }
  205. int main()
  206. {
  207. int optiune;
  208. Lista l;
  209. l.head=NULL;
  210. do
  211. {
  212. cout<<"1. Adaugare scanere in lista"<<endl;
  213. cout<<"2. Adaugare imprimante in lista"<<endl;
  214. cout<<"3. Afisare articole"<<endl;
  215. cout<<"4. Afisare scanere cu un anumit soft"<<endl;
  216. cout<<"5. Stergere articol dupa producator"<<endl;
  217. cout<<"Dati o optiune: ";
  218. cin>>optiune;
  219. switch(optiune)
  220. {
  221. case 1:
  222. introducere(l,0);
  223. break;
  224. case 2:
  225. introducere(l,1);
  226. break;
  227. case 3:
  228. l.afisare_lista();
  229. break;
  230. case 4:
  231. char soft[50];
  232. cout<<"Introduceti numele softului: ";
  233. cin>>soft;
  234. l.cautare(soft);
  235. break;
  236. case 5:
  237. char prod[50];
  238. cout<<"Introduceti numele producatorului: ";
  239. cin>>prod;
  240. l.stergere(prod);
  241. l.afisare_lista();
  242. case 0:
  243. break;
  244. default:
  245. cout<<"Optiune gresita"<<endl;
  246. }
  247. }while(optiune);
  248. getch();
  249. return 0;
  250. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement