Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <iomanip>
- namespace Zwierzaki {
- using std::string;
- class Pupil {
- public:
- int wiek;
- virtual void foo() = 0;
- Pupil(int wiek){
- this -> wiek = wiek;
- }
- };
- class Ssak {
- public:
- string imie;
- string gatunek;
- int l_nog;
- bool siersc;
- int idKlasy;
- void Save( std::ostream& ) const;
- Ssak(string imie, string gatunek, int l_nog, bool siersc, int idKlasy) {
- this->imie = imie;
- this->gatunek = gatunek;
- this->l_nog = l_nog;
- this->siersc = siersc;
- this->idKlasy = idKlasy;
- }
- int getId(){
- return idKlasy;
- }
- friend std::ostream& operator << (std::ostream& out, Zwierzaki::Ssak & s);
- };
- class Kot : public Ssak {
- protected:
- int l_wasow;
- public:
- Kot(string imie, string gatunek, int l_nog, bool siersc,int l_wasow, int idKlasy) : Ssak(imie, gatunek, l_nog, siersc, idKlasy) {
- this->l_wasow = l_wasow;
- }
- int getWasy(){
- return l_wasow;
- }
- friend std::ostream& operator << (std::ostream& out, Zwierzaki::Kot & k);
- };
- class Pies : public Ssak, public Pupil {
- protected:
- int glosnosc;
- bool czyszczeka;
- public:
- virtual void foo() {}
- Pies(string imie, string gatunek, int l_nog, bool siersc, int glosnosc, bool czyszczeka, int wiek, int idKlasy) : Ssak(imie, gatunek, l_nog, siersc, idKlasy), Pupil(wiek) {
- this->glosnosc = glosnosc;
- this->czyszczeka = czyszczeka;
- }
- int getGlosnosc(){
- return glosnosc;
- }
- int setGlosnosc(int a){
- this -> glosnosc = glosnosc + (glosnosc * a /100);
- }
- int getId(){
- return idKlasy;
- }
- friend std::ostream& operator << (std::ostream& out, Zwierzaki::Pies & p);
- };
- std::ostream& operator << (std::ostream& out, Zwierzaki::Ssak & s)
- {
- out << std::endl << "Dane ssaków: " << std::endl;
- if(s.getId()==1){
- out << static_cast<Pies&>(s);
- }
- else if(s.getId()==2)
- out << static_cast<Kot&>(s);
- return out;
- }
- std::ostream& operator << (std::ostream& out, Zwierzaki::Pies & p) {
- out << std::endl << "Dane psa: " << std::endl;
- out << "Imie: " << p.imie << std::endl;
- out << "Gatunek: " << p.gatunek << std::endl;
- out << "Liczba nog: " << p.l_nog << std::endl;
- out << "Siersc: " << p.siersc << std::endl;
- out << "Glosnosc: " << p.glosnosc << std::endl;
- out << "Szczeka: " << p.czyszczeka << std::endl;
- out << "Wiek: " << p.wiek << std::endl;
- return out;
- }
- std::ostream& operator << (std::ostream& out, Zwierzaki::Kot & k) {
- out << std::endl << "Dane kota: " << std::endl;
- out << "Imie: " << k.imie << std::endl;
- out << "Gatunek: " << k.gatunek << std::endl;
- out << "Liczba nog: " << k.l_nog << std::endl;
- out << "Siersc: " << k.siersc << std::endl;
- out << "Liczba wasow: " << k.l_wasow << std::endl;
- return out;
- }
- }
- class Zoo
- {
- private:
- std::string nazwa;
- Zwierzaki::Ssak **listaSsakow = new Zwierzaki::Ssak*[100];
- Zwierzaki::Ssak **listaId = new Zwierzaki::Ssak*[100];
- int liczbaSsakow;
- public:
- Zoo(std::string nazwa) {
- this->nazwa = nazwa;
- liczbaSsakow = 0;
- }
- void dodajSsaka(Zwierzaki::Ssak *s) {
- listaSsakow[liczbaSsakow] = s;
- liczbaSsakow++;
- }
- void znajdzSsaka(std::string imie) {
- int i;
- for (i = 0; i < liczbaSsakow; i++)
- {
- if (imie == listaSsakow[i]->imie)
- {
- std::cout << "Znaleziono " << imie << " pod numerem " << i + 1 << std::endl;
- break;
- }
- }
- std::cout << "Nie znaleziono " << imie << std::endl;
- }
- friend std::ostream& operator << (std::ostream& out, Zoo & z) {
- int i;
- out << z.nazwa << std::endl;
- for (i = 0; i < z.liczbaSsakow; i++) {
- out << *z.listaSsakow[i] << std::endl;
- }
- return out;
- }
- int getLiczbaSsakow(){
- return liczbaSsakow;
- }
- };
- int main()
- {
- Zwierzaki::Kot k1("Robert", "Maklowicz", 3, true, 3, 2);
- Zwierzaki::Pies p1("Wojciech", "Cejrowski", 3, true, 12, true, 1, 1);
- Zoo z("Rychu Peja");
- z.dodajSsaka(&k1);
- z.dodajSsaka(&p1);
- std::cout<<z<<std::endl;
- z.znajdzSsaka("Rob1ert");
- std::cout << k1.getWasy() << std::endl;
- int procent;
- std::cout << "podaj procent" << std::endl;
- std::cin >> procent;
- std::cout << "glosnosc przed: " << p1.getGlosnosc() << std::endl;
- p1.setGlosnosc(procent);
- std::cout << "glosnosc po: " << p1.getGlosnosc() << std::endl;
- std::string filename = "ssaki.txt";
- std::fstream file;
- file.open(filename.c_str());
- if (!file)
- std::cerr << "Blad";
- else
- file << z;
- file.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement