A simple calculator application
Hello,from this post i promised to write a simple class to ease the burden on my lovely calculator and bring my mechanics issues online,and so i did.I have now completed the class and here it is.
Calculator Library.Place it in your libraries folder:
.
*
* @package Calculator
* @copyright 2006-2010 Geoffrey Keymann
* @license http://www.gnu.org/licenses/gpl.html
* @version $Id: Calculator.php 205 2010-02-07 11:33:55Z undgerman@gmail.com $
*/
class Calculator
{
function add( $num1, $num2)
{
return $num1 + $num2;
}
function subtract( $num1, $num2)
{
return $num1 - $num2;
}
function multiply( $num1, $num2)
{
return $num1 * $num2;
}
function divide( $num1, $num2)
{
return $num1 / $num2;
}
function getSine($value)
{
return sin($value);
}
function getCosine($value)
{
return cos($value);
}
function getTan($value)
{
return tan($value);
}
function getLogarithm($value)
{
return log($value);
}
function getPower($value1, $value2)
{
return pow($value1, $value2);
}
function getSqrt($value)
{
return sqrt($value);
}
function getFmod($value1, $value2)
{
return fmod($value1, $value2);
}
}
?>
Now here is the controller.Place it in your controllers folder.
.
*
* @package Calculate
* @copyright 2006-2010 Geoffrey Keymann
* @license http://www.gnu.org/licenses/gpl.html
* @version $Id: Calculate.php 205 2010-02-07 11:40:21Z undgerman@gmail.com $
*/
class Calculate extends Controller
{
function calc()
{
$this->load->library('Calculator');
$a = 20;
$b = 4;
echo("The two numbers are $a and $b
\n");
$calca = new Calculator();
$sum = $calca->add($a, $b);
$sine = $calca->getSine($a);
echo ("The sine of $a is equal to $sine
\n");
echo("Their sum is $sum
\n");
}
}
?>





