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

Write a program that allows the user to convert between radians and degrees. You

ID: 3631308 • Letter: W

Question

Write a program that allows the user to convert between radians and degrees. You MUST define the following two functions:

double rad2deg(double);
double deg2rad(double);
Continuously prompt the user to select an option as specified in the examples below. Option c prints Exiting. and ends the program.

Constraints:

Ensure that you display 8 digits after the decimal point
Use the constant M_PI as your pi value. It is included with the <cmath> library.
Examples:

Choose a conversion
a) Convert radians to degrees
b) Convert degrees to radians
c) Exit
a
Enter radians: 2.567
2.567 radians in degrees is 147.07826601

Choose a conversion
a) Convert radians to degrees
b) Convert degrees to radians
c) Exit
b
Enter degrees: 60.8
60.8 degrees in radians is 1.06116019

Choose a conversion
a) Convert radians to degrees
b) Convert degrees to radians
c) Exit
4
Incorrect Option. Try again.

Choose a conversion
a) Convert radians to degrees
b) Convert degrees to radians
c) Exit
c
Exiting.

In C++

Explanation / Answer

#include <iostream>

#define _USE_MATH_DEFINES

#include <cmath>

using namespace std;

int main()

{

   //PROTOTYPES

   double rad2deg(double rad);

   double deg2rad(double degree);

   //LOCAL DECLARATIONS

   char choice;

   double input;

   //PROCEDURES

   do

   {

      cout << "Choose a conversion "

           << "a) Convert radians to degrees "

           << "b) Convert degrees to radians "

           << "c) Exit ";

      cin >> choice;

      cin.ignore();

      if (toupper(choice) == 'A')

      {

         cout << "Enter radians: ";

         cin >> input;

         cin.ignore();

         cout << input << " radians in degrees is " << rad2deg(input) << endl;

      }

      else if (toupper(choice) == 'B')

      {

         cout << "Enter degrees: ";

         cin >> input;

         cin.ignore();

         cout << input << " degrees in radians is " << deg2rad(input) << endl;

      }

      else if (toupper(choice) == 'C')

      {

         cout << "Exiting. ";

      }

      else

      {

         cout << "Incorrect Option. Try again. ";

      }

      cout << endl;

   } while (toupper(choice) != 'C');

   cin.get();

   return 0;

}

//---------------------------------------------------------

// FUNCTION DEFINITIONS

//---------------------------------------------------------

double rad2deg(double rad)

{

   return rad / M_PI * 180;

}

//---------------------------------------------------------

double deg2rad(double degree)

{

   return degree / 180 * M_PI;

}

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