Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.20 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class K1;
  6. class K2;
  7.  
  8.  
  9. class K1
  10.     {
  11.      string * p1;
  12.       public:
  13.  
  14.         K1(): p1(new string[2])
  15.         {
  16.             p1[0] = "BRAK";
  17.             p1[1] = "BRAK";
  18.         }
  19.  
  20.         K1(const string &a1,const string &a2): p1(new string[2])
  21.         {
  22.             p1[0] = a1;
  23.             p1[1] = a2;
  24.         }
  25.  
  26.         K1(const K1 &obiekt): p1(new string[2])
  27.         {
  28.             p1[0] = obiekt.p1[0];
  29.             p1[1] = obiekt.p1[1];
  30.         }
  31.  
  32.  
  33.         K1 &operator=(const K1 &a){
  34.             if(this!=&a){
  35.             p1[0] = a.p1[0];
  36.             p1[1] = a.p1[1];
  37.             }
  38.             return *this;
  39.         }
  40.  
  41.         friend ostream &operator<<(ostream &out, const K1 &a)
  42.         {
  43.             return a.pokaz(out);
  44.         }
  45.         ostream &pokaz(ostream &out)const{
  46.         return out << p1[0] << " " << p1[1];
  47.         }
  48.         friend K2;
  49.     };
  50.  
  51. class K2
  52.     {
  53.      K1 p1;
  54.      double p2;
  55.  
  56.       public:
  57.         K2(): p2(0)
  58.         {
  59.         }
  60.  
  61.         K2(const string &a1, const string &a2,const double &a3): p2(a3)
  62.         {
  63.             p1.p1[0] = a1;
  64.             p1.p1[1] = a2;
  65.         }
  66.  
  67.         K2(const K2 &a): p2(a.p2)
  68.         {
  69.             p1.p1[0] = a.p1.p1[0];
  70.             p1.p1[1] = a.p1.p1[1];
  71.         }
  72.  
  73.         K2 &operator=(const K2 &a)
  74.         {
  75.             if(this!=&a){
  76.             p1.p1[0] = a.p1.p1[0];
  77.             p1.p1[1] = a.p1.p1[1];
  78.             p2 = a.p2;
  79.             }
  80.             return *this;
  81.         }
  82.  
  83.          double operator-(const double &i)
  84.         {
  85.             return p2 - i;
  86.         }
  87.  
  88.     friend ostream &operator<<(ostream &out, const K2 &a){
  89.     return a.pokaz(out);
  90.     }
  91.  
  92.     ostream &pokaz(ostream &out)const{
  93.     return out << p1.p1[0] << " " << p1.p1[1] << " " << p2 << endl;
  94.     }
  95.  
  96.  
  97.  
  98.  
  99.     };
  100.  
  101.  
  102. int main() {
  103.     K2 ob1, ob2;
  104.     const K2 *wsk1 = new K2("Kawa", " z mlekiem", 4.50);
  105.     const K2 ob3(*wsk1);
  106.     delete wsk1;
  107.     wsk1=0;
  108.  
  109.     const K2 * wsk2 = new K2(ob3);
  110.     ob2=*wsk2;
  111.     cout<<ob1<<*wsk2;
  112.     delete wsk2;
  113.     wsk2=0;
  114.  
  115. cout<<ob2;
  116. cout<<ob2-1.25;
  117.  
  118. cout<<"******** 3 *********\n"<<endl;
  119.     return 0;
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement