Пример #1
0
//***********************************************************************************
// int parseStringX()  
// This is a simple function to parse and return the coodinates you want to goto
// 
// 
//**********************************************************************************
void parseMovement(string strX,string strY,ship &s)
{
   int x;
   int y;
   double hypot=0.0;

    

 
   x = atoi(strX.c_str());
   y = atoi(strY.c_str());
  

   if (x == 0)
   {
	s.setX(s.getX());
   }
  
   if (y == 0)
   {
	s.setY(s.getY());
   }


   if (x <= POSITIVE_XLIMIT && x >= NEGATIVE_XLIMIT && y <= POSITIVE_YLIMIT && y >= NEGATIVE_YLIMIT)
  {
  // calculate data for hypotenuese (sp?) and get units for fuel subtraction
   double xc = x-s.getX();
   double yc = y-s.getY();
  
   double xcsq = xc*xc;
   double yxsq = yc*yc;

   double hypot = abs(sqrt(xcsq+yxsq));
	  // error checking for input
	outfile.open("errorLog.txt", ios::app);
	outfile  << "The time is: " << asctime(localtm) << " " << "Hypotenoose: " << hypot << endl;
    outfile.close();
     // ------
	  s.setX(x);  // 
	  s.setY(y);
  
	  s.setFuel(s.getFuel()-hypot);
  }

 

} // end of method