Question: Trigonometric Table Using the C++ math functions of sin, cos, and tan produce a formatted table of Sine, Cosine, and Tangent. The table should go
Trigonometric Table
Using the C++ math functions of sin, cos, and tan produce a formatted table of Sine, Cosine, and Tangent. The table should go from 0 to 360-degrees in steps of 10-degrees. You will need to use a loop for this homework.
To use the math functions please add the following include file to the top of your source file:
#include
This will add the function definitions for cos, sin, tan which are as follows:
double sin(x);
double cos(x);
double tan(x);
Where x is an angle in radians.
To convert from radians to degrees use this expression:
angle_in_radians = angle_in_degrees * PI / 180.0;
Sine Example: cout << sin(angle_in_radians) << endl;
For formatting you will need the advanced cout formatting flags/functions to format the table correctly.
Brief formatting
Add the proper header file after #include
#include
to include these functions and flags.
You will be using the fixed, noshowpoint, showpoint, setw, and setprecision flags. Here are some examples. To output a float/double number with a fixed width of eight and four digits after the decimal point use the following:
double x = 1243.333333;
cout << fixed << setw(8) << setprecision(4) << x << endl;
Prints: 1243.3333
To output a float/double number with a fixed width of eight and no decimal point:
double x = 1243.333333;
cout << fixed << setw(8) << setprecision(0) << x << endl;
Prints: 1243
Sample Program Output:
This table uses the following formatting characteristics:
For Sine and Cosine use a width of 10 and a precision of 4
For Tangent use a width of 25 and a precision of 4
Degrees Sine Cosine Tangent
0 0.0000 1.0000 0.0000
10 0.1736 0.9848 0.1763
20 0.3420 0.9397 0.3640
30 0.5000 0.8660 0.5774
40 0.6428 0.7660 0.8391
50 0.7660 0.6428 1.1918
60 0.8660 0.5000 1.7321
70 0.9397 0.3420 2.7475
80 0.9848 0.1736 5.6713
90 1.0000 0.0000 16331239353195370.0000
100 0.9848 -0.1736 -5.6713
110 0.9397 -0.3420 -2.7475
120 0.8660 -0.5000 -1.7321
130 0.7660 -0.6428 -1.1918
140 0.6428 -0.7660 -0.8391
150 0.5000 -0.8660 -0.5774
160 0.3420 -0.9397 -0.3640
170 0.1736 -0.9848 -0.1763
180 0.0000 -1.0000 -0.0000
190 -0.1736 -0.9848 0.1763
200 -0.3420 -0.9397 0.3640
210 -0.5000 -0.8660 0.5774
220 -0.6428 -0.7660 0.8391
230 -0.7660 -0.6428 1.1918
240 -0.8660 -0.5000 1.7321
250 -0.9397 -0.3420 2.7475
260 -0.9848 -0.1736 5.6713
270 -1.0000 -0.0000 5443746451065123.0000
280 -0.9848 0.1736 -5.6713
290 -0.9397 0.3420 -2.7475
300 -0.8660 0.5000 -1.7321
310 -0.7660 0.6428 -1.1918
320 -0.6428 0.7660 -0.8391
330 -0.5000 0.8660 -0.5774
340 -0.3420 0.9397 -0.3640
350 -0.1736 0.9848 -0.1763
360 -0.0000 1.0000 -0.0000
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
