Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1.  
  2.  
  3. #include <iostream>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. class CPoint
  9. {
  10. protected:
  11. int x;
  12. int y;
  13. public:
  14. CPoint()
  15. {
  16. x = 0;
  17. y = 0;
  18. };
  19. CPoint(int _x, int _y)
  20. {
  21. x = _x;
  22. y = _y;
  23. }
  24. friend istream& operator>> (istream &in, CPoint &cpoint);
  25. friend ostream& operator<< (ostream &out, CPoint &cpoint);
  26.  
  27. void get_out_XY()
  28. {
  29. cout << "Значение координаты x: " << x << ' ' << "Значение координаты y: " << y << endl;
  30. }
  31. int get_X()
  32. {
  33. return x;
  34. }
  35. int get_Y()
  36. {
  37. return y;
  38. }
  39. void set_XY(int _x_, int _y_)
  40. {
  41. x = _x_;
  42. y = _y_;
  43. }
  44. void get_XY(int &x, int &y)
  45. {
  46. x = this->x;
  47. y = this->y;
  48. }
  49. };
  50.  
  51. istream& operator>> (istream &in, CPoint &cpoint)
  52. {
  53. cout << "Введите координаты x и y: ";
  54. in >> cpoint.x >> cpoint.y;
  55.  
  56. return in;
  57. }
  58.  
  59. ostream& operator<< (ostream &out, CPoint &cpoint)
  60. {
  61. cout << "Координаты х и у: ";
  62. out << cpoint.x << ' ' << cpoint.y << endl;
  63.  
  64. return out;
  65. }
  66.  
  67. class CLine : public CPoint
  68. {
  69. private:
  70. int length = 0;
  71. CPoint *mas;
  72. public:
  73. CLine(CPoint *massive,int num)
  74. {
  75. length = num;
  76. *mas = *new CPoint[length];
  77. for(int i =0 ;i < num; i++)
  78. {
  79. mas[i]=massive[i];
  80. }
  81. }
  82. void get_info()
  83. {
  84. for(int i = 0; i < length; i++)
  85. {
  86. mas[i].get_out_XY();
  87. }
  88. }
  89.  
  90. void add(CPoint &p)
  91. {
  92. length++;
  93. mas[length-1] = p;
  94. }
  95. };
  96.  
  97.  
  98.  
  99. ////////////
  100. class CcoloredPoint : public CPoint
  101. {
  102. private:
  103. vector <char> v;
  104. public:
  105. CcoloredPoint():CPoint(){};
  106.  
  107. CcoloredPoint(int _x, int _y, vector <char> new_v):CPoint(_x,_y)
  108. {
  109. v = new_v;
  110. }
  111. friend ostream& operator<< (ostream &out, CPoint &cpoint);
  112. vector <char> Get_v () {
  113. return v;
  114. }
  115. };
  116.  
  117. ostream& operator<< (ostream &out, CcoloredPoint &cpoint)
  118. {
  119. cout << "Координаты х и у: ";
  120. out << cpoint.get_X() << ' ' << cpoint.get_Y() << endl;
  121. cout << "Цвет " << endl;
  122. vector <char> ws_v = cpoint.Get_v();
  123. for (auto i : ws_v) {
  124. out << i;
  125. }
  126.  
  127. return out;
  128. }
  129. int main()
  130. {
  131. // CPoint first;
  132. // int absc, ord;
  133. // cin >> absc >> ord;
  134. // first.set_XY(absc, ord);
  135. // cout << first;
  136. int a = 5, b = 7;
  137. char test [] = { 'w', 'h', 'i', 't', 'e' };
  138. vector<char> v;
  139. for(int i=0;i<5;i++)
  140. v.push_back(test[i]);
  141. CcoloredPoint first (a, b, v);
  142. cout << first << endl;
  143.  
  144.  
  145. /*CPoint f(2,5), d(3, 6);
  146. CPoint *massive_pointov= new CPoint[2];
  147. massive_pointov[0]=f;
  148. massive_pointov[1]=d;
  149.  
  150. CLine fr(massive_pointov,2);
  151. fr.get_info();
  152. cout<<endl;
  153. fr.add(f);
  154. fr.get_info();*/
  155.  
  156. return 0;
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement