Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- class komunikator{
- public:
- virtual ostream& wyswietl (ostream& out) const=0;
- virtual ~komunikator(){};
- };
- class k1 : public komunikator{
- protected:
- string* text;
- public:
- k1():text(new string("brak")){};
- k1(const string& a):text(new string(a)){};
- k1(const k1& a):text(new string(*a.text)){};
- k1& operator = (const k1& a) {
- if(this != &a) {
- delete text;
- text = new string(*a.text);
- }
- return *this;
- }
- ~k1(){delete text;}
- ostream& wyswietl (ostream& out) const {return out<<*text;};
- };
- class k2:public komunikator{
- protected:
- string* text;
- int wartosc;
- public:
- k2():text(new string("brak")),wartosc(0){};
- k2(const string& a,int b):text(new string(a)),wartosc(b){};
- ~k2(){delete text;};
- ostream& wyswietl (ostream& out) const {return out<<*text<<" "<<wartosc<<endl;};
- };
- int main(){
- const k1 koniec("Koniec komunikatow");
- komunikator* linia [5];
- linia[0] = new k1("Temperatura powietrza:");
- linia[1] = new k2("Czestochowa", -5);
- linia[2] = new k1("Opady sniegu:");
- linia[3] = new k2("Katowice", 10);
- linia[4] = new k1(koniec);
- for(int i=0; i<5; ++i){
- cout << *linia[i];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement