Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <iostream>
- #include <cassert>
- #include <cstring>
- class Utwor{
- int rok_powstania;
- public:
- Utwor(int);
- virtual ~Utwor();
- int rok();
- virtual void drukuj();
- };
- class Utwor_muzyczny : public Utwor{
- char *tytul;
- public:
- Utwor_muzyczny(char*,int);
- ~Utwor_muzyczny();
- Utwor_muzyczny &operator=(Utwor &);
- void drukuj();
- };
- Utwor::Utwor(int r)
- {
- rok_powstania=r;
- }
- Utwor::~Utwor()
- {
- std::cout<<"Wyowało destruktor klasy bazowej"<<std::endl;
- }
- int Utwor::rok()
- {
- return rok_powstania;
- }
- void Utwor::drukuj(){
- std::cout<<"Rok powstania to: "<<rok_powstania<<std::endl;
- }
- Utwor_muzyczny::Utwor_muzyczny(char *tyt,int r):Utwor(r){
- int dlugosc=strlen(tyt);
- tytul=new char[dlugosc+1];
- assert(tytul);
- strcpy(tytul,tyt);
- }
- Utwor_muzyczny::~Utwor_muzyczny(){
- std::cout<<"Wyowlano destruktor klasy pochodnej "<<std::endl;
- delete [] tytul;
- }
- void Utwor_muzyczny::drukuj(){
- std::cout<<"Rok powstania to: "<<rok()<<" tytul to: "<<tytul<<std::endl;
- }
- Utwor_muzyczny & Utwor_muzyczny::operator=(Utwor &muzyczny)
- {
- if (this==&muzyczny)
- return *this;
- Utwor *wsk;
- wsk=&muzyczny;
- rok_powstania=wsk->rok();
- delete [] tytul;
- int dlugosc=strlen(muzyczny.tytul);
- tytul=new char[dlugosc+1];
- assert(tytul);
- strcpy(tytul,muzyczny.tytul);
- }
- int main()
- {
- Utwor utwor(1998);
- Utwor_muzyczny muzyczny1("Fajny",2012);
- Utwor_muzyczny muzyczny2 ("Siemka",1992);
- Utwor *wsk;
- wsk=&utwor;
- wsk->drukuj();
- wsk=&muzyczny1;
- wsk->drukuj();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement