Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Add functions and function prototypes to the file polarcoord.cpp as specified be

ID: 3759440 • Letter: A

Question

Add functions and function prototypes to the file polarcoord.cpp as specified below. When completed, the program reads in the polar coordinates of a point and computes and outputs the Cartesian coordinates. The main() routine of the program is already provided in polarcoord_template.cpp. DO NOT MODIFY ANY OF THE CODE in procedure main(). Your task is to add two functions, degrees2radians() and compute_coord(), so that the program produces the desired results.

Program polarcoord.cpp: a. 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 × /180 where D is degrees and R is radians. b. 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 listed in the following order: i. the polar radius of the point, ii. the polar angle in radians of the point, iii. the x-coordinate of the point, iv. the y-coordinate of the point. All parameters should have type double. The first two parameters should be passed by value and the last two parameters should be passed by reference. The function does not return any value, but it modifies the last two parameters. 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 xcoordinate and y is the y-coordinate of the point.

polarcoord.cpp template

#include <iostream>
#include <cmath>

using namespace std;

// FUNCTION PROTOTYPE FOR degrees2radians


// FUNCTION PROTOTYPE FOR compute_coord


// DO NOT MODIFY THE MAIN ROUTINE IN ANY WAY
int main()
{
double angle_degrees(0.0), angle_radians(0.0), radius(0.0);
double coord_x(0.0), coord_y(0.0);

// 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:


// DEFINE FUNCTION compute_coord here:

Explanation / Answer

#include <iostream>

#include <cmath>

using namespace std;

// FUNCTION PROTOTYPE FOR degrees2radians

double degrees2radians(double angle);

// FUNCTION PROTOTYPE FOR compute_coord

double compute_coord(double radius, double angle_radians, double& coord_x, double& coord_y);

// DO NOT MODIFY THE MAIN ROUTINE IN ANY WAY

int main()

{

  

double angle_degrees(0.0), angle_radians(0.0), radius(0.0);

  

double coord_x(0.0), coord_y(0.0);

  

// 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 angle){

  

double radians;

  

radians = angle * (3.141592654/180);

  

return radians;

  

}

// DEFINE FUNCTION compute_coord here:

double compute_coord(double radius, double angle_radians, double& coord_x, double& coord_y){

  

coord_x = radius * cos(angle_radians);

  

coord_y = radius * sin(angle_radians);

  

return coord_x,coord_y;

  

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote