VEndymionV

Untitled

Jan 22nd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.04 KB | None | 0 0
  1. // obiektowka z podzialem na klasy.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "stdafx.h"
  6. #include <iostream>
  7. #include <vector>
  8. #include <string>
  9. #include "Testov.h"
  10. #include "Animal.h"
  11. #include "Dog.h"
  12. #include <iterator>
  13. #include "Cat.h"
  14. #include "Fish.h"
  15. #include "Dogerror.h"
  16. #include "Testdog.h"
  17. #include "wyborerror.h"
  18. #include "Caterror.h"
  19. #include "Fisherror.h"
  20. #include <algorithm>
  21. using namespace std;
  22.  
  23. string imie_szukane;
  24.  
  25. bool sortow(Animal* first, Animal* second)
  26. {
  27.     return (first->wzrost < second->wzrost);
  28. }
  29. Animal * second;
  30.  
  31. bool searchmy(Animal* first)
  32. {
  33.     return (first->imie == imie_szukane);
  34. }
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41. void DajGlos(Animal * x)
  42. {
  43.     x->sound();
  44. }
  45.  
  46. int main()
  47. {
  48.     vector <Animal*>tab;
  49.     vector <int>::iterator it;
  50.     int i = 0;
  51.     //Zwierze* tab[10];
  52.     Animal* wsk;
  53.  
  54.    
  55.  
  56.  
  57.     int wybor;
  58.     int temp = 0;
  59.     for (;;)
  60.     {
  61.         system("cls");
  62.         cout << "0.Wyswietl\n1.Dodaj Psa\n2.Dodaj Kota\n3.Dodaj Rybke\n4.Sortowanie po wzroscie\n5.Wyszukiwanie\n6.Polimorfiz\n9.Wyjscie" << endl;
  63.         cout << " Schemat dodawania: Imie [ENTER], wzrost [ ENTER]" << endl;
  64.         cin >> wybor;
  65.         try
  66.         {
  67.             if (wybor < 0 || (wybor > 5 && wybor != 9)) throw wyborerror("Niepoprawwna wartosc!");
  68.         }
  69.         catch (wyborerror &p)
  70.         {
  71.             cout << p.Geterror() << endl;
  72.             system("PAUSE");
  73.             continue;
  74.         }
  75.  
  76.         if (wybor == 0)
  77.         {
  78.             for (int i = 0; i < tab.size(); i++)
  79.             {
  80.                 cout << tab[i]->imie << " " << tab[i]->rasa << " " << tab[i]->wzrost << endl;
  81.  
  82.             }
  83.             system("PAUSE");
  84.         }
  85.         if (wybor == 1)
  86.         {
  87.             cout << "Wstawianie psa" << endl;
  88.             wsk = new Dog();
  89.  
  90.             try
  91.             {
  92.                 if (wsk->rasa != "Pies")throw Dogerror("Blad konsktruktora");
  93.             }
  94.             catch (Dogerror &d)
  95.             {
  96.                 cout << d.Geterror() << endl;
  97.                 system("PAUSE");
  98.                 continue;
  99.             }
  100.             tab.push_back(wsk);
  101.         }
  102.         if (wybor == 2)
  103.         {
  104.             wsk = new Cat();
  105.             try
  106.             {
  107.                 if (wsk->rasa != "Kot")throw Caterror("Blad konsktruktora");
  108.             }
  109.             catch (Caterror &g)
  110.             {
  111.                 cout << g.Geterror() << endl;
  112.                 system("PAUSE");
  113.                 continue;
  114.             }
  115.             tab.push_back(wsk);
  116.         }
  117.         if (wybor == 3)
  118.         {
  119.             wsk = new Fish();
  120.             try
  121.             {
  122.                 if (wsk->rasa != "Ryba")throw Fisherror("Blad konsktruktora");
  123.             }
  124.             catch (Dogerror &g)
  125.             {
  126.                 cout << g.Geterror() << endl;
  127.                 system("PAUSE");
  128.                 tab.push_back(wsk);
  129.  
  130.             }
  131.         }
  132.         if (wybor == 4)
  133.             {
  134.  
  135.  
  136.                 sort(tab.begin(), tab.end(), sortow);
  137.                 continue;
  138.  
  139.             }
  140.         if (wybor == 9)
  141.             {
  142.                 return 0;
  143.             }
  144.        
  145.         if (wybor == 5)
  146.         {
  147.  
  148.             cout << "Podaj szukane imie" << endl;
  149.             cin >> imie_szukane;
  150.  
  151.  
  152.             vector <Animal*>::iterator it = find_if(tab.begin(), tab.end(), searchmy);
  153.  
  154.             if (it == tab.end())
  155.                 cout << "Animal not found.\n";
  156.  
  157.             else
  158.             {
  159.                 cout << "Animal found:\n";
  160.             }
  161.  
  162.            
  163.  
  164.         }
  165.  
  166.  
  167.         if (wybor == 6)
  168.         {
  169.             //polimorfizm
  170.             Dog x;
  171.             Cat y;
  172.             wsk = &x;
  173.             DajGlos(wsk);
  174.             tab.push_back(wsk);
  175.  
  176.             wsk = &y;
  177.             DajGlos(wsk);
  178.             tab.push_back(wsk);
  179.  
  180.         }
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.         }
  196.  
  197.  
  198.  
  199.    
  200.  
  201.  
  202.     }
Advertisement
Add Comment
Please, Sign In to add comment