Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <string>
  4. using namespace std;
  5.  
  6.  
  7. class Point
  8. {
  9. public:
  10. float x; //Абсцисса точки.
  11. float y; //Ордината точки.
  12.  
  13. Point() // конструктор по умолчанию для создания точки (0;0)
  14. {
  15. x = 0;
  16. y = 0;
  17. }
  18.  
  19. Point (float a, float b) //конструктор для созданию точки с передаваемыми значениями
  20. {
  21. x = a;
  22. y = b;
  23. }
  24.  
  25. Point (const Point &a) //Создаёт точку, копируя данные из другой точки.
  26. {
  27. x = a.x;
  28. y = a.y;
  29. }
  30.  
  31. //_________________________________________________________________________________________
  32.  
  33. Point copy()
  34. {
  35. Point tochka (x, y);
  36. return (tochka);
  37. }
  38.  
  39. bool equals(Point tochka) //Возвращает результат сравнения точки с другой точкой.
  40. {
  41. if (x == tochka.x & y == tochka.y)
  42. return(1);
  43. else
  44. return(0);
  45. }
  46.  
  47. bool equals(Point first, Point second) //Возвращает результат сравнения точки first с точкой second
  48. {
  49. if (first.x == second.x & first.y == second.y)
  50. return(1);
  51. else
  52. return(0);
  53. }
  54.  
  55. string toString() //Возвращает координаты строкой
  56. {
  57. return (format);
  58. }
  59.  
  60. public:
  61. const string format = "";
  62. };
  63.  
  64. void main()
  65. {
  66. setlocale(LC_ALL, "rus");
  67.  
  68. Point point1 ;
  69. Point point2 (3, 4);
  70. Point point3 (point1);
  71.  
  72. cout <<"Первая точка: " << point1.x << " "<< point1.y << "\n"; // стандартная 0.0
  73. cout <<"Вторая точка: " << point2.x << " "<< point2.y << "\n"; // Вывод трех точек: // с нашими координатами 3.4
  74. cout <<"Третья точка: " << point3.x << " "<< point3.y << "\n"; // копия первой 0.0
  75.  
  76. //Методы:
  77. cout << point1.equals(point2) << endl; // Сравнивает точку1 с передаваемой точкой2
  78.  
  79. cout << point1.equals(point1, point2) << endl; // Сравнивает две передаваемые точки
  80.  
  81. Point point4 (point2.copy()); // Проверяет работу метода возвращения копии точки
  82. cout <<"Четвертая точка, копия от копии второй: " << point4.x << " "<< point4.y << "\n";
  83.  
  84. cout << point2.copy().x << point2.copy().y << endl; // Вывод координат копии точки 2
  85.  
  86. cout << point2.toString(); //Вывод строки стринг с координатами
  87.  
  88. _getch();
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement