//what is the problem in following program?


#include <iostream>
#include <cmath>

using namespace std;

// FUNCTION PROTYPE FOR test_polar
void test_polar();

// FUNCTION PROTOTYPE FOR read_point
void read_point(double & radius, double & angle);


// FUNCTION PROTOTYPE FOR degrees2radians
double degrees2radians(double angle);

// FUNCTION PROTOTYPE FOR compute_coord
void compute_coord(double radius, double radians, double & x, double & y);

// FUNCTION PROTOTYPE FOR compute_distance
double compute_distance(double x1, double y1,double x2,double y2);


// FUNCTION PROTOTYPE FOR output_point
void output_point(double x, double y);

// DO NOT MODIFY THE MAIN ROUTINE IN ANY WAY
int main()
{
double r1(0.0), a1(0.0); // Polar coord (r1, a1) of point 1
double r2(0.0), a2(0.0); // Polar coord (r2, a2) of point 2
double radians1(0.0); // Angle a1 in radians
double radians2(0.0); // Angle a2 in radians
double x1(0.0), y1(0.0); // Cartesian (x,y) coordinates of point 1
double x2(0.0), y2(0.0); // Cartesian (x,y) coordinates of point 2
double distance(0.0); // Distance between points

// Call test routine
test_polar();

// Read two points in polar coordinates
read_point(r1, a1);
read_point(r2, a2);

// Convert degrees to radians
radians1 = degrees2radians(a1);
radians2 = degrees2radians(a2);

// Compute Cartesian (x,y) coordinates
compute_coord(r1, radians1, x1, y1);
compute_coord(r2, radians2, x2, y2);

// Compute distance from point 1 to point 2
distance = compute_distance(x1, y1, x2, y2);

cout << "Distance from ";
output_point(x1, y1);
cout << " to ";
output_point(x2,y2);
cout << " = " << distance << endl;

return 0;
}

// DO NOT MODIFY THIS FUNCTION IN ANY WAY
// test_polar: Test functions in polar.cpp
void test_polar()
{
double radians(0.0); // angle in radians
double x(0.0), y(0.0); // Cartesian (x,y) coordinates
double distance(0.0); // distance between points

cout << "Testing:" << endl;

radians = degrees2radians(45);
cout << "45 degrees equals " << radians << " radians." << endl;

cout << "Polar coordinates (2,30) = Cartesian coordinates ";
output_point(1.73, 1.00);
cout << endl;

compute_coord(2, M_PI/3, x, y);
cout << "Polar coordinates (2,60) = Cartesian coordinates ";
output_point(x, y);
cout << endl;

distance = compute_distance(1.73, 1.00, 1.00, 1.73);
cout << "Distance from (1.73,1.00) to (1.00,1.73) = "
<< distance << endl;

cout << "End test." << endl;
cout << endl;
}

// DEFINE FUNCTION read_point here:

void read_point(double & radius, double & angle)
{
cout<<"Enter polar coordinates of point (radius, angle) : "<<endl;
cin>>radius>>angle;

}

// DEFINE FUNCTION degrees2radians here:

double degrees2radians(double angle)
{
double radians=angle * M_PI / 180;
return radians;
}

// DEFINE FUNCTION compute_coord here:
void compute_coord(double r, double radians, double & x, double & y)
{
x=r*cos(radians);
y=r*sin(radians);

}

// DEFINE FUNCTION distance here:

double compute_distance(double x1, double y1, double x2, double y2)

{
double distance=sqrt((x2-x1)^2+(y2-y1)^2);
return distance;
}


// DEFINE FUNCTION output_point here:

void output_point(double x, double y)
{
cout.precision(2);

}


//what is the problem it has?

This article has been dead for over six months. Start a new discussion instead.