C++ Function Parameter convert to polar coordinate system

Description

C++ Function Parameter convert to polar coordinate system

#include <iostream>
#include <cmath>
using namespace std;
void polar(double, double, double&, double&);  // function prototype
int main()//from   w  w  w  . j av a2s . co  m
{
   double distance, angle;
   polar(3.0, 4.0, distance, angle);
   cout << "r = " << distance << endl;
   cout << "angle = " << angle << endl;
   return 0;
}
void polar(double x, double y, double& r, double& theta)
{
   const double TODEGREES = 180.0/3.141593;
   r = sqrt(x * x + y * y);
   theta = atan(y/x) * TODEGREES;
   return;
}



PreviousNext

Related