Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Rekord
- {
- protected:
- string nazwa;
- public:
- Rekord(string tytul) : nazwa(tytul) {}
- virtual void wypisz() = 0; // metoda czysto wirtualna
- };
- class film : public Rekord // public Rekord informuje kompilator, że klasa ta dziedziczy od klasy Rekord (jest jej klasą pochodną)
- {
- string rezyser, gatunek;
- int rok_produkcji;
- public:
- film(string director, string tytul, string rodzaj, int rok) : Rekord(tytul), rezyser(director), gatunek(rodzaj), rok_produkcji(rok) {}
- void wypisz()
- {
- cout << "Film o tytule " << nazwa << " (" << gatunek << ") z roku " << rok_produkcji << ", wyrezyserowany przez " << rezyser << endl;
- }
- };
- class czasopismo : public Rekord
- {
- int numer;
- public:
- czasopismo(int number, string tytul) : Rekord(tytul), numer(number) {}
- void wypisz()
- {
- cout << "Czasopismo o nazwie " << nazwa << ", nr " << numer << endl;
- }
- };
- class ksiazka : public Rekord
- {
- string wydawnictwo, autor, miasto_wydania;
- int ilosc_stron, rok_wydania;
- public:
- ksiazka(string publisher, string writer, string city, string tytul, int pages, int year) : Rekord(tytul), wydawnictwo(publisher), autor(writer), miasto_wydania(city), ilosc_stron(pages), rok_wydania(year) {}
- void wypisz()
- {
- cout << "Ksiazka o tytule " << nazwa << " autorstwa " << autor << ", " << miasto_wydania << ' ' << rok_wydania << " (" << wydawnictwo << ") liczba stron: " << ilosc_stron << endl;
- }
- };
- int main()
- {
- film film1("Robert Zemeckis", "Forrest Gump", "komediodramat", 1994);
- film1.wypisz();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement