Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <string>
- using namespace std;
- class Point
- {
- public:
- float x; //Абсцисса точки.
- float y; //Ордината точки.
- Point() // конструктор по умолчанию для создания точки (0;0)
- {
- x = 0;
- y = 0;
- }
- Point (float a, float b) //конструктор для созданию точки с передаваемыми значениями
- {
- x = a;
- y = b;
- }
- Point (const Point &a) //Создаёт точку, копируя данные из другой точки.
- {
- x = a.x;
- y = a.y;
- }
- //_________________________________________________________________________________________
- Point copy()
- {
- Point tochka (x, y);
- return (tochka);
- }
- bool equals(Point tochka) //Возвращает результат сравнения точки с другой точкой.
- {
- if (x == tochka.x & y == tochka.y)
- return(1);
- else
- return(0);
- }
- bool equals(Point first, Point second) //Возвращает результат сравнения точки first с точкой second
- {
- if (first.x == second.x & first.y == second.y)
- return(1);
- else
- return(0);
- }
- string toString() //Возвращает координаты строкой
- {
- return (format);
- }
- public:
- const string format = "";
- };
- void main()
- {
- setlocale(LC_ALL, "rus");
- Point point1 ;
- Point point2 (3, 4);
- Point point3 (point1);
- cout <<"Первая точка: " << point1.x << " "<< point1.y << "\n"; // стандартная 0.0
- cout <<"Вторая точка: " << point2.x << " "<< point2.y << "\n"; // Вывод трех точек: // с нашими координатами 3.4
- cout <<"Третья точка: " << point3.x << " "<< point3.y << "\n"; // копия первой 0.0
- //Методы:
- cout << point1.equals(point2) << endl; // Сравнивает точку1 с передаваемой точкой2
- cout << point1.equals(point1, point2) << endl; // Сравнивает две передаваемые точки
- Point point4 (point2.copy()); // Проверяет работу метода возвращения копии точки
- cout <<"Четвертая точка, копия от копии второй: " << point4.x << " "<< point4.y << "\n";
- cout << point2.copy().x << point2.copy().y << endl; // Вывод координат копии точки 2
- cout << point2.toString(); //Вывод строки стринг с координатами
- _getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement