In this lab will practice prompting the user for values, reading values as doubles from the user/keyboard into variables, using an arithmetic expression to convert the value from degrees to radians, and calculating the sine and cosine using <cmath>
functions sin()
, cos()
, and tan()
. Be sure to read this lab thoroughly, especially the Hand-in Procedure.
Write a complete program that:
Creates a global constant to hold pi (π = 3.141592).
Prompts the user to enter an angle in degrees then reads in an angle in degrees from the keyboard as a double.
Converts the angle from (2) to radians.
Computes the sine of the angle from (3) using <cmath>
.
Computes the cosine of the angle from (3) using <cmath>
.
Computes the tangent of the angle from (3) using <cmath>
.
Writes the answers from (3) (4) (5) and (6) out to the display.
The formula to convert degrees to radians is:
The prototypes for sin() and cos() are:
double sin(double x);
double cos(double x);
double tan(double x);
An example of an interaction with your program is shown below, your output should match these examples exactly.
Alexs-iMac:lab2a alex$ g++ -Wall -pedantic -Werror main.cpp Alexs-iMac:lab2a alex$ ./a.out Enter an angle value, in degrees **10 10 degrees = 0.174533 radians sin(10) = 0.173648 cos(10) = 0.984808 tan(10) = 0.176327
See CodeGrade for more examples.
Note: The line breaks after the inputs in the example output formatting above are the default ones C++’s cin
and getline()
automatically apply after reading an input from the user. CodeGrade supplies input in a different manner (Linux redirection) to programs so in CodeGrade's auto tests there will not be line breaks after the inputs.
main.cpp
. Do not ignore this step or save your file(s) with different names..cpp
file prior to the deadline to receive full credit. Any submissions after the deadline will be subject to the class’ late policy.