SHARE
TWEET

Untitled

a guest Jan 21st, 2020 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <string>
  3.  
  4.  using namespace std;
  5.  
  6.  class komunikator{
  7.      public:
  8.  virtual ostream& wyswietl (ostream& out) const=0;
  9.  virtual ~komunikator(){};
  10.  };
  11.  
  12.  class k1 : public komunikator{
  13. protected:
  14.     string* text;
  15. public:
  16.  
  17.     k1():text(new string("brak")){};
  18.     k1(const string& a):text(new string(a)){};
  19.     k1(const k1& a):text(new string(*a.text)){};
  20.  
  21.      k1& operator = (const k1& a) {
  22.         if(this != &a) {
  23.             delete text;
  24.             text = new string(*a.text);
  25.         }
  26.         return *this;
  27.     }
  28.  
  29.     ~k1(){delete text;}
  30.     ostream& wyswietl (ostream& out) const {return out<<*text;};
  31.  };
  32.  
  33.  class k2:public komunikator{
  34.      protected:
  35.  string* text;
  36.  int wartosc;
  37.  public:
  38.      k2():text(new string("brak")),wartosc(0){};
  39.      k2(const string& a,int b):text(new string(a)),wartosc(b){};
  40.  
  41.  
  42.      ~k2(){delete text;};
  43.      ostream& wyswietl (ostream& out) const {return out<<*text<<" "<<wartosc<<endl;};
  44.  };
  45.  
  46.  
  47.  
  48.  int main(){
  49.  const k1 koniec("Koniec komunikatow");
  50.  
  51.     komunikator* linia [5];
  52.     linia[0] = new k1("Temperatura powietrza:");
  53.     linia[1] = new k2("Czestochowa", -5);
  54.     linia[2] = new k1("Opady sniegu:");
  55.     linia[3] = new k2("Katowice", 10);
  56.     linia[4] = new k1(koniec);
  57.  
  58.  
  59.     for(int i=0; i<5; ++i){
  60.         cout << *linia[i];
  61.  
  62.  return 0;
  63.  }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top