Advertisement
Alx09

on

Feb 26th, 2022
978
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.01 KB | None | 0 0
  1. /*Cautarea unui teren extravilan dupa tipul de sol*/
  2. #include <iostream>
  3. #include <list>
  4. #include <iterator>
  5. #include <string>
  6. using namespace std;
  7. class Lista;
  8. class teren
  9. {
  10. private:
  11.     string forma;
  12.     int pret, tip, suprafata;
  13. public:
  14.     teren(string forma, int pret, int supr, int tip)
  15.     {
  16.         this->pret = pret;
  17.         this->forma = forma;
  18.         this->tip = tip;
  19.         this->suprafata = supr;
  20.     }
  21.     virtual void afisare()
  22.     {
  23.         cout << "Forma= " << forma << endl;
  24.         cout << "Pretul= " << pret << endl;
  25.         cout << "Tip= " << tip << endl;
  26.         cout << "Suprafata= " << suprafata << endl;
  27.     }
  28.     friend void cautare(list<teren*>);
  29. };
  30.  
  31. list<teren*>::iterator it;
  32. class intravilan :public teren
  33. {
  34. private:
  35.     string acces;
  36.     int tip;
  37. public:
  38.     intravilan(string forma, int pret, int supr, string acces, int tip) :teren(forma, pret, supr, tip)
  39.     {
  40.         this->acces = acces;
  41.         this->tip = tip;
  42.     }
  43.     void afisare()
  44.     {
  45.         teren::afisare();
  46.         cout << "Tip acces= " << acces << endl;
  47.     }
  48. };
  49. class extravilan :public teren
  50. {
  51. private:
  52.     string tips;
  53.     int tip;
  54. public:
  55.     extravilan(string forma, int pret, int supr, string tips, int tip) : teren(forma, pret, supr, tip)
  56.     {
  57.         this->tips = tips;
  58.         this->tip = tip;
  59.     }
  60.     void afisare()
  61.     {
  62.         teren::afisare();
  63.         cout << "Tip Sol= " << tips << endl;
  64.     }
  65. };
  66. void adaugare(list<teren*>& t, int tip)
  67. {
  68.     string forma, acces, tips;
  69.     int pret, supr;
  70.     cout << "Introduceti forma-> ";
  71.     cin >> forma;
  72.     cout << "Introduceti suprafata-> ";
  73.     cin >> supr;
  74.     cout << "Introduceti pretul-> ";
  75.     cin >> pret;
  76.     if (tip == 1)
  77.     {
  78.         cout << "Are acces la strada?[DA/NU]-> ";
  79.         cin >> acces;
  80.         t.push_back(new intravilan(forma, pret, supr, acces, 1));
  81.     }
  82.     if (tip == 2)
  83.     {
  84.         cout << "Tipul Solului-> ";
  85.         cin >> tips;
  86.         t.push_back(new extravilan(forma, pret, supr, tips, 2));
  87.     }
  88. }
  89. void afisare(list<teren*>t)
  90. {
  91.     for (it = t.begin(); it != t.end(); it++)
  92.     {
  93.         cout << "-----";
  94.         (*it)->afisare();
  95.         cout << "------" << endl;
  96.     }
  97. }
  98. void cautare(list<teren*>t)
  99. {
  100.     int sol;
  101.     cout << "Introduceti tipul de sol-> ";
  102.     cin >> sol;
  103.  
  104.     for (it = t.begin(); it != t.end(); it++)
  105.     {
  106.         teren* ter = (*it);
  107.         if (ter->tip == sol)
  108.         {
  109.             (*it)->afisare();
  110.         }
  111.     }
  112. }
  113. int main()
  114. {
  115.     list<teren*> teren;
  116.     int opt;
  117.     do
  118.     {
  119.         cout << "1.Adaugare teren intravilan (tip=1)" << endl;
  120.         cout << "2.Adaugare teren extravilan (tip=2)" << endl;
  121.         cout << "3.Afisare terenuri" << endl;
  122.         cout << "4.Cautare dupa tip de sol" << endl;
  123.         cout << "5.Iesire" << endl;
  124.         cout << "Alegerea D-stra-> ";
  125.         cin >> opt;
  126.         switch (opt)
  127.         {
  128.         case 1:
  129.             system("cls");
  130.             adaugare(teren, 1);
  131.             system("pause");
  132.             system("cls");
  133.             break;
  134.         case 2:
  135.             system("cls");
  136.             adaugare(teren, 2);
  137.             system("pause");
  138.             system("cls");
  139.             break;
  140.         case 3:
  141.             system("cls");
  142.             afisare(teren);
  143.             system("pause");
  144.             system("cls");
  145.             break;
  146.         case 4:
  147.             system("cls");
  148.             cautare(teren);
  149.             system("pause");
  150.             system("cls");
  151.             break;
  152.         case 5:
  153.             exit(0);
  154.             break;
  155.         default:
  156.             break;
  157.         }
  158.     } while (opt != 5);
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement