Advertisement
Skylighty

lab11_pg

Jan 16th, 2019
470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.31 KB | None | 0 0
  1. //------------PAWEŁ GĄSIEWSKI---------
  2. //------------Laboratorium 11---------
  3. #include <iostream>
  4. #include <cstdlib>
  5. #include <ctime>
  6. #include <vector>
  7. #include <queue>
  8. #include <stack>
  9. #include <list>
  10. using namespace std;
  11.  
  12.  
  13. class produkt {
  14. private:
  15.     int cena;
  16. public:
  17.     produkt();
  18.     int return_cena();
  19. };
  20. produkt::produkt() {
  21.     cena = (rand() % 100) + 1;
  22.     cout << "p o cenie : " << cena << endl;
  23. }
  24. int produkt::return_cena() {
  25.     return cena;
  26. }
  27.  
  28. class pojemnik {
  29. public:
  30.     vector <produkt> wektor;
  31.     queue <produkt> kolejka;
  32.     stack <produkt> stos;
  33.     list <produkt> lista;
  34.     void v_add(produkt *p);
  35.     void show();
  36. };
  37. void pojemnik::v_add(produkt *p) { //Metoda dodajaca obiekty na koniec wektora
  38.     wektor.push_back(*p);
  39.     cout << "Dodaje do wektora w pojemniku obiekt o cenie : " << p->return_cena() << endl;
  40. }
  41. void pojemnik::show() { //Metoda wyswietlajaca ceny produktow zaczynajac od poczatku wektora
  42.     for (auto i = wektor.begin(); i != wektor.end(); ++i)
  43.     {
  44.         cout << "Wyswietlam element wektora w pojemniku o cenie : " << i->return_cena() << endl;
  45.     }
  46. }
  47.  
  48. int main() {
  49.     vector <produkt> myvector;
  50.     queue <produkt> myqueue;
  51.     stack <produkt> mystack;
  52.     list <produkt> mylist;
  53.     for (int i = 0; i < 10; i++)
  54.     {
  55.         produkt *np = new produkt();
  56.         myvector.push_back(*np);
  57.     }
  58.     for (auto i = myvector.begin(); i < myvector.end(); ++i)
  59.     {
  60.         cout << "Wyswietlam produkt o cenie : " << i->return_cena() << endl;
  61.     }
  62.     if (!myvector.empty())
  63.         cout << "Wektor nie jest pusty i ma w sobie : " << myvector.size() << " elementow." << endl;
  64.     else
  65.         cout << "Wektor jest pusty." << endl;
  66.     myvector.erase(myvector.begin() + 4); //5 element od poczatku vectora, bo nie znamy iteracji
  67.     cout << "Wyswietlam wektor po usunieciu elementu 5 od poczatku: " << endl;
  68.     for (auto i = myvector.begin(); i < myvector.end(); ++i)
  69.     {
  70.         cout << "Wyswietlam produkt o cenie : " << i->return_cena() << endl;
  71.     }
  72.     for (int i = 0; i < 10; i++)
  73.     {
  74.         produkt *np = new produkt();
  75.         myqueue.push(*np);
  76.     }
  77.     while (!myqueue.empty())
  78.     {
  79.         cout << "Wyswietlam element kolejki o cenie : " << myqueue.front().return_cena() << endl;
  80.         myqueue.pop();
  81.     }
  82.     if (myqueue.empty())
  83.         cout << "Kolejka jest teraz pusta" << endl;
  84.     for (int i = 0; i < 10; i++)
  85.     {
  86.         produkt *np = new produkt();
  87.         mystack.push(*np);
  88.     }
  89.     cout << endl;
  90.     while (!mystack.empty())
  91.     {
  92.         cout << "Wyswietlam element stosu o cenie : " << mystack.top().return_cena() << endl;
  93.         mystack.pop();
  94.     }
  95.     cout << endl;
  96.     if (mystack.empty())
  97.         cout << "Stos jest teraz pusty." << endl;
  98.     cout << endl;
  99.     pojemnik *p = new pojemnik();
  100.     for (int i = 0; i < 20; i++)
  101.     {
  102.         produkt *np = new produkt();
  103.         p->wektor.push_back(*np);
  104.     }
  105.     for (auto i = p->wektor.begin(); i != p->wektor.end(); ++i)
  106.     {
  107.         cout << "Wyswietlam produkt w pojemniku p o cenie : " << i->return_cena() << endl;
  108.     }
  109.     cout << endl;
  110.     cout << "Czyszcze wektor : " << endl;
  111.     myvector.clear();
  112.     if (myvector.empty())
  113.         cout << "Moj wektor jest teraz pusty." << endl;
  114.     cout << endl;
  115.     pojemnik *cube = new pojemnik();
  116.     cout << "Tworze nowy pojemnik o nazwie cube " << endl;
  117.     for (int i = 0; i < 10; i++)
  118.     {
  119.         produkt *np = new produkt();
  120.         cube->v_add(np);
  121.     }
  122.     cout << endl;
  123.     cout << "Teraz wyswietle wektor znajdujacy sie w pojemniku cube : " << endl;
  124.     cube->show();
  125.     cout << endl;
  126.     system("pause");
  127.     return 0;
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement