/*********************************************
This program creates a text-file for Excel
that plots a course steered by the user.
Our position starts at (0,0), and the user
enters moves in (dx,dy) format, with a "q"
to quit.  Notice how + and << have been
defined for points.  This version of the
program - at least the "main" function - is
very simple and clean.
**********************************************/
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;

/*********************************************
 ** PROTOTYPES & CLASS DEFINITIONS
 *********************************************/
class point
{
public:
  double x,y;
};

point operator+(point a, point b);
bool getmove(point &p,istream &IN);

/*********************************************
 ** MAIN FUNCTION
 *********************************************/
int main()
{
  // Initialization
  ofstream OUT("out.txt");
  point p,m;
  p.x = p.y = m.x = m.y = 0;

  // Get moves & write moves
  do {
    p = p + m;
    OUT << p.x << '\t' << p.y << endl;
  }while(getmove(m,cin));

  return 0;
}

/*********************************************
 ** FUNCTION DEFINITIONS
 *********************************************/
// Defines + for points
point operator+(point a, point b)
{
  point s;
  s.x = a.x + b.x;
  s.y = a.y + b.y;
  return s;
}

// Gets tht next more from the user & stores
// in point p.  Returns true if read was
// successful, and false otherwise
bool getmove(point &p, istream &IN)
{
  cout << "Enter move vector: ";    
  char c;
  if (IN >> c && c == '(' && IN >> p.x &&
      IN >> c && c == ',' && IN >> p.y &&
      IN >> c && c == ')')
    return true;
  else
    return false;
}