Advertisement
smatskevich

Lesson21

May 6th, 2023
824
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. #include <cmath>
  2. #include <iomanip>
  3. #include <iostream>
  4. using namespace std;
  5. struct Point {
  6.   double x;
  7.   double y;
  8. };
  9. struct Vector {
  10.   double x;
  11.   double y;
  12. };
  13. Vector operator-(const Point& p1, const Point& p2) {return {p1.x - p2.x, p1.y - p2.y};}
  14. Vector operator+(const Vector& v1, const Vector& v2) {return {v1.x + v2.x, v1.y + v2.y};}
  15. Vector operator-(const Vector& v1, const Vector& v2) {return {v1.x - v2.x, v1.y - v2.y};}
  16. Point operator+(const Point& p, const Vector& v) {return {p.x + v.x, p.y + v.y};}
  17. double DotProduct(const Vector& v1, const Vector& v2) {return v1.x * v2.x + v1.y * v2.y;}
  18. double CrossProduct(const Vector& v1, const Vector& v2) {return v1.x * v2.y - v1.y * v2.x;}
  19.  
  20. int main() {
  21.   Vector v1 = {3, 4}, v2 = {0, 5};
  22.   cout << DotProduct(v1, v2) << endl;
  23.   cout << CrossProduct(v2, v1) << endl;
  24.   Point p1{2, 2}, p2{6, 5};
  25.   Vector v3 = p2 - p1;
  26.   cout << v3.x << " " << v3.y << endl;
  27.   return 0;
  28. }
  29.  
  30. int main1() {
  31.   int n = 0;
  32.   Point p;
  33.   p.x = 5.0;
  34.   p.y = acos(-1);
  35.   cout << fixed << p.x << " " << setprecision(10) << p.y << endl;
  36.   cout << p.x << " " << p.y << endl;
  37.   return 0;
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement