Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class K1;
- class K2;
- class K1
- {
- string * p1;
- public:
- K1(): p1(new string[2])
- {
- p1[0] = "BRAK";
- p1[1] = "BRAK";
- }
- K1(const string &a1,const string &a2): p1(new string[2])
- {
- p1[0] = a1;
- p1[1] = a2;
- }
- K1(const K1 &obiekt): p1(new string[2])
- {
- p1[0] = obiekt.p1[0];
- p1[1] = obiekt.p1[1];
- }
- K1 &operator=(const K1 &a){
- if(this!=&a){
- p1[0] = a.p1[0];
- p1[1] = a.p1[1];
- }
- return *this;
- }
- friend ostream &operator<<(ostream &out, const K1 &a)
- {
- return a.pokaz(out);
- }
- ostream &pokaz(ostream &out)const{
- return out << p1[0] << " " << p1[1];
- }
- friend K2;
- };
- class K2
- {
- K1 p1;
- double p2;
- public:
- K2(): p2(0)
- {
- }
- K2(const string &a1, const string &a2,const double &a3): p2(a3)
- {
- p1.p1[0] = a1;
- p1.p1[1] = a2;
- }
- K2(const K2 &a): p2(a.p2)
- {
- p1.p1[0] = a.p1.p1[0];
- p1.p1[1] = a.p1.p1[1];
- }
- K2 &operator=(const K2 &a)
- {
- if(this!=&a){
- p1.p1[0] = a.p1.p1[0];
- p1.p1[1] = a.p1.p1[1];
- p2 = a.p2;
- }
- return *this;
- }
- double operator-(const double &i)
- {
- return p2 - i;
- }
- friend ostream &operator<<(ostream &out, const K2 &a){
- return a.pokaz(out);
- }
- ostream &pokaz(ostream &out)const{
- return out << p1.p1[0] << " " << p1.p1[1] << " " << p2 << 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;
- delete wsk2;
- wsk2=0;
- cout<<ob2;
- cout<<ob2-1.25;
- cout<<"******** 3 *********\n"<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement