C++ Function Definition Rectangular to Polar Coordinate Conversion

Description

C++ Function Definition Rectangular to Polar Coordinate Conversion

#include <iostream>
#include <cmath>
using namespace std;
void getrec(double&, double&);                 // function prototype
void polar(double, double, double&, double&);   // function prototype
void showit(double, double);                   // function prototype
int main()//from w  ww.j a  v a2  s  . co m
{
   double x, y, distance, angle;
   getrec(x, y);
   polar(x, y, distance, angle);
   showit(distance, angle);
   return 0;
}
void getrec(double& x, double& y)
{
   cout << "Rectangular to Polar Coordinate"
   << " Conversion Program\n" << endl;
   cout << "Enter the x coordinate: ";
   cin  >> x;
   cout << "Enter the y coordinate: ";
   cin  >> y;
   return;
}
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;
}
void showit(double radius, double angle)
{
   cout << "\nThe polar coordinates are: " << endl;
   cout << "  Distance from origin: " << radius << endl;
   cout << "  Angle (in degrees) from x-axis: " << angle << endl;
   return;
}



PreviousNext

Related