This program is proving difficult to begin. I\'m supposed to make a program that
ID: 3623445 • Letter: T
Question
This program is proving difficult to begin. I'm supposed to make a program that reads in polar coordinates of two points and then compute and output the distance between the two points. I have to do this with the five functions: read_point(), degrees2radians(), compute_coord(), compute_distance() and output_point(). The steps are :1. Write a function read_point() which prints and reads in the polar coordinates (radius and angle) of a point. The function has two
parameters: the polar radius of the point, and the polar angle in degrees of the point.
Both parameters are of type double. The parameters should be passed by reference.
The function does not return any value.
2. Write a function degrees2radians() which converts degrees to radians. The function
has one parameter: an angle in degrees of type double. The function returns a value
of type double which is the angle in radians.
The formula to convert degrees to radians is: R=(D*PI)/180, where D is in degrees
3. Write a function compute_coord() which computes the Cartesian (x; y) coordinates of a point from its polar coordinates (radius; angle) where angle is measured in radians.
The function has four parameters:
- the polar radius of the point
- the polar angle in radians of the point
- the x-coordinate of the point
- the y-coordinate of the point
The formula to compute the x and y-coordinates from the polar coordinates is:
x=radius*cos(angle)
y=radius*sin(angle)
where radius is the polar radius, angle is the angle measured in radians, x is the
x-coordinate and y is the y-coordinate of the point.
4. Write a function compute_distance() which computes the distance between two
points. The function has four parameters listed in the following order:
- the x-coordinate of the first point
- the y-coordinate of the first point
- the x-coordinate of the second point
- the y-coordinate of the second point
The formula to compute the distance is:
d=sqrt((x2-x1)^2-(y2-y1)^2)
where x1; y1 are the x and y-coordinates of the rst point, and x2; y2 are the x and
y-coordinates of the second point, and distance is the distance.
5. Write a function output_point() which prints at the terminal the two coordinates
of a point between parentheses and separated by a comma. The coordinates should
be in fixed notation with exactly two digits after the decimal point.) For instance,
output_point(7.2,5) should print (7.20,5.00)". Note that output_point() does
not print a new line after the point. The function has two parameters:
- the first parameter is the x-coordinate of the point;
- the second parameter is the y-coordinate of the point.
All parameters should have type double and should be passed by value. The function
does not return any value.
My code so far is this with the categories set in order. I just have no idea where to begin and my mind is ready to explode.
#include <iostream>
#include <cmath>
using namespace std;
// FUNCTION PROTYPE FOR test_polar
void test_polar();
// FUNCTION PROTOTYPE FOR read_point
// FUNCTION PROTOTYPE FOR degrees2radians
// FUNCTION PROTOTYPE FOR compute_coord
// FUNCTION PROTOTYPE FOR compute_distance
// FUNCTION PROTOTYPE FOR output_point
// 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:
// DEFINE FUNCTION degrees2radians here:
// DEFINE FUNCTION compute_coord here:
// DEFINE FUNCTION distance here:
// DEFINE FUNCTION output_point here:
Explanation / Answer
please rate - thanks
should get you started
I don't understand the math-sorry
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
// FUNCTION PROTYPE FOR test_polar
void test_polar();
// FUNCTION PROTOTYPE FOR read_point
void read_point(double&,double&);
// FUNCTION PROTOTYPE FOR degrees2radians
double degrees2radians(double);
// FUNCTION PROTOTYPE FOR compute_coord
void compute_coord( double,double,double&,double&);
// FUNCTION PROTOTYPE FOR compute_distance
double compute_distance(double,double,double,double);
// FUNCTION PROTOTYPE FOR output_point
void output_point(double,double);
// 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;
system("pause");
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& r,double& a)
{cout<<"for a point ";
cout<<"enter the radius: ";
cin>>r;
cout<<"enter the angle: ";
cin>>a;
}
// DEFINE FUNCTION degrees2radians here:
double degrees2radians(double d)
{return d*((22./7.)/180.);
}
// DEFINE FUNCTION compute_coord here:
void compute_coord( double r,double a,double& x,double& y)
{x=r*cos(a);
y=r*sin(a);
}
// DEFINE FUNCTION distance here:
double compute_distance(double x1,double y1,double x2,double y2)
{double num;
num=pow(x2-x1,2.)-pow(y2-y1,2.);
if(fabs(num)==0)
num=0;
else
num=sqrt(num);
cout<<num<<endl;
return num;
}
// DEFINE FUNCTION output_point here:
void output_point(double x,double y)
{cout<<"("<<setprecision(2)<<fixed<<x<<","<<y<<")";
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.