Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- #include <cmath>
- using namespace std;
- /*
- *
- * Программное обеспечение пожирает мир.
- * — Марк Андрессен
- *
- */
- class Segment {
- private:
- double x, xx;
- double y, yy;
- public:
- Segment(double x = 0, double y = 0, double xx = 0, double yy = 0) {
- this->x = x;
- this->y = y;
- this->xx = xx;
- this->yy = yy;
- };
- Segment random() {
- srand(time(0));
- return Segment(rand() % 31 - 15, rand() % 31 - 15, rand() % 31 - 15, rand() % 31 - 15);
- };
- friend ostream& operator<<(ostream& os, const Segment& at) {
- os << "x=" << at.x << ", y=" << at.y << " -> x1=" << at.xx << ", y1=" << at.yy;
- return os;
- };
- //Длинна отрезка
- double length() {
- return sqrt(pow(xx - x, 2) + pow(yy - y, 2));
- };
- bool equals(Segment a) {
- if (this->length() == a.length())return true;
- return false;
- };
- bool operator==(Segment a) {
- return this->equals(a);
- };
- bool operator!=(Segment a) {
- return !(this->equals(a));
- };
- void operator=(Segment b) {
- this->x = b.x;
- this->y = b.y;
- this->xx = b.xx;
- this->yy = b.yy;
- };
- };
Advertisement
Add Comment
Please, Sign In to add comment