Kolorwanie:
Status:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
#include <iostream>
#include <fstream>

using namespace std;

class K1{
    private:
        string *p1;
    public:
        friend class K2;
        K1():p1{nullptr}{
            p1=new string;

        }
        K1(const string& string_val):p1{nullptr}{
            p1=new string;
            *p1=string_val;
        }
        ~K1(){
            delete p1;
        }
        K1(const K1& source):K1{*source.p1}{

        };
        K1& operator=(const K1& data){
            if (this==&data){
                return *this;
            }
            delete p1;
            p1=new string;
            *p1=*data.p1;
            return *this;
        }
    
    friend ostream &operator<<(ostream &out, const K1 &data);
};
    ostream &operator<<(ostream &out, const K1 &data){
        out<<*data.p1;
        return out;
}


class K2{
    private:
        K1 txt[2];
        int w1;
    public:
        K2():w1{0}{
            *txt[0].p1="default";
            *txt[1].p1="default";
        }
        K2(const string& k1val1,const string& k1val2, const int& intval):w1{intval}{
            *txt[0].p1=k1val1;
            *txt[1].p1=k1val2;
        }
        K2(const K2& source):w1{source.w1}{
            *txt[0].p1=*source.txt[0].p1;
            *txt[1].p1=*source.txt[1].p1;

        }
        K2 &operator=(const K2& data){
            if(this==&data){
                return *this;
            }
            *txt[0].p1=*data.txt[0].p1;
            *txt[1].p1=*data.txt[1].p1;
            w1=data.w1;
            return *this;

        }
        ~K2(){}
        friend ostream& operator<< (ostream &os, const K2& data);

        K2 &operator+ (const int& x){
            w1=w1+x;

            return *this;
        }
        K2 &operator+= (const int& x){
            w1+=x;

            return *this;
        }
        void czytaj(ifstream &plik){
            plik>>*txt[0].p1;
            plik>>*txt[1].p1;
            plik>>w1;
        }

};
        ostream& operator<< (ostream & os, const K2& data){
            os<<data.txt[0]<<"  "<<data.txt[1]<<"  "<<data.w1<<endl;
            return os;
        }

int main(int argc, char const *argv[]) {

    K2 ob1, ob2;

    const K2 *wsk1= new K2 {"ala", "koala",15};
    const K2 ob3(*wsk1);
    delete wsk1;
    wsk1=0;
    const K2 *wsk2 = new K2(ob3);
    ob2=*wsk2;
    cout<<ob1<<*wsk2;
    delete wsk2;
    wsk2=0;
    cout<<ob2;
    cout<<ob2+10;

    ifstream file;
    file.open("dk2.txt");
    K2 tab[4];
    for(size_t i=0; i<4; ++i){
        tab[i].czytaj(file);
    }
    for (int i=0; i<4; ++i){
        tab[i]+=1;
        cout<<tab[i];
    }

    return 0;
}


Copyrights 2014-2019 © Wklejaj.pl Wszelkie prawa zastrzeżone.