Kolorwanie:
Status:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
#include <iostream>
#include <fstream>
using namespace std;

class K1{
private:
    string *p1;
public:
    K1():p1{nullptr} {
        p1= new string[2];
        p1[0]="default";
        p1[1]="default";

    };
    K1(const string& val1, const string& val2):p1{nullptr}{
        p1= new string[2];
        p1[0]=val1;
        p1[1]=val2;
    }
    K1(const K1& source):p1{nullptr}{
        p1= new string[2];
        p1[0]=source.p1[0];
        p1[1]=source.p1[1];
    }
    string &operator[](const size_t& i){
        return p1[i];
    }
    const string &operator[](const size_t& i) const{
        return p1[i];
    }
    ~K1(){
        delete []p1;
    }
    K1 &operator= (const K1& p){
        if(this==&p){
            return *this;
        }
        delete []p1;
        p1=new string[2];
        p1[0]=p.p1[0];
        p1[1]=p.p1[1];
        return *this;

    }
    ostream &operator <<(ostream &out){
        out<<p1[0]<<"  "<<p1[1]<<"  "<<endl;
        return out;
    }
};
class K2{
private:
double p2;
K1 p1;
public:
K2():p2{0},p1{"default", "default"}{
}
K2(const string& val1, const string &val2, const double& xval):p2{xval}, p1{val1, val2}{
}
K2(const double& xval, const K1& k1val): p2{xval}, p1{k1val}{
}
K2(const K2& source):K2{source.p2, source.p1}{
}
~K2(){}
K2 &operator=(const K2& wsk){
    if(this==&wsk){
        return *this;
    }
    p2=wsk.p2;
    p1[0]=wsk.p1[0];
    p1[1]=wsk.p1[1];
    return *this;
}

friend ostream &operator <<(ostream &out, const K2 &d);
K2 &operator- (const double& x){
    p2=p2-x;
    return *this;
}
void czytaj(ifstream &plik){
    plik>>p1[0];
    plik>>p1[1];
    plik>>p2;

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

};
ostream &operator <<(ostream &out, const K2& d){
    out<<d.p1[0]<<"  "<<d.p1[1]<<"  "<<d.p2<<endl;
    return out;
}

int main(int argc, char const *argv[]) {
    K2 ob1, ob2;
    const K2 *wsk1= new K2{"kawa", " z mlekiem", 4.50};
    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 - 1.25;
    ifstream file;
    file.open("dk.txt");
    K2 tab[4];
    for (size_t i=0; i<4; i++){
    tab[i].czytaj(file);
    }
    for(size_t i=0; i<4; i++){
        tab[i] += 1;
        cout << tab[i];
    }

    file.close();

    return 0;
}


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