Advertisement
MeehoweCK

Untitled

Jan 7th, 2021
674
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.66 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Rekord
  6. {
  7. protected:
  8.     string nazwa;
  9. public:
  10.     Rekord(string tytul) : nazwa(tytul) {}
  11.     virtual void wypisz() = 0;          // metoda czysto wirtualna
  12. };
  13.  
  14. class film : public Rekord      // public Rekord informuje kompilator, że klasa ta dziedziczy od klasy Rekord (jest jej klasą pochodną)
  15. {
  16.     string rezyser, gatunek;
  17.     int rok_produkcji;
  18. public:
  19.     film(string director, string tytul, string rodzaj, int rok) : Rekord(tytul), rezyser(director), gatunek(rodzaj), rok_produkcji(rok) {}
  20.     void wypisz()
  21.     {
  22.         cout << "Film o tytule " << nazwa << " (" << gatunek << ") z roku " << rok_produkcji << ", wyrezyserowany przez " << rezyser << endl;
  23.     }
  24. };
  25.  
  26. class czasopismo : public Rekord
  27. {
  28.     int numer;
  29. public:
  30.     czasopismo(int number, string tytul) : Rekord(tytul), numer(number) {}
  31.     void wypisz()
  32.     {
  33.         cout << "Czasopismo o nazwie " << nazwa << ", nr " << numer << endl;
  34.     }
  35. };
  36.  
  37. class ksiazka : public Rekord
  38. {
  39.     string wydawnictwo, autor, miasto_wydania;
  40.     int ilosc_stron, rok_wydania;
  41. public:
  42.     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) {}
  43.     void wypisz()
  44.     {
  45.         cout << "Ksiazka o tytule " << nazwa << " autorstwa " << autor << ", " << miasto_wydania << ' ' << rok_wydania << " (" << wydawnictwo << ") liczba stron: " << ilosc_stron << endl;
  46.     }
  47. };
  48.  
  49. int main()
  50. {
  51.     film film1("Robert Zemeckis", "Forrest Gump", "komediodramat", 1994);
  52.     film1.wypisz();
  53.  
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement