/*********************************************
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 & STRUCT DEFINITIONS
 *********************************************/
struct Point
{
  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;
}