/*********************************************
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.
**********************************************/
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
/*********************************************
** PROTOTYPES & CLASS DEFINITIONS
*********************************************/
struct point
{
double x,y;
};
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 {
// Compute new position p from move m
p.x = p.x + m.x;
p.y = p.y + m.y;
// Write move
OUT << p.x << '\t' << p.y << endl;
}while(getmove(m,cin));
return 0;
}
/*********************************************
** FUNCTION DEFINITIONS
*********************************************/
// 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;
}