#include <fstream>

/**************************************
 ** CLASS DEFINITIONS
 **************************************/
struct point 
{
  double x, y;
};

/**************************************
 ** FUNCTION PROTOTYPES
 **************************************/
point midpoint(point a, point b);
point readpoint();
void writepoint(point p);
void writepoint(point p, ostream&);

/**************************************
 ** MAIN FUNCTION
 **************************************/
int main()
{
  // Read in triangle vertices
  cout << "Enter triangle vertices: ";
  point a = readpoint(), 
        b = readpoint(), 
        c = readpoint();

  // Compute midpoints
  point e = midpoint(a,b), 
        f = midpoint(b,c), 
        g = midpoint(c,a);

  // Write out midpoint triangle vertices
  cout << "Midpoint triangle verts: ";
  writepoint(e);
  writepoint(f);
  writepoint(g);
  cout << endl;

  // Write Excel
  ofstream out("tri.txt");
  // Original triangle
  writepoint(a,out);
  writepoint(b,out);
  writepoint(c,out);
  writepoint(a,out);
  out << endl;  
  // Midpoint triangle
  writepoint(e,out);
  writepoint(f,out);
  writepoint(g,out);
  writepoint(e,out);
  out << endl;

  return 0;
}

/**************************************
 ** FUNCTION DEFINITIONS
 **************************************/
point midpoint(point a, point b)
{
  point m;
  m.x = (a.x + b.x)/2;
  m.y = (a.y + b.y)/2;
  return m;
}

point readpoint()
{
  point p;
  char c;
  cin >> c >> p.x >> c >> p.y >> c;
  return p;
}

// Writes p to the screen in (x,y) notation
void writepoint(point p)
{
  cout << '(' << p.x << ',' << p.y << ')';
}

// Writes p to ostream out in x <tab> y <endl> notation
void writepoint(point p, ostream &out)
{
  out << p.x << '\t' << p.y << endl;
}