Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // vector.hpp
- #ifndef _VECTOR_H_
- #define _VECTOR_H_
- class vector
- {
- private:
- double x;
- double y;
- public:
- vector(double x, double y);
- friend bool operator== (vector &vector1, vector &vector2);
- };
- #endif
- // vector.cpp
- #include "vector.hpp"
- #include <cmath>
- vector::vector(double x, double y) {
- this->x = x;
- this->y = y;
- }
- bool operator== (vector &vector1, vector &vector2) {
- // модуль вектора равен квадртному корню из суммы квадратов координат вектора.
- double vector1_module = sqrt(pow(vector1.x, 2) + pow(vector1.y, 2));
- double vector2_module = sqrt(pow(vector2.x, 2) + pow(vector2.y, 2));
- return vector1_module == vector2_module;
- }
- // main.cpp
- #include <iostream>
- #include "vector.hpp"
- int main(int argc, char const *argv[])
- {
- vector vector1(10, 25);
- vector vector2(40, 5);
- vector vector3(25, 10);
- bool comparison1 = (vector1 == vector2);
- bool comparison2 = (vector1 == vector3);
- bool comparison3 = (vector2 == vector3);
- std::cout << std::boolalpha << comparison1 << std::endl;
- std::cout << std::boolalpha << comparison2 << std::endl;
- std::cout << std::boolalpha << comparison3 << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement