Computer Science I - Programming Assignment 3
Due Wednesday, November 4th
Summary
For this assignment you will be adding error checking, and some extra functions to your formula library from programming assignment 2
-
The RealRoot1 and ReallRoot2 function should return NaN if the first coefficient (a) is zero
or if the discriminant is less than zero.
-
The AreaOfCircle and AreaOfSphere should return NaN if the radius is less than zero.
-
The Pythagorean function should return NaN if either of the sides is less than or equal to zero.
-
Add a Factorial function that computes the factoral of a positive integer n.
This function should return NaN if n is less than 1
-
Add new functions SineApprox and CosineApprox to calculate the
sine and cosine of an angle in radians using the following formulas:
Since these are approximations you only need the first 30 terms each series.
These functions are defined on all values, so no error checking will be needed.
The functions must be implemented in a file called
formula2.js, and the tests must be implemented in a file called
formula2-test.html.
I have implemented the
Factorial function, added empty
SineApprox and
CosineApprox functions,
and updated the specifications for the old functions here:
I have also implemented a test for
SineApprox that uses a
for loop to test a large range of values here:
Helpful Hints
- π is π in HTML and Math.PI in JavaScript.
- You may use the Math.sqrt and Math.pow built-in functions in your code.
- The JavaScript special value NaN means "not a number" and is case sensitive.
- Make sure to test each of the cases that should result in an error (return NaN).
- Implement and test each function before starting on the next one. If there is a syntax error in one function it may impact the other functions as well.
Instructions for Handing In the Program
Please hand in the following:
- a printed copy of your completed formula2.js and formula2-test.html in class on the due date
- an electronic copy of these files via FileZilla in the handin folder in your home directory on the CS server.
Do not put your assignment in your html directory as that is publicly viewable.