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..
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...
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 =...
IN JAVA write a program that asks a user for a maximum of 20 user-inputted elements...
IN JAVA write a program that asks a user for a maximum of 20 user-inputted elements and create an array. Then, write a Merge Sort function with recursion (in the main) that takes the user inputted elements in the array, sorts them, and prints them back.
Write a Java program that asks the user to enter an integer that is used to...
Write a Java program that asks the user to enter an integer that is used to set a limit that will generate the following four patterns of multiples of five using nested loops •Ascending multiples of five with ascending length triangle •Ascending multiples of five with descending length (inverted) triangle •Descending multiples of five with ascending length triangle •Descending multiples of five with descending length (inverted) triangle Use error checking to keep asking the user for a positive number until...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT