Engr 123 Assigned: January 27, 2016 Assignment 3 Due: February 8, 2016

advertisement
Engr 123
Assignment 3
Assigned: January 27, 2016
Due: February 8, 2016
Trigonometric functions can be written and calculated from an infinite series. For
example, the infinite series for the sine function is given by:
∞
x3 x5 x7
x 2 n +1
sin( x) = x − + − +  = ∑ (−1) n
3! 5! 7!
(2n + 1)!
n =0
where x is in radians.
Write a console program in C# to approximate the sin(x) using this series. Your program
should do the following:
1. Prompt the user to enter a value for x in degrees. Your program should check the
value of x to see that it is in the range 0 ≤ x ≤ 90. If x is outside of this range
issue an appropriate error message and prompt for a new value of x. If x is 0 print
the message "sin(0) = 0" and terminate the program.
2. Prompt the user for the number of terms. Your program should check to see that
this is in the range 0 ≤ n ≤ 80 1. If n is 0 print the message: "sin(x) = 0 for 0
terms." where x is the value entered for the number of degrees. If n is out the
range issue an appropriate error message and allow the user to reenter n.
3. Convert the number of degrees to radians and use the series for sin(x) to calculate
the approximate value. Issue the message: "sin(x) = y.yyyyyyy for n terms."
Where x is the value entered by the user for the degrees, y.yyyyyyy is the
approximate value of sin(x) to at least 7 decimal places, and n is the value entered
for the number of terms.
This is a typical run of the program showing the console output.
Enter degrees 0 to 90 ... 45
Enter number of terms 0 to 80 ... 10
The sin(45) = 0.707106781170674 for 10 terms.
Enter degrees 0 to 90 ... 45
Enter number of terms 0 to 80 ... 50
The sin(45) = 0.707106781170674 for 50 terms.
Enter degrees 0 to 90 ... 0
Press any key to continue . . .
Turn in a doc, docx, or text document containing the design for the program and a zipped
project file. Name your zipped file Asn3XXX.zip where XXX are your three initials.
Upload your zipped project file to \\cecsfp01\users\everyone\Engr123.
1
n is limited to about 80 since (2n + 1)! is larger than the largest representable double precision number.
Download