Question

In: Computer Science

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 will go from 0° to 90° in increments of 10°. This needs to be displayed on the screen and on a .txt file

c++


#include <iostream>
#include <iomanip>
#include <string>
#include <stdio.h>
#include <cmath>

using namespace std;


char choice;

int main()
{
float radian, degrees;
char option;

cout << "Degree or Radians [enter d or r]" << endl;  
cin >> option;
option = tolower(option);



if (option == 'r')
{

cout<<"Enter in radians: " << endl;
cin>>radian;
degrees = radian*180/M_PI;
cout << setprecision (4) << fixed;
cout<<degrees<<" degrees = " << radian<<" radians"<<endl;
cout<<" Sine: "<<sin(radian)<<endl;  
cout<<" Cosine: "<<cos(radian)<<endl;
cout<<" Tangent: "<<tan(radian);  
cout << endl;
}

else if (option == 'd')
{
  
cout<<"Enter angle in degrees: " << endl;
cin>>degrees;
radian = (degrees*M_PI)/180;
cout << setprecision (4) << fixed;
cout<<degrees<<" degrees = "<< radian <<" Radians"<<endl;
cout<<" Sine: "<<sin(radian)<<endl;
cout<<" Cosine: "<<cos(radian)<<endl;
cout<<" Tangent: "<<tan(radian);
cout << endl;
}
else  

{
cout << "incorrect option." << endl;
}

cout << endl << endl;


system("pause");
return 0; // return 0
  
}

Solutions

Expert Solution

Code

#include <iostream>

#include <iomanip>

#include <string>

#include <stdio.h>

#include <cmath>

#include<fstream>

using namespace std;

int main()

{

  const int START_DEGREE = 0;

  const int END_DEGREE = 90;

  const int INCREMENT = 10;

  float radian;

  ofstream out("a.txt");

  out << setprecision(4) << fixed;

out.width(15);out<<left<<"Degree";

out.width(15);out<<left<<"Sine";

out.width(15);out<<left<<"Cosine";

out<<left<<"Tangent"<<endl;

  for (int i = START_DEGREE; i <= END_DEGREE; i += INCREMENT)

  {

    out.width(15);out<<left<<i;

out.width(15);out<<left<<sin(i);

out.width(15);out<<left<<cos(i);

out<<left<<tan(i)<<endl;

  }

out.close();

}

Output

a.txt

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.


Related Solutions

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,...
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...
Write a program that asks the user to enter five test scores. The program should display...
Write a program that asks the user to enter five test scores. The program should display a letter grade for each score and the average test score. Write the following methods in the program: calcAverage: This method should accept five test scores as arguments and return the average of the scores. determineGrade: This method should accept a test score as an argument and return a letter grade for the score, based on the following grading scale: Score Letter Grade 90-100...
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 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 C++ program that finds the minimum number entered by the user .The user is...
Write a C++ program that finds the minimum number entered by the user .The user is allowed to enter negative numbers 0, or positive numbers. The program should be controlled with a loop statement. Break statements is not allowed to break from loop. After each number inputted by the user, The program will prompt user if they need to enter another number. User should enter either Y for yes or N for no. Make Sure the user enters either Y...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT