Question

In: Computer Science

Have an option for Degrees or Radians. If Radians Write a program that asks the user...

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++

Solutions

Expert Solution

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:


Related Solutions

Write a program that asks the user for an angle, entered in radians. The program should...
Write a program that asks the user for an angle, entered in radians. The program should then display the 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 Take your previous Angle Calculator program and modify it to do a table of trig values. The columns will be: Degrees, Sine, Cosine, Tangent,. And the rows...
Write a program that asks the user for an integer. The program checks and prints to...
Write a program that asks the user for an integer. The program checks and prints to the screen whether the number is prime or not. For example, if user enters 17, the program should print “17 is prime”; if the user enters 20, the program should print “20 is not prime”. please do it with a “ while Loop”, Thanks..
Python: Write a program that asks the user for the name of a file. The program...
Python: Write a program that asks the user for the name of a file. The program should display the contents of the file line by line.
Write a java program to convert Celsius degrees to Fahrenheit degrees the user enters degrees in...
Write a java program to convert Celsius degrees to Fahrenheit degrees the user enters degrees in Celsius and the program Coverts the input to Fahrenheit using the following formula T(°F) = T(°C) × 1.8 + 32 submit the source code Design output Load: 1. Design (Pseudocode ) 2. Source file (Java file, make sure to include comments) 3. Output file (word or pdf or jpig file)
Write a program that asks the user to enter the name of a file, and then...
Write a program that asks the user to enter the name of a file, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the file. Use Notepad or another text editor to create a sample file that can be used to test the program. Sample Run java FileLetterCounter Enter file name: wc4↵ Enter character to count: 0↵ The character '0' appears in the file...
Write a program that asks the user for the lengths of the sides of a rectangle....
Write a program that asks the user for the lengths of the sides of a rectangle. Again, check for valid input and exit with an error msg if you don’t get it. Testing: use some known values to confirm that the calculations are correct. E.g. 3 – 4 - 5 triangle >> 3 X 4 rectangle Then print • The area and perimeter of the rectangle • The length of the diagonal (use the Pythagorean theorem). This question should be...
This is Java In this problem we will write a program that asks the user to...
This is Java In this problem we will write a program that asks the user to enter a) The user's first name and b) a series of integers separated by commas. The integers may not include decimal points nor commas. The full string of numbers and commas will not include spaces either, just digits and commas. An example of valid input string is:        7,9,10,2,18,6 The string must be input by the user all at once; do not use a loop...
Write a program IN JAVA that asks the user for a number. The program should check...
Write a program IN JAVA that asks the user for a number. The program should check the number to ensure that it is valid (if not, the user should enter a valid number to continue.) The program should print out all of the prime numbers from 2 up to the number, with up to 10 numbers per line. (Recall: A prime number is a number that is only divisible by itself and 1.) The code should ask the user if...
Program should be written in Java a) Write a program that asks the user to enter...
Program should be written in Java a) Write a program that asks the user to enter the approximate current population of India. You should have the computer output a prompt and then YOU (as the user should enter the population.)  For testing purposes you may use the value of 1,382,000,000 from August 2020. Assume that the growth rate is 1.1% per year. Predict and print the predicted population for 2021 and 2022. The printout should include the year and the estimated...
Tail of a File, C++ Program. write a program that asks the user for the name...
Tail of a File, C++ Program. write a program that asks the user for the name of a text file. The program should display the last 10 lines, or all lines if less than 10. The program should do this using seekg Here is what I have so far. #include<iostream> #include<fstream> #include<string> using namespace std; class File { private:    fstream file;    string name; public:    int countlines();    void printlines(); }; int File::countlines() {    int total =...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT