Write a class that calculates the sum: 11*1- 12*2 + 13*3 - 14*4 + 15*5 - 16*6 ...
Follow the algorithm:
1. Initialize the sum to 0 and the first term to 1.
2. If the absolut value of next term >= 0.000001 do the next two steps:
2.1 Add next term to the sum.
2.2 Calculate a new next term.
Every term in the sum is on the form 1/(k*k), where k increaces by one for each step. Set a variable to keep track of if the next term is negative or positive. When the program is run the sum will be 0.82247.
If the operator abs is used outside a when clause, state events are triggered. If this is not desired, the noEvent function can be applied to it.
When the program is run the sum will be 0.82247 and it will calculate the sum of: 11*1- 12*2 + 13*3 - 14*4 + 15*5 ... - 11001*1001