MeehoweCK

Untitled

Dec 15th, 2022
790
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.93 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class WpisBiblioteczny
  6. {
  7. protected:
  8.     string title;
  9.     short rok;
  10. public:
  11.     WpisBiblioteczny(string tytul, short year);
  12.     virtual void wypisz() const = 0;        // metoda czysto wirtualna
  13. };
  14.  
  15. class Ksiazka : public WpisBiblioteczny
  16. {
  17.     string autor;
  18.     string miasto;
  19.     short liczba_stron;
  20. public:
  21.     Ksiazka(string tytul, short year, string auth, string city, short strony);
  22.     void wypisz() const;
  23. };
  24.  
  25. class Film : public WpisBiblioteczny
  26. {
  27.     string rezyser;
  28.     string scenariusz;
  29.     short czas_trwania;
  30. public:
  31.     Film(string tytul, short year, string director, string screenplay, short time);
  32.     void wypisz() const;
  33. };
  34.  
  35. WpisBiblioteczny::WpisBiblioteczny(string tytul, short year) : title(tytul), rok(year) {}
  36.  
  37. Ksiazka::Ksiazka(string tytul, short year, string auth, string city, short strony)
  38.     : WpisBiblioteczny(tytul, year), autor(auth), miasto(city), liczba_stron(strony) {}
  39.  
  40. void Ksiazka::wypisz() const
  41. {
  42.     cout << "Ksiazka pod tytulem " << '\"' << title << "\" autorstwa " << autor
  43.          << ", wydana w roku " << rok << " w " << miasto << ", liczba stron: " << liczba_stron << endl;
  44. }
  45.  
  46. Film::Film(string tytul, short year, string director, string screenplay, short time)
  47.     : WpisBiblioteczny(tytul, year), rezyser(director), scenariusz(screenplay), czas_trwania(time) {}
  48.  
  49. void Film::wypisz() const
  50. {
  51.     cout << "Film pod tytulem " << '\"' << title << "\" w rezyserii " << rezyser
  52.          << ", scenariusz " << scenariusz << ", premiera w roku " << rok << ", dlugosc: " << czas_trwania << " minut" << endl;
  53. }
  54.  
  55. int main()
  56. {
  57.     WpisBiblioteczny* tab[2];
  58.     tab[0] = new Ksiazka("Rok 1984", 1948, "George Orwell", "Londyn", 300);
  59.     tab[1] = new Film("Forrest Gump", 1994, "Robert Zemeckis", "Eric Roth", 140);
  60.  
  61.     for(short i = 0; i < 2; ++i)
  62.         tab[i]->wypisz();
  63.  
  64.     delete tab[0];
  65.     delete tab[1];
  66.  
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment