Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class WpisBiblioteczny
- {
- protected:
- string title;
- short rok;
- public:
- WpisBiblioteczny(string tytul, short year);
- virtual void wypisz() const = 0; // metoda czysto wirtualna
- };
- class Ksiazka : public WpisBiblioteczny
- {
- string autor;
- string miasto;
- short liczba_stron;
- public:
- Ksiazka(string tytul, short year, string auth, string city, short strony);
- void wypisz() const;
- };
- class Film : public WpisBiblioteczny
- {
- string rezyser;
- string scenariusz;
- short czas_trwania;
- public:
- Film(string tytul, short year, string director, string screenplay, short time);
- void wypisz() const;
- };
- WpisBiblioteczny::WpisBiblioteczny(string tytul, short year) : title(tytul), rok(year) {}
- Ksiazka::Ksiazka(string tytul, short year, string auth, string city, short strony)
- : WpisBiblioteczny(tytul, year), autor(auth), miasto(city), liczba_stron(strony) {}
- void Ksiazka::wypisz() const
- {
- cout << "Ksiazka pod tytulem " << '\"' << title << "\" autorstwa " << autor
- << ", wydana w roku " << rok << " w " << miasto << ", liczba stron: " << liczba_stron << endl;
- }
- Film::Film(string tytul, short year, string director, string screenplay, short time)
- : WpisBiblioteczny(tytul, year), rezyser(director), scenariusz(screenplay), czas_trwania(time) {}
- void Film::wypisz() const
- {
- cout << "Film pod tytulem " << '\"' << title << "\" w rezyserii " << rezyser
- << ", scenariusz " << scenariusz << ", premiera w roku " << rok << ", dlugosc: " << czas_trwania << " minut" << endl;
- }
- int main()
- {
- WpisBiblioteczny* tab[2];
- tab[0] = new Ksiazka("Rok 1984", 1948, "George Orwell", "Londyn", 300);
- tab[1] = new Film("Forrest Gump", 1994, "Robert Zemeckis", "Eric Roth", 140);
- for(short i = 0; i < 2; ++i)
- tab[i]->wypisz();
- delete tab[0];
- delete tab[1];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment