Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.06 KB | None | 0 0
  1. #include<iostream>
  2. #include<conio.h>
  3. #include<string.h>
  4. using namespace std;
  5.  
  6. class lista;
  7. class fructe {
  8. private:
  9. int tip;
  10. string nume;
  11. int pret;
  12. string valabilitate;
  13. int cantitate;
  14. fructe* urm;
  15. public:
  16. fructe(int t,string n, int p, string valb, int cnt) {
  17. tip = t;
  18. nume = n;
  19. pret = p;
  20. valabilitate = valb;
  21. cantitate = cnt;
  22. urm = NULL;
  23. }
  24. virtual void afisare() {
  25. cout <<"nume: "<< nume << endl;
  26. cout <<"pret: "<< pret << endl;
  27. cout << "valabilitate: "<<valabilitate << endl;
  28. cout << "cantitate: "<<cantitate << endl;
  29. }
  30. friend class lista;
  31. };
  32.  
  33. class autohtone : public fructe {
  34. private:
  35. string judet;
  36. string producator;
  37. string data_cules;
  38. public:
  39. autohtone(int t,string n, int p, string valb, int cnt, string jud, string prod, string data_c) :fructe(t,n, p, valb, cnt) {
  40. judet = jud;
  41. producator = prod;
  42. data_cules = data_c;
  43. }
  44. void afisare() {
  45. fructe::afisare();
  46. cout << "JUDET: " << judet << endl;
  47. cout << "producator: "<<producator << endl;
  48. cout << "data cules: "<<data_cules << endl;
  49. }
  50.  
  51. friend class lista;
  52. };
  53.  
  54. class import: public fructe {
  55. private:
  56. string tara_prov;
  57. string importator;
  58. public:
  59. import(int t,string n, int p, string valb, int cnt, string tara_p, string imp) : fructe(t,n, p, valb, cnt) {
  60. tara_prov = tara_p;
  61. importator = imp;
  62. }
  63. void afisare() {
  64. fructe::afisare();
  65. cout << "TARA: " << tara_prov << endl;
  66. cout <<"importator: "<< importator << endl;
  67. }
  68. friend class lista;
  69. };
  70.  
  71. class lista {
  72. public:
  73. fructe* head;
  74. void adaugare_fructe(fructe* a);
  75. void afisare_fructe();
  76. void cautare_valabilitate(string valabilitate);
  77. int afisare_stoc();
  78. void vanzare(string nume,int cnt);
  79. void max();
  80. };
  81. void lista::adaugare_fructe(fructe* a) {
  82. fructe* p;
  83. p = head;
  84. if (p == NULL) {
  85. head = a;
  86. }
  87. else if (a->nume < head->nume) {
  88. a->urm = head;
  89. head = a;
  90. }
  91. else {
  92. while (p->urm && a->nume > p->urm->nume) p = p->urm;
  93. a->urm = p->urm;
  94. p->urm = a;
  95. }
  96. }
  97.  
  98. void lista::afisare_fructe() {
  99. fructe* p;
  100. p = head;
  101. if (p == NULL) cout << "LISTA GOALA";
  102. else
  103. while (p) {
  104. p->afisare();
  105. p = p->urm;
  106. }
  107.  
  108. }
  109.  
  110. void lista::cautare_valabilitate(string valabilitate) {
  111. fructe* p;
  112. p = head;
  113. if (p == NULL) cout << "lista goala";
  114. else
  115. while (p) {
  116. if (p->valabilitate == valabilitate)
  117. p->afisare();
  118. p = p->urm;
  119. }
  120. }
  121.  
  122. int lista::afisare_stoc() {
  123. int stoc = 0;
  124. fructe* p;
  125. p = head;
  126. if (p == NULL) return 0;
  127. else
  128. while (p) {
  129. stoc = stoc + p->cantitate;
  130. p = p->urm;
  131. }
  132. return stoc;
  133. }
  134.  
  135. void lista::vanzare(string nume,int cnt) {
  136. fructe* p,*q;
  137. p = q = head;
  138. if (p == NULL) cout << "lista vida";
  139. else
  140. while (p && p->nume!=nume){
  141. q = p;
  142. p = p->urm;
  143. }
  144. if (p==NULL) cout << "nu exista fructul";
  145. else
  146. if (p->cantitate > cnt) p->cantitate = p->cantitate - cnt;
  147. else
  148. if (p != q) {
  149. q->urm = p->urm;
  150. delete p;
  151. }
  152. else {
  153. head = p->urm;
  154. delete q;
  155. }
  156. }
  157. void lista::max()
  158. {
  159. int max = 0;
  160. fructe* p,*q;
  161. p = q = head;
  162. if (p == NULL) cout << "lista vida";
  163. while (p) {
  164. if (p->pret > max && p->tip==1) max = p->pret;
  165. p = p->urm;
  166. }
  167. while (q) {
  168. if (q->pret == max&& q->tip==1) q->afisare();
  169. q = q->urm;
  170. }
  171.  
  172. }
  173. void introducere(lista &l, int x) {
  174. fructe *f;
  175. autohtone *a;
  176. import* i;
  177. string nume, valabilitate, judet, producator, data_cules, tara, importator;
  178. int pret, cantitate;
  179. cout << "nume: "; cin >> nume;
  180. cout << "pret: "; cin >> pret;
  181. cout << "valabilitate: "; cin >> valabilitate;
  182. cout << "cantitate: "; cin >> cantitate;
  183.  
  184. if (x == 0) {
  185. cout << "judet: "; cin >> judet;
  186. cout << "producator:"; cin >> producator;
  187. cout << "data la care au fost culese:"; cin >> data_cules;
  188. a = new autohtone(0,nume, pret,valabilitate, cantitate, judet, producator, data_cules);
  189. f = a;
  190. l.adaugare_fructe(f);
  191. }
  192. else
  193. if (x == 1) {
  194. cout << "tara provenienta: "; cin >> tara;
  195. cout << "importaor: "; cin >> importator;
  196. i = new import(1,nume, pret, valabilitate, cantitate, tara, importator);
  197. f = i;
  198. l.adaugare_fructe(f);
  199. }
  200. }
  201. int main() {
  202. int opt,cnt;
  203. string nume,vlb;
  204. lista l;
  205. l.head = NULL;
  206. do {
  207. cout << "1.adaugare autohtone" << endl;
  208. cout << "2.adaugare import" << endl;
  209. cout << "3.afisare lista " << endl;
  210. cout << "4.afisare stoc(cantitatea totala de frct)" << endl;
  211. cout << "5 cautare dupa valabilitate " << endl;
  212. cout << "6.vanzare: " << endl;
  213. cout << "7.pret max import" << endl;
  214. cin >> opt;
  215. switch (opt)
  216. {
  217. case 1:
  218. introducere(l, 0);
  219. break;
  220. case 2:
  221. introducere(l, 1);
  222. break;
  223. case 3:
  224. l.afisare_fructe();
  225. break;
  226. case 4:
  227. cout << l.afisare_stoc();
  228. break;
  229. case 5:
  230. cout << "valabilitate cautata:"; cin >> vlb;
  231. l.cautare_valabilitate(vlb);
  232. break;
  233. case 6:
  234. cout << "nume: "; cin >> nume;
  235. cout << "cantitate "; cin >> cnt;
  236. l.vanzare(nume, cnt);
  237. break;
  238. case 7:
  239. l.max();
  240. break;
  241. default: cout << "optiune gresita";
  242. break;
  243. }
  244.  
  245.  
  246. } while (opt);
  247.  
  248. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement