Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.69 KB | None | 0 0
  1. #include<iostream>
  2. #include<conio.h>
  3. #include<string>
  4. using namespace std;
  5. class Lista;
  6.  
  7. class agentie
  8. {
  9. private:
  10. int tip, pret, tenis;
  11. string nume;
  12. agentie *urm;
  13. public:
  14. agentie(int tp, string n, int p, int t)
  15. {
  16. tip = tp;
  17. nume = n;
  18. pret = p;
  19. tenis = t;
  20. urm = NULL;
  21. }
  22. void virtual afisare()
  23. {
  24. cout << "------------------\n";
  25. if (tip == 1)
  26. cout << "Tip=hotel\n";
  27. else
  28. cout << "Tip=pensiune\n";
  29. cout << "Pret=" << pret << "\n";
  30. cout << "Nume=" << nume << "\n";
  31. cout << "Tenis=" << tenis << "\n";
  32. }
  33. friend class Lista;
  34. };
  35.  
  36. class hotel :public agentie
  37. {
  38. private:
  39. int stele, piscina, sauna;
  40. public:
  41. hotel(int tp, string n, int p, int t, int stars, int pisc, int sau) :agentie(tp, n, p, t)
  42. {
  43. stele = stars;
  44. piscina = pisc;
  45. sauna = sau;
  46. }
  47. void afisare()
  48. {
  49. agentie::afisare();
  50. cout << "Stele=" << stele << endl;
  51. cout << "Piscina=" << piscina << endl;
  52. cout << "Sauna=" << sauna << endl;
  53. }
  54. friend class Lista;
  55. };
  56.  
  57. class pensiune :public agentie
  58. {
  59. private:
  60. int margarete, gradina;
  61. public:
  62. pensiune(int tp, string n, int p, int t, int marga, int grad) :agentie(tp, n, p, t)
  63. {
  64. margarete = marga;
  65. gradina = grad;
  66. }
  67.  
  68. void afisare()
  69. {
  70. agentie::afisare();
  71. cout << "Margarete=" << margarete << endl;
  72. cout << "Gradina=" << gradina << endl;
  73. }
  74. friend class Lista;
  75. };
  76.  
  77. class Lista
  78. {
  79. public:
  80. agentie *head;
  81. void adaugare(agentie *a);//adaugare in lista
  82. void afisare_lista();
  83. void stergere(string nume);
  84. void oferta_avantajoasa();
  85. };
  86.  
  87. void Lista::adaugare(agentie *a)
  88. {
  89. agentie *p;
  90. p = head;
  91. if (p == NULL)
  92. {
  93. head = a;
  94. }
  95. else
  96. {
  97. if (a->nume.compare( head->nume) < 0)
  98. {
  99. a->urm = head;
  100. head = a;
  101. }
  102. else
  103. {
  104. while (p->urm && (a->nume.compare(p->urm->nume) > 0))
  105. p = p->urm;
  106. a->urm = p->urm;
  107. p->urm = a;
  108. }
  109. }
  110. }
  111.  
  112. void Lista::afisare_lista()
  113. {
  114. agentie *p;
  115. p = head;
  116. while (p != NULL)
  117. {
  118. p->afisare();//se apeleaza afisarea corespunzatoare nodului curent
  119. p = p->urm;
  120. }
  121. }
  122.  
  123. void introducere(Lista &l, int x)//introd informatii in noduri
  124. {
  125. string nume;
  126. int pret;
  127. int tenis;
  128. int stele;
  129. int piscina;
  130. int sauna;
  131. int margarete;
  132. int gradina;
  133. agentie *p;
  134.  
  135. cout << "Dati numele: ";
  136. cin >> nume;
  137. cout << "Dati pretul camerei: ";
  138. cin >> pret;
  139. cout << "Dati daca are teren de tenis[0/1]: ";
  140. cin >> tenis;
  141.  
  142. if (x == 1)//daca e hotel
  143. {
  144. hotel *h;
  145. cout << "Dati numarul de stele: ";
  146. cin >> stele;
  147. cout << "Dati daca are piscina[0/1]: ";
  148. cin >> piscina;
  149. cout << "Dati daca are sauna[0/1]: ";
  150. cin >> sauna;
  151. h = new hotel(1, nume, pret, tenis, stele, piscina, sauna);
  152. //apelare constructor info citite
  153. p = h;//cast pt clasa de baza
  154. l.adaugare(p);//se adauga nodul
  155. }
  156. else if (x == 2)//daca e pensiune
  157. {
  158. pensiune *pen;
  159. cout << "Dati nr de margarete: ";
  160. cin >> margarete;
  161. cout << "Dati daca are gradina: ";
  162. cin >> gradina;
  163. pen = new pensiune(2, nume, pret, tenis, margarete, gradina);
  164. p = pen;
  165. l.adaugare(p);
  166. }
  167. }
  168.  
  169. void Lista::stergere(string nume)
  170. {
  171. agentie *p;
  172. agentie *aux;
  173. p = head;
  174. if (p == NULL)
  175. cout << "e nula";
  176. else
  177. {
  178. if (head->nume.compare( nume) == 0)
  179. {
  180. aux = head;
  181. head = head->urm;
  182. free(aux);
  183. }
  184. else
  185. {
  186. while (p->urm && (p->urm->nume.compare(nume) != 0))
  187. p = p->urm;
  188. aux = p->urm;
  189. p->urm = p->urm->urm;
  190. free(aux);
  191. }
  192. }
  193. }
  194.  
  195. void Lista::oferta_avantajoasa()
  196. {
  197. int min = 99, oferta;
  198. string nume;
  199. agentie *p;
  200. hotel *h;
  201. pensiune *pen;
  202. p = head;
  203. while (p)
  204. {
  205. if (p->tip == 1)
  206. {
  207. h = (hotel *)p;
  208. oferta = (h->stele)*(h->pret);
  209. }
  210. else if (p->tip == 2)
  211. {
  212. pen = (pensiune *)p;
  213. oferta = (pen->margarete)*(pen->pret);
  214. }
  215. if (oferta < min)
  216. {
  217. min = oferta;
  218. (nume.compare( p->nume));
  219. }
  220. p = p->urm;
  221. }
  222. cout << "Oferta minima este: " << min << " a agentiei " << nume << endl;
  223.  
  224. }
  225.  
  226. int main()
  227. {
  228. int opt;
  229. Lista l;
  230. l.head = NULL;
  231. do
  232. {
  233. //system("CLS");
  234. cout << "\n\n";
  235. cout << "1.Ad. oferta hotel \n";
  236. cout << "2.Ad. oferta pensiune \n";
  237. cout << "3.Afis oferte \n";
  238. cout << "4.Stergere oferta \n";
  239. cout << "5.Afisare oferta cea mai avantajoasa \n";
  240. cout << "0.Iesire \n";
  241. cout << "Dati optiunea dvs: ";
  242. cin >> opt;
  243. switch (opt)
  244. {
  245. case 1:
  246. introducere(l, 1);
  247. break;
  248. case 2:
  249. introducere(l, 2);
  250. break;
  251. case 3:
  252. l.afisare_lista();
  253. break;
  254. case 4:
  255. char nume[20];
  256. cout << "ntrod numele dupa care se sterge: ";
  257. cin >> nume;
  258. l.stergere(nume);
  259. break;
  260. case 5:
  261. l.oferta_avantajoasa();
  262. break;
  263. case 0:
  264. break;
  265.  
  266. }
  267. } while (opt != 0);
  268. _getch();
  269. return 0;
  270. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement