Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // zadanieady.cpp: definiuje punkt wejścia dla aplikacji konsolowej.
- //
- #include "stdafx.h"
- #include <iostream>
- class PojazdMechaniczny
- {
- private:
- char* nazwa;
- int wiek;
- public:
- PojazdMechaniczny()
- {
- this->nazwa = (char*)"noname";
- this->wiek = 0;
- }
- PojazdMechaniczny(char* nazwa, int wiek)
- {
- this->nazwa = nazwa;
- this->wiek = wiek;
- }
- char* getNazwa()
- {
- return this->nazwa;
- }
- int getWiek()
- {
- return this->wiek;
- }
- virtual void show() {};
- };
- class Samochod : public PojazdMechaniczny
- {
- private:
- char* kolor;
- int pojemnosc;
- public:
- Samochod(char* nazwa, int wiek, char* kolor, int pojemnosc) : PojazdMechaniczny(nazwa, wiek)
- {
- this->kolor = kolor;
- this->pojemnosc = pojemnosc;
- }
- friend std::ostream&operator <<(std::ostream& out, Samochod& o)
- {
- out << "Nazwa: " << o.getNazwa() << ",\nWiek: " << o.getWiek() << ",\nKolor: " << o.kolor << ",\nPojemnosc: " << o.pojemnosc << "cm^3" << std::endl;
- return out;
- }
- char* getKolor()
- {
- return this->kolor;
- }
- int getPojemnosc()
- {
- return this->pojemnosc;
- }
- void show()
- {
- std::cout << "samochod" << std::endl;
- }
- };
- class Lodz : public PojazdMechaniczny
- {
- private:
- char* typ;
- int wypornosc;
- public:
- Lodz(char* nazwa, int wiek, char* typ, int wypornosc) : PojazdMechaniczny(nazwa, wiek)
- {
- this->typ = typ;
- this->wypornosc = wypornosc;
- }
- Lodz(char* typ, int wypornosc)
- {
- this->typ = typ;
- this->wypornosc = wypornosc;
- }
- friend std::ostream&operator <<(std::ostream& out, Lodz& o)
- {
- out << "Nazwa: " << o.getNazwa() << ",\nWiek: " << o.getWiek() << ",\nTyp: " << o.typ << ",\nWypornosc: " << o.wypornosc << std::endl;
- return out;
- }
- char* getTyp()
- {
- return this->typ;
- }
- int getWypornosc()
- {
- return this->wypornosc;
- }
- void show()
- {
- std::cout << "lodz" << std::endl;
- }
- };
- class Amfibia : public Samochod, Lodz
- {
- public:
- Amfibia(char* nazwa, int wiek, char* kolor, int pojemnosc, char* typ, int wypornosc) : Samochod(nazwa, wiek, kolor, pojemnosc), Lodz(typ, wypornosc)
- {
- }
- friend std::ostream&operator <<(std::ostream& out, Amfibia& o)
- {
- out << "Nazwa: " << static_cast<Samochod>(o).getNazwa() << ",\nWiek: " << static_cast<Samochod>(o).getWiek() << ",\nKolor: " << o.getKolor() << ",\nPojemnosc: " << o.getPojemnosc() << "cm^3,\n" << "Typ: " << o.getTyp() << ",\nWypornosc: " << o.getWypornosc() << std::endl;
- return out;
- }
- void show()
- {
- std::cout << "amfibia" << std::endl;
- }
- };
- class Garaz
- {
- private:
- PojazdMechaniczny* pojazd;
- public:
- Garaz()
- {
- this->pojazd = nullptr;
- }
- PojazdMechaniczny* getPojazd()
- {
- return this->pojazd;
- }
- void zaparkuj_pojazd(PojazdMechaniczny* pojazd)
- {
- if (this->pojazd == nullptr) {
- this->pojazd = pojazd;
- std::cout << "Zaparkowales " << this->pojazd->getNazwa() << std::endl;
- }
- else
- {
- std::cout << "Garaz jest zajety przez" << this->pojazd->getNazwa() << std::endl;
- }
- }
- void wyprowadz_pojazd()
- {
- if (this->pojazd != nullptr)
- {
- this->pojazd = nullptr;
- std::cout << "Garaz zostal zwolniony" << std::endl;
- }
- else
- {
- std::cout << "Garaz jest pusty" << std::endl;
- }
- }
- };
- int main()
- {
- Garaz garaz;
- Samochod* bmw = new Samochod((char*)"BMW", 2017 , (char*)"Czarny", 1597);
- Samochod maluch((char*)"Fiat 126p", 1990, (char*)"Czerwony", 700);
- Lodz l((char*)"lodz", 2000, (char*)"jakis typ", 500);
- Amfibia* a = new Amfibia((char*)"Amfibia", 2018, (char*)"Rozowy", 2000, (char*)"Hybryda", 100);
- std::cout << *bmw << std::endl;
- std::cout << maluch << std::endl;
- std::cout << l << std::endl;
- std::cout << *a << std::endl;
- if(garaz.getPojazd() != nullptr)
- garaz.getPojazd()->show();
- garaz.zaparkuj_pojazd(bmw);
- garaz.getPojazd()->show();
- garaz.zaparkuj_pojazd(&maluch);
- garaz.wyprowadz_pojazd();
- garaz.zaparkuj_pojazd(&maluch);
- garaz.getPojazd()->show();
- garaz.wyprowadz_pojazd();
- garaz.zaparkuj_pojazd(static_cast<PojazdMechaniczny*>(static_cast<Samochod*>(a)));
- delete bmw;
- delete a;
- char c;
- std::cin >> c;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement