Posted by : Unknown
domingo, 23 de noviembre de 2014
SDP04 Project 01
Square Root of Two
November 21st, 2014
After solving the before four exercises, we could solve the first SDP04 project
that could only be solved applying the previous knowledge and abilities (also examples).
In this project we started with an application that solved the square root of the number two (2), nevertheless, there are some things that we've got to change in order to get our application solve square root of other numbers using the Newton's method.
When we had just started to read the problem, we noticed that the problem was working effectively in some situations but, on the other hand, the results were wrong when we wrote numbers that have a exact square root.
Our instructor gave us some advices to notice what we had got to do.
The first thing that we did was to modify the UNumber class by adding a public method named sqr with a parameter named decimales.
We modified the three first variables changing the mantissa, the characteristic, and the sign, for example; creating the variable sig, we noticed that it was necessary to change values in the constructor because the number in the characteristic depends on decimales parameter.
We also need precision, so that we added ten units to each line in which we used the variable decimales.
Then, we wrote the code that we've been using to calculate the Square Root according to Newton's method. We only had to change some values using the variables dp (that's named after decimal point), s (that's named after sign), and d (according to the mantissa dimension).
Once done this, we create an object from UNumber class into TestMainline class to call
the method that we created in UNumber class, remembering that we have modified the method and we have to give a type int parameter on calling the method.
We finally wrote a line that shows the result of the operation onto the screen.
After that, we proved the app and we noticed that it works correctly, now it doesn't only calculates the square root of two but of other numbers, this was thanks to the variable decimales that helps the computer to calculate the solution for a lot of numbers, giving the most close numbers as result .