Create function to convert to polar coordinate system - C++ Function

C++ examples for Function:Function Parameter

Description

Create function to convert to polar coordinate system

Demo Code

#include <iostream>
#include <cmath>
using namespace std;
void polar(double, double, double&, double&);  // function prototype
int main()/*w ww.  java2s .  c om*/
{
   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;
}

Result


Related Tutorials