1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
#include <iostream>
#include <cmath>
using namespace std;
// FUNCTION PROTOTYPE FOR degrees2radians
double degrees2radians(double deg);
// FUNCTION PROTOTYPE FOR compute_coord
double compute_coord(double r, double angr, double & x, double & y);
// DO NOT MODIFY THE MAIN ROUTINE IN ANY WAY
int main()
{
double angle_degrees(0.0), angle_radians(0.0), radius(0.0); //angle_degrees is the user inputted angle. angle_radians is the angle of the user input but in radians, radius is the length of the vector that the user inputs.
double coord_x(0.0), coord_y(0.0); //coord_x is the x coordinate value on the cartesian plane of the endpoint of the radius, and y_coord is the y value on the cartesian plane of the enpoint of the entered radius
// Read in polar coordinates
cout << "Enter radius: ";
cin >> radius;
cout << "Enter polar angle (degrees): ";
cin >> angle_degrees;
// Convert degrees to radians
angle_radians = degrees2radians(angle_degrees);
// Compute Cartesian (x,y) coordinates
compute_coord(radius, angle_radians, coord_x, coord_y);
// Output Cartesian coordinates
cout << "Cartesian coordinates: ";
cout << "(" << coord_x << "," << coord_y << ")" << endl;
return 0;
}
// DEFINE FUNCTION degrees2radians here:
double degrees2radians(double deg)
{ return deg * M_PI / 180;}
// DEFINE FUNCTION compute_coord here:
double compute_coord(double r, double angr, double & x, double & y)
{
x = r * cos(angr);
y = r * sin(angr);
}
|