Wednesday, 4 March 2015

Fahrenheit-Celsius Conversion.

Objective:
               To convert a value in fahrenheit  to degree celsius.

Approach:
               use the formula:
                                        celsius=(fahrenheit value  -32 )  x  5/9 
                                                        or
                                       celsius=(fahrenheit value-32)/1.8;
Solution:

              output for the following program will look like this:




To get this as a desired output we have to design a textfield,a button to convert and label to display.

To make it look more aesthetic i have added a background colour,set border width and corner radius for textfield by importing QuartzCore Framework and customised fonts for label.finally added decimal pad keyboard type instead of default keyboard type.

In our button action (CONVERT),we have to first declare two double values for fahrenheit and celsius and do the math
;


Save the value of the celsius in a string and show it in the label's text.









So the task is done .finally you have to disable the textfield's decimal pad keyboard.we can't do this in textfield should return method.

So add touches begin method and complete the task .



Conclusion:
                Using this same approach we can convert different metrics using their appropriate formulas.



















                                                                                       







No comments:

Post a Comment