Advertisement
Guest User

Coffe

a guest
Nov 20th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. class K1 {
  7.     string* p1;
  8. public:
  9.     K1();
  10.     K1(const K1&);
  11.     K1& operator=(const K1&);
  12.  
  13.     void setStrings(const string& s1, const string& s2);
  14.  
  15. };
  16.  
  17. class K2 {
  18.     K1 p1;
  19.     double p2;
  20. public:
  21.     K2() {};
  22.     K2(const string& s1, const string& s2, double p);
  23.     K2(const K2&);
  24.     K2& operator=(const K2&);
  25. };
  26.  
  27.  
  28. K1::K1() {
  29.     p1 = new string[2];
  30. }
  31.  
  32. K1::K1(const K1& other) {
  33.     this->operator=(other);
  34. }
  35.  
  36. K1& K1::operator=(const K1& other) {
  37.     this->p1 = other.p1;
  38. }
  39.  
  40. void K1::setStrings(const string& s1, const string& s2) {
  41.     p1[0] = s1;
  42.     p1[1] = s2;
  43. }
  44.  
  45. K2::K2(const string& s1, const string& s2, double p) {
  46.     this->p1.setStrings(s1, s2);
  47.     this->p2 = p;
  48. }
  49.  
  50. K2::K2(const K2& other) {
  51.     this->operator=(other);
  52. }
  53.  
  54. K2& K2::operator=(const K2& other) {
  55.     this->p1 = other.p1;
  56.     this->p2 = other.p2;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement