Advertisement
smatskevich

Lesson29

Apr 25th, 2024
641
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct Point { double x; double y; };
  6. struct Vector { double x; double y; };
  7. Point operator+(const Point& p, const Vector& v) { return {p.x + v.x, p.y + v.y}; }
  8. Vector operator+(const Vector& v1, const Vector& v2) { return {v1.x + v2.x, v1.y + v2.y}; }
  9. Vector operator-(const Vector& v1, const Vector& v2) { return {v1.x - v2.x, v1.y - v2.y}; }
  10. double DotProduct(const Vector& v1, const Vector& v2) { return v1.x * v2.x + v1.y * v2.y; }
  11. double CrossProduct(const Vector& v1, const Vector& v2) { return v1.x * v2.y - v1.y * v2.x; }
  12. istream& operator>>(istream& in, Point& p) { return in >> p.x >> p.y; }
  13. ostream& operator<<(ostream& out, const Point& p) { return out << p.x << " " << p.y; }
  14. istream& operator>>(istream& in, Vector& v) { return in >> v.x >> v.y; }
  15. ostream& operator<<(ostream& out, const Vector& v) { return out << v.x << " " << v.y; }
  16.  
  17. int main() {
  18. //  Point p; Vector v;
  19. //  cin >> p >> v;
  20. //  cout << p + v;
  21.   Vector v1, v2; cin >> v1 >> v2;
  22.   cout << DotProduct(v1, v2) << "\n";
  23.   cout << CrossProduct(v1, v2) << "\n";
  24.   return 0;
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement