In: Computer Science
Have an option for Degrees or Radians.
If Radians
Write a program that asks the user for an angle, entered in radians. The program should then display the radian as a degree and display sine, cosine, and tangent of the angle. (Use the sin, cos, and tan library functions to determine these values.) The output should be displayed in fixed-point notation, rounded to four decimal places of precision.
If Degrees
Write a program that asks the user for an angle, entered in degrees. The program should then display the degree as a radian and display, sine, cosine, and tangent of the angle. (Use the sin, cos, and tan library functions to determine these values.) The output should be displayed in fixed-point notation, rounded to four decimal places of precision.
for C++
Code:
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int main()
{
   float radians,degrees;
   int choice;/*Declaring variables*/
   cout<<"1.Radians to degrees"<<endl;
   cout<<"2.Degrees to radians"<<endl;
   cout<<"Enter your Choice: ";
   /*Displaying menu to the user*/
   cin>>choice;/*Here we read users choice*/
   switch(choice)
   {
       case 1:/*When user choice is 1 we
convert radians to degrees*/
          
cout<<"Enter radian to convert into degrees: ";
          
cin>>radians;/*Reading user input*/
          
degrees=radians*180/M_PI;/*HEre we convert into degrees*/
          
cout<<setprecision(4)<<radians<<" radians =
"<<degrees<<"Degrees"<<endl;
          
cout<<setprecision(4)<<"Sin("<<degrees<<")="<<sin(degrees)<<endl;
          
cout<<setprecision(4)<<"cos("<<degrees<<")="<<cos(degrees)<<endl;
          
cout<<setprecision(4)<<"tan("<<degrees<<")="<<tan(degrees);  
           break;/*HEre we
print the sin cos and tan values*/
       case 2:/*When user choice is 2 we
convert degrees to radians*/
          
cout<<"Enter degrees to convert into radians: ";
          
cin>>degrees;/*Reading the user input*/
          
radians=degrees*M_PI/180;
          
cout<<setprecision(4)<<degrees<<" degrees =
"<<radians<<" Radians"<<endl;
          
cout<<setprecision(4)<<"Sin("<<radians<<")="<<sin(radians)<<endl;
          
cout<<setprecision(4)<<"cos("<<radians<<")="<<cos(radians)<<endl;
          
cout<<setprecision(4)<<"tan("<<radians<<")="<<tan(radians);  
           break;/*HEre we
print the sin cos and tan values*/
       default:
          
cout<<"Invalid input";
          
break;      
   }
}
Output:


Indentation:
