Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct Point { double x; double y; };
- struct Vector { double x; double y; };
- Point operator+(const Point& p, const Vector& v) { return {p.x + v.x, p.y + v.y}; }
- Vector operator+(const Vector& v1, const Vector& v2) { return {v1.x + v2.x, v1.y + v2.y}; }
- Vector operator-(const Vector& v1, const Vector& v2) { return {v1.x - v2.x, v1.y - v2.y}; }
- double DotProduct(const Vector& v1, const Vector& v2) { return v1.x * v2.x + v1.y * v2.y; }
- double CrossProduct(const Vector& v1, const Vector& v2) { return v1.x * v2.y - v1.y * v2.x; }
- istream& operator>>(istream& in, Point& p) { return in >> p.x >> p.y; }
- ostream& operator<<(ostream& out, const Point& p) { return out << p.x << " " << p.y; }
- istream& operator>>(istream& in, Vector& v) { return in >> v.x >> v.y; }
- ostream& operator<<(ostream& out, const Vector& v) { return out << v.x << " " << v.y; }
- int main() {
- // Point p; Vector v;
- // cin >> p >> v;
- // cout << p + v;
- Vector v1, v2; cin >> v1 >> v2;
- cout << DotProduct(v1, v2) << "\n";
- cout << CrossProduct(v1, v2) << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement