/***************************************************
Calculating a midpoint
The program takes the two points as input and
outputs the midpoint.
Carefully look at how the operators are overloaded.
***************************************************/
#include <iostream>
using namespace std;
// struct defintion
struct point
{
double x, y;
};
// operators
istream& operator >> (istream& is, point& p);
ostream& operator << (ostream& os, point p);
point operator + (point p, point q);
point operator / (point p, double d);
// main function
int main()
{
point p, q;
cin >> p >> q;
cout << "midpoint: " << (p+q)/2.0 << endl;
return 0;
}
// defintions of the operators
istream& operator >> (istream& is, point& p)
{
char c;
return is >> c >> p.x >> c >> p.y >> c;
}
ostream& operator << (ostream& os, point p)
{
return os << "(" << p.x << ", " << p.y << ")";
}
point operator + (point p, point q)
{
point r = {p.x+q.x, p.y+q.y};
return r;
}
point operator / (point p, double d)
{
point r = {p.x/d, p.y/d};
return r;
}