Pasta: a41bc60abde4ee4a0400b63008223ac65e1d287b (2017-11-28)

Język: Text
Adres: p43.pl/p,a41bc60abde4ee4a0400b63008223ac65e1d287b
Ilość linii: 179
Rozmiar: 2.74 kB
Wyświetleń: 183
Ostatnio użyto: 2018-07-12 03:04:15
#include <iostream> #include <fstream> using namespace std; class K2; class K1 { string * p1; public: K1() : p1(new string[2]) { p1[0] = "brak"; p1[1] = "brak"; } K1(const string &a, const string &b) { p1 = new string [2]; p1[0] = a; p1[1] = b; } K1(const K1 &r) { p1 = new string [2]; p1[0] = r.p1[0]; p1[1] = r.p1[1]; } string &a0() { return p1[0]; } string &a1() { return p1[1]; } ~K1() { delete [] p1; } friend ostream & operator << (ostream &, const K2 &); }; class K2 { K1 p1; double p2; public: K2() : p1(), p2(0) {} K2(const string & a, const string & b, const double & c) : p1(a,b), p2(c) {} K2(const K2 & r): p1(r.p1), p2(r.p2) {} string & b0() { return p1.a0(); } string & b1() { return p1.a1(); } double & P2() { return p2; } friend ostream & operator << (ostream &, const K2 &); K2 operator - (const double & x) { this->p2 -= 1.25; return *this; } K2 operator += (const double & x) { this->p2 += x; return *this; } K2 operator + (const string & x) { this->p1.a1() += x; return *this; } }; K2 operator + (const string &x, const K2 & obiekt) { K2 O(obiekt); string y; y = O.b0(); O.b0() = x; O.b0() += y; return O; } ostream & operator << (ostream & out, const K2 & r) { out << r.p1.p1[0] << " " << r.p1.p1[1] << " " << r.p2 ; return out; } int main(int argc, char * 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 << '\t' << *wsk2 << '\n'; delete wsk2; wsk2 = 0; cout << ob2 << '\n'; cout << ob2 - 1.25 << '\n'; cout << "******** 3 ********"; K2 tab[4]; ifstream plik; plik.open(argv[1]); for (int i=0; i<4; i++) { plik >> tab[i].b0() >> tab[i].b1() >> tab[i].P2(); } for (int i=0; i<4; i++) { tab[i]+=1; cout << tab[i] << '\n'; } cout << "******** 4 ********"; tab[1] = tab[1] + " with sugar"; tab[3] = "hot " + tab[3]; for (int i=0; i<4; i++) cout << tab[i] << '\n'; cout << "******** 5 ********"; }