Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.35 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.  
  118. ostream& operator<< (ostream &out, CcoloredPoint &cpoint)
  119. {
  120.     cout << "Координаты х и у: ";
  121.     out << cpoint.get_X() << ' ' << cpoint.get_Y() << endl;
  122.     cout << "Цвет " << endl;
  123.     vector <char> ws_v = cpoint.Get_v();
  124.     for (auto i : ws_v) {
  125.         out << i;
  126.     }
  127.    
  128.     return out;
  129. }
  130.  
  131. class CcoloredLine : public CcoloredPoint{
  132.     private :
  133.     vector <CcoloredPoint> v;
  134.     public :
  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. int main()
  149. {
  150. //    CPoint first;
  151. //    int absc, ord;
  152. //    cin >> absc >> ord;
  153. //    first.set_XY(absc, ord);
  154. //    cout << first;
  155.     int a = 5, b = 7;
  156.     char test [] = { 'w', 'h', 'i', 't', 'e' };
  157.     vector<char> v;
  158.     for(int i=0;i<5;i++)
  159.         v.push_back(test[i]);
  160.     CcoloredPoint first (a, b, v);
  161.     cout << first << endl;
  162.    
  163.    
  164.     /*CPoint f(2,5), d(3, 6);
  165.      CPoint *massive_pointov= new CPoint[2];
  166.      massive_pointov[0]=f;
  167.      massive_pointov[1]=d;
  168.      
  169.      CLine fr(massive_pointov,2);
  170.      fr.get_info();
  171.      cout<<endl;
  172.      fr.add(f);
  173.      fr.get_info();*/
  174.    
  175.     return 0;
  176. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement