Pasta: 1dec77b4a72713db9b8ee5b853a29da5931cf439 (2017-11-28)

Język: Text
Adres: p43.pl/p,1dec77b4a72713db9b8ee5b853a29da5931cf439
Ilość linii: 78
Rozmiar: 1.47 kB
Wyświetleń: 234
Ostatnio użyto: 2018-10-21 09:28:09
#include <iostream> #include <string> using namespace std; class K1 { string * p1; public: K1(){ p1=new string[2];} K1(const string & a1,const string & a2) { p1=new string[2]; p1[0]=a1; p1[1]=a2; } string operator[](unsigned i) { if (i > 2) { i = 2; cout << "za zakresem" << endl; } return p1[i]; } string&s1(){return p1[0];} const string&s1() const {return p1[0];} string&s2(){return p1[1];} const string&s2() const {return p1[1];} //friend //ostream &operator<<(ostream &out,const string &r); }; class K2 { K1 p1; double p2; public: K2():p1("duoa ","dupa "),p2(0){} K2(const string & a1,const string & a2 ,const double & a3): p1(a1,a2),p2(a3){} const K1 &K() const {return p1;} double &P(){return p2;} const double &P()const {return p2;} K2 operator- (const double &r) { this->p2-=r; return *this; } friend ostream &operator<<(ostream &out,const string &r); }; ostream &operator<<(ostream &out,const K2 &r) { return out<<r.K().s1()<<r.K().s2()<<r.P()<<endl; } int main() { 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<<endl; delete wsk2; wsk2=0; cout<<ob2<<endl; cout<<ob2-1.25<<endl; return 0; }