Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Point {
- private:
- float a, b;
- public:
- Point() {}
- Point(float _a, float _b) {
- a = _a;
- b = _b;
- }
- Point operator + (Point p) {
- Point res(a + p.a, b + p.b);
- return res;
- }
- Point operator - (Point p) {
- Point res(a - p.a, b - p.b);
- return res;
- }
- Point operator * (Point p) {
- Point res(a * p.a, b * p.b);
- return res;
- }
- Point operator / (Point p) {
- Point res(a / p.a, b / p.b);
- return res;
- }
- void print() {
- cout << a << " " << b << endl;
- }
- };
- int main() {
- Point a(4.0, 5.6);
- Point b(3.7, 6.3);
- Point c_plus = a + b;
- Point c_minus = a - b;
- Point c_multiply = a * b;
- Point c_divide = a / b;
- c_plus.print();
- c_minus.print();
- c_multiply.print();
- c_divide.print();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment