Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <sstream>
- #include <typeinfo>
- #include <assert.h>
- #include <time.h>
- using namespace std;
- class Pies;
- class Czlowiek;
- enum Plec {
- PIES,
- SUKA
- };
- enum Plec_czlowieka {
- MEZCZYZNA,
- KOBIETA
- };
- class Miska {
- private:
- int porcja;
- public:
- Miska& operator()(int porcja) {
- this->porcja = porcja;
- return *this;
- }
- int dajPorcja() {
- return porcja;
- }
- };
- class FunkcjeZyciowe {
- public:
- virtual void jedz(int iloscPozywienia) = 0;
- virtual void pij(int iloscWody) = 0;
- virtual void spij(int czas) = 0;
- virtual void bawSie(int czas) = 0;
- };
- class Zwierze {
- private:
- string mImie;
- protected:
- int glod = 0;
- int pragnienie = 0;
- int zmeczenie = 0;
- int humor = 0;
- public:
- Zwierze() {
- }
- Zwierze(string imie) {
- mImie = imie;
- }
- friend ostream& operator << (ostream & ss, Zwierze& z);
- string dajImie() const {
- return mImie;
- }
- void ustawImie(string imie) {
- mImie = imie;
- }
- const string naLancuch() const {
- stringstream ss;
- ss << dajRodzajZwierzecia() << " " << mImie
- << ", glod: " << glod
- << ", pragnienie: " << pragnienie
- << ", zmeczenie: " << zmeczenie;
- return ss.str();
- }
- virtual string dajRodzajZwierzecia() const {
- return "Zwierzatko: ";
- }
- };
- class Pies: public Zwierze, public FunkcjeZyciowe {
- private:
- Plec plec;
- public:
- Pies(string imie = "") : Zwierze(imie) {
- }
- Pies(string imie, Plec plec_psa) : Zwierze(imie) {
- plec = plec_psa;
- }
- Plec dajPlec() {
- return plec;
- }
- void ustawPlec(Plec new_plec) {
- plec = new_plec;
- }
- void szczekaj() {
- cout << naLancuch() << ": Hau hau mister frau" << endl;
- }
- void dajLape() {
- cout << naLancuch() << " daje lape" << endl;
- }
- string dajRodzajZwierzecia() const {
- return "Pies: ";
- }
- const string naLancuch() const {
- stringstream ss;
- ss << dajRodzajZwierzecia() << dajImie()
- << ", glod: " << glod
- << ", pragnienie: " << pragnienie
- << ", zmeczenie: " << zmeczenie
- << ", plec: " << (plec == 0 ? "PIES" : "SUKA");
- return ss.str();
- }
- void jedz(int iloscPozywienia) {
- glod -= 10 * iloscPozywienia;
- zmeczenie -= 5 * iloscPozywienia;
- }
- void pij(int iloscWody) {
- pragnienie -= 15 * iloscWody;
- zmeczenie -= 8 * iloscWody;
- }
- void spij(int czas) {
- zmeczenie -= 14 * czas;
- }
- void bawSie(int czas) {
- pragnienie += 5 * czas;
- zmeczenie += 7 * czas;
- glod += 12 * czas;
- humor += 40 * czas;
- }
- string generujImie(string imie1, string imie2) {
- string new_imie;
- int chars_from_imie = rand() % imie1.length();
- new_imie = imie1.substr(0, chars_from_imie);
- chars_from_imie = rand() % imie2.length();
- new_imie += imie2.substr(0, chars_from_imie);
- new_imie[0] = toupper(new_imie[0]);
- int new_imie_len = new_imie.length();
- for(int i = 1; i < new_imie_len; i++) {
- new_imie[i] = tolower(new_imie[i]);
- }
- return new_imie;
- }
- Plec generujLosowaPlec() {
- Plec plec = (Plec)(rand() % 2);
- return plec;
- }
- Pies operator +(Pies& p2) {
- assert(dajPlec() != p2.dajPlec());
- Pies new_p;
- string noweImie = generujImie(dajImie(), p2.dajImie());
- new_p.ustawImie(noweImie);
- Plec new_plec = generujLosowaPlec();
- new_p.ustawPlec(new_plec);
- return new_p;
- }
- void operator <<(Miska& miska) {
- glod -= miska.dajPorcja();
- miska(0);
- }
- };
- ostream& operator <<(ostream & ss, Zwierze& z) {
- ss << z.dajRodzajZwierzecia() << " " << z.mImie
- << ", glod: " << z.glod
- << ", pragnienie: " << z.pragnienie
- << ", zmeczenie: " << z.zmeczenie;
- return ss;
- }
- class Kot: public Zwierze, public FunkcjeZyciowe {
- public:
- Kot(string imie) : Zwierze(imie) {
- }
- void miaucz() {
- cout << dajImie() << " " << " miaaaaaauuuuu" << endl;
- }
- void myjSie() {
- cout << dajImie() << " " << " robi myju myju" << endl;
- }
- string dajRodzajZwierzecia() const {
- return "Kot: ";
- }
- void jedz(int iloscPozywienia) {
- glod -= 7 * iloscPozywienia;
- }
- void pij(int iloscWody) {
- pragnienie -= 8 * iloscWody;
- }
- void spij(int czas) {
- zmeczenie -= 6 * czas;
- }
- void bawSie(int czas) {
- pragnienie += 17 * czas;
- zmeczenie += 6 * czas;
- glod += 11 * czas;
- humor += 33 * czas;
- }
- };
- class SchroniskoDlaZwierzat {
- private:
- Zwierze* zwierzeta[100];
- public:
- SchroniskoDlaZwierzat() {
- }
- void dodajZwierze(Zwierze* z, int numer) {
- zwierzeta[numer] = z;
- }
- Zwierze* dajZwierze(int numer) {
- return zwierzeta[numer];
- }
- };
- class Czlowiek
- {
- private:
- string imie;
- Plec_czlowieka plec;
- int wiek;
- public:
- Czlowiek(string imie2, int wiek2, Plec_czlowieka plec2)
- {
- imie = imie2;
- wiek = wiek2;
- plec = plec2;
- }
- const string wyswietlDane() const
- {
- stringstream napis;
- napis << endl << "IMIE: " << imie << endl << "PLEC: " << (plec == 0 ? "MEZCZYZNA" : "KOBIETA")
- << endl << "WIEK: " << wiek << endl;
- return napis.str();
- }
- };
- int main()
- {
- /*
- srand (time(NULL));
- Pies p1("Stefan", PIES);
- Pies p2("Zosiaa", SUKA);
- cout << p1.naLancuch() << endl;
- cout << p2.naLancuch() << endl;
- Pies p3 = p1 + p2;
- cout << p3.naLancuch() << endl;
- Pies p4 = p2 + p3;
- cout << p4.naLancuch() << endl;
- */
- Pies p1("Stefan", PIES);
- Miska miska;
- cout << p1.naLancuch() << endl;
- //miska(100);
- p1 << miska(200);
- cout << p1.naLancuch() << endl;
- //miska(250);
- //p1 << miska;
- //cout << p1.naLancuch() << endl;
- cout << "Porcja w misce: " << miska.dajPorcja() << endl;
- cout << p1;
- Czlowiek czlowiek1("Janusz",33,MEZCZYZNA);
- cout << czlowiek1.wyswietlDane();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement