Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // obiektowka z podzialem na klasy.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include "stdafx.h"
- #include <iostream>
- #include <vector>
- #include <string>
- #include "Testov.h"
- #include "Animal.h"
- #include "Dog.h"
- #include <iterator>
- #include "Cat.h"
- #include "Fish.h"
- #include "Dogerror.h"
- #include "Testdog.h"
- #include "wyborerror.h"
- #include "Caterror.h"
- #include "Fisherror.h"
- #include <algorithm>
- using namespace std;
- string imie_szukane;
- bool sortow(Animal* first, Animal* second)
- {
- return (first->wzrost < second->wzrost);
- }
- Animal * second;
- bool searchmy(Animal* first)
- {
- return (first->imie == imie_szukane);
- }
- void DajGlos(Animal * x)
- {
- x->sound();
- }
- int main()
- {
- vector <Animal*>tab;
- vector <int>::iterator it;
- int i = 0;
- //Zwierze* tab[10];
- Animal* wsk;
- int wybor;
- int temp = 0;
- for (;;)
- {
- system("cls");
- cout << "0.Wyswietl\n1.Dodaj Psa\n2.Dodaj Kota\n3.Dodaj Rybke\n4.Sortowanie po wzroscie\n5.Wyszukiwanie\n6.Polimorfiz\n9.Wyjscie" << endl;
- cout << " Schemat dodawania: Imie [ENTER], wzrost [ ENTER]" << endl;
- cin >> wybor;
- try
- {
- if (wybor < 0 || (wybor > 5 && wybor != 9)) throw wyborerror("Niepoprawwna wartosc!");
- }
- catch (wyborerror &p)
- {
- cout << p.Geterror() << endl;
- system("PAUSE");
- continue;
- }
- if (wybor == 0)
- {
- for (int i = 0; i < tab.size(); i++)
- {
- cout << tab[i]->imie << " " << tab[i]->rasa << " " << tab[i]->wzrost << endl;
- }
- system("PAUSE");
- }
- if (wybor == 1)
- {
- cout << "Wstawianie psa" << endl;
- wsk = new Dog();
- try
- {
- if (wsk->rasa != "Pies")throw Dogerror("Blad konsktruktora");
- }
- catch (Dogerror &d)
- {
- cout << d.Geterror() << endl;
- system("PAUSE");
- continue;
- }
- tab.push_back(wsk);
- }
- if (wybor == 2)
- {
- wsk = new Cat();
- try
- {
- if (wsk->rasa != "Kot")throw Caterror("Blad konsktruktora");
- }
- catch (Caterror &g)
- {
- cout << g.Geterror() << endl;
- system("PAUSE");
- continue;
- }
- tab.push_back(wsk);
- }
- if (wybor == 3)
- {
- wsk = new Fish();
- try
- {
- if (wsk->rasa != "Ryba")throw Fisherror("Blad konsktruktora");
- }
- catch (Dogerror &g)
- {
- cout << g.Geterror() << endl;
- system("PAUSE");
- tab.push_back(wsk);
- }
- }
- if (wybor == 4)
- {
- sort(tab.begin(), tab.end(), sortow);
- continue;
- }
- if (wybor == 9)
- {
- return 0;
- }
- if (wybor == 5)
- {
- cout << "Podaj szukane imie" << endl;
- cin >> imie_szukane;
- vector <Animal*>::iterator it = find_if(tab.begin(), tab.end(), searchmy);
- if (it == tab.end())
- cout << "Animal not found.\n";
- else
- {
- cout << "Animal found:\n";
- //cout << (*it)->IMIE << endl;
- //IMIE to funkcja która daje Ci imię czy co tam chcesz wyświetlić
- }
- }
- if (wybor == 6)
- {
- //polimorfizm
- Dog x;
- Cat y;
- wsk = &x;
- DajGlos(wsk);
- tab.push_back(wsk);
- wsk = &y;
- DajGlos(wsk);
- tab.push_back(wsk);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment