Advertisement
Guest User

Untitled

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