Advertisement
Guest User

Untitled

a guest
Nov 11th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class K2;
  6.  
  7. class K1{
  8.     string * p1;
  9.     public:
  10.         K1():p1(new string[2]){
  11.             p1[0]="brak";
  12.             p1[1]="brak";
  13.         }
  14.         K1(const string& a1,const string& a2):p1(new string[2]){
  15.             p1[0]=a1;
  16.             p1[1]=a2;
  17.         }
  18.         K1(const K1& r):p1(new string[2]){
  19.             p1[0]=r.p1[0];
  20.             p1[1]=r.p1[1];
  21.         }
  22.        
  23.         friend ostream& operator<<(ostream& out,const K1& r);
  24.         friend K2;
  25.        
  26.        
  27. ~K1(){delete [] p1;}
  28. };
  29.  
  30. class K2{
  31.     K1 p1;
  32.     double p2;
  33.     public:
  34.         K2():p2(0){}
  35.         K2(const string&a1,const string&a2,const double& a3):p1(a1,a2),p2(a3){}
  36.         K2(const K2& r):p1(r.p1),p2(r.p2){}
  37.        
  38.         friend ostream& operator<<(ostream& out,const K2& r);
  39.        
  40.         const K2 operator-(const double & pa)const{
  41.             return K2(p1.p1[0],p1.p1[1],(p2-pa));
  42.         }
  43. };
  44.  
  45.  
  46. ostream& operator<<(ostream& out,const K2& r){
  47.     return out<< r.p1 << r.p2 <<endl;
  48. }
  49.  
  50. ostream& operator<<(ostream& out,const K1& r){
  51.     return out<< r.p1[0] << " " << r.p1[1] << " ";
  52. }
  53.  
  54.  
  55.  
  56.  
  57. int main(int argc, char** argv) {
  58.    
  59.     K2 ob1, ob2;
  60.     const K2 * wsk1 = new K2("kawa","z mlekiem",4.50);
  61.     const K2 ob3(*wsk1);
  62.     delete wsk1;
  63.     wsk1=0;
  64.    
  65.     const K2 * wsk2 = new K2(ob3);
  66.     ob2=*wsk2;
  67.     cout << ob1 << *wsk2;
  68.     delete wsk2;
  69.     wsk2= 0;
  70.    
  71.     cout << ob2;
  72.     cout << ob2-1.25;
  73.    
  74.     return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement