Answer to Question #96981 in C++ for Katie Harns

Question #96981
Write a program to display a table of sin(x) and cos(x) function values:
a sin(a) cos(a)
==============================
0.0 xxx.xxxx xxx.xxxx
30.0 xxx.xxxx xxx.xxxx
45.0 xxx.xxxx xxx.xxxx
60.0 xxx.xxxx xxx.xxxx
90.0 xxx.xxxx xxx.xxxx
------------------------------
where column “a” has angle values in degree; columns “sin(a)” and “cos(a)” give respective function values of each angle. The first column has a fixed width of 6 character spaces, and the angles are displayed with one decimal digit. The second and the third columns have a fixed width of 12 character spaces each, and the function values are calculated by using sin() and cos() functions from the <cmath> library and the values are displayed with four decimal digits. All columns should be right-justified.
1
Expert's answer
2019-10-21T14:11:35-0400
#include <iostream>
#include <iomanip>
#include <cmath>
#define M_PI  3.14159265358979323846

using namespace std;

int main()
{
  double a=0.0;
  cout<<"=================="<<endl;
cout<<fixed<<setprecision(1)<<a<<"\t"<<setprecision(4)<<sin(a*M_PI/180)<<"\t"<<cos(a*M_PI/180)<<endl;

a=30.0;
cout<<fixed<<setprecision(1)<<a<<"\t"<<setprecision(4)<<sin(a*M_PI/180)<<"\t"<<cos(a*M_PI/180)<<endl;

a=45.0;
cout<<fixed<<setprecision(1)<<a<<"\t"<<setprecision(4)<<sin(a*M_PI/180)<<"\t"<<cos(a*M_PI/180)<<endl;

a=60.0;
cout<<fixed<<setprecision(1)<<a<<"\t"<<setprecision(4)<<sin(a*M_PI/180)<<"\t"<<cos(a*M_PI/180)<<endl;

a=90.0;
cout<<fixed<<setprecision(1)<<a<<"\t"<<setprecision(4)<<sin(a*M_PI/180)<<"\t"<<cos(a*M_PI/180)<<endl;
 cout<<"——————————";
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS