Exemplo n.º 1
0
 public static function exec($Operation)
 {
     $X = new Calc();
     $X->setOperation($Operation);
     $X->run();
     return $X->getResult();
 }
Exemplo n.º 2
0
 function __construct($v)
 {
     if (is_array($v)) {
         $this->values = $v;
         $this->saved_values = $this->values;
         $this->label = '[' . implode(', ', $v) . ']';
     } else {
         $this->label = $v;
         preg_match('%^(?P<multiple>\\d*)\\[(?P<set>[^\\]]+)\\]$%i', $v, $matches);
         $v = $matches['set'];
         $values = explode(',', $v);
         for ($z = 0; $z < max(1, intval($matches['multiple'])); $z++) {
             foreach ($values as $v) {
                 $this->values[] = $v;
             }
         }
         $this->saved_values = $this->values;
         foreach ($this->values as $k => $v) {
             $calc = new Calc($v);
             $this->values[$k] = $calc->calc();
         }
         foreach ($this->values as $k => $value) {
             $calc = new Calc($value);
             $this->values[$k] = $calc->calc();
         }
     }
 }
Exemplo n.º 3
0
 public function actionKira()
 {
     $model = new Calc();
     if (isset($_POST['Calc'])) {
         $model->attributes = $_POST['Calc'];
         $model->total = $model->field1 + $model->field2;
         if ($model->save()) {
             $this->redirect(array('kira', 'id' => $model->id));
         }
     }
     $this->render('kira', array('model' => $model));
 }
Exemplo n.º 4
0
 function _calc($params)
 {
     $user = $params['user'];
     $channel = $params['channel'];
     $query = $params['query'];
     $query = html_entity_decode($query);
     $calc = new Calc($query);
     echo htmlspecialchars($expression) . "\n";
     echo $calc->infix() . " = " . $calc->calc() . "\n";
     $output = Utils::cmdout($params);
     $output .= $calc->infix() . " = " . $calc->calc();
     Status::create()->data($output)->user_id($user->id)->channel($channel)->insert();
     return true;
 }
Exemplo n.º 5
0
 public function calcget($year, $month)
 {
     $temps = "";
     if ($year % 400 == 0 || $year % 4 == 0 && $year % 100 != 0) {
         $monthDay = array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
     } else {
         $monthDay = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
     }
     if (Calc::where('year', '=', $year)->where('month', '=', $month)->count() > 0) {
         for ($i = 1; $i < $monthDay[$month - 1] + 1; $i++) {
             if (Calc::where('year', '=', $year)->where('month', '=', $month)->where('day', '=', $i)->count() > 0) {
                 $calc = Calc::where('year', '=', $year)->where('month', '=', $month)->where('day', '=', $i)->get();
                 for ($y = 0; $y < count($calc); $y++) {
                     $temps[] = $calc[$y]->commit;
                 }
                 $temp = implode("\\n", $temps);
                 $export[] = array("year" => $year, "month" => $month, "day" => $i, "commit" => urlencode($temp));
             } else {
                 $export[] = array("year" => $year, "month" => $month, "day" => $i, "commit" => " ");
             }
             $temps = "";
         }
     } else {
         $export[] = array("year" => " ", "month" => " ", "day" => " ", "commit" => " ");
     }
     return urldecode(json_encode($export));
 }
Exemplo n.º 6
0
 /**
  * @dataProvider additionProvider
  */
 public function testAdd2($a, $b, $expected)
 {
     $calc = new Calc();
     $result = $calc->add($a, $b);
     $this->assertEquals($expected, $result);
 }
Exemplo n.º 7
0
Arquivo: onp.php Projeto: rn0/php-calc
            if ($token instanceof Number) {
                $tempStack->push($token);
            } elseif ($token instanceof Operator || $token instanceof Funct) {
                /** @var $token Operator|Funct */
                if ($tempStack->count() < $token->numOfArgs()) {
                    throw new Exception(sprintf('Required %d arguments, %d given.', $token->numOfArgs(), $tempStack->count()));
                }
                $arg = $tempStack->popMultiple($token->numOfArgs());
                $tempStack->push($token->execute(array_reverse($arg)));
            }
        }
        return $tempStack->pop()->value;
    }
    public function evaluate()
    {
        $this->convertToRpn();
        return $this->process();
    }
}
/**
 * sin(PI/2+2*PI)+cos(2*2*PI)+tg(2*PI)+ctg(PI/2+2*PI)+2^2/2-2+2*2-4 + ((2+2)*2-(4/2*2)*2) =
 * 1 + 1 + 0 + 0 + 0
*/
$ret = null;
try {
    $calc = new Calc($_GET['expression']);
    $ret = $calc->evaluate();
} catch (Exception $e) {
    $ret = $e->getMessage();
}
echo json_encode(array('result' => $ret));
Exemplo n.º 8
0
<?php

include 'Calc.php';
echo Calc::sum_3_5(1000);
echo "\n";
Exemplo n.º 9
0
}
/* Line 840 of lalr1.php  */
/* Line 94 of "calc.y"  */
class Position
{
    public $line;
    public $token;
    public function __construct($l = 0, $t = 0)
    {
        $this->line = $l;
        $this->token = $t;
    }
    public function equals(Position $l)
    {
        return $l->line == $this->line && $l->token == $this->token;
    }
    public function __toString()
    {
        return $this->line . "." . $this->token;
    }
    public function lineno()
    {
        return $this->line;
    }
    public function token()
    {
        return $this->token;
    }
}
$p = new Calc(STDIN, new Exception());
$p->parse();
/*
可以灵活的模拟像Java中的函数重载的效果
*/

class Calc{
	public function area(){
		//判断一个调用area时,得到的参数个数
		$args = func_get_args();
		if(count($args) == 1){
			return 3.14 * $args[0];
		}else if(count($args) == 2){
			return $args[0] * $args[1];
		}else{
			return '未知图形<br />';
		}

	}
}


//计算面积
$cal = new Calc();
echo $cal->area();
echo '<br/>';
echo $cal->area(8.88);
echo '<br/>';
echo $cal->area(77, 88);

?>
Exemplo n.º 11
0
 /**
  * Compares two dates
  *
  * @param int $day1
  *        	the day of the month
  * @param int $month1
  *        	the month
  * @param int $year1
  *        	the year. Use the complete year instead of the
  *        	abbreviated version. E.g. use 2005, not 05.
  *        	Do not add leading 0's for years prior to 1000.
  * @param int $day2
  *        	the day of the month
  * @param int $month2
  *        	the month
  * @param int $year2
  *        	the year. Use the complete year instead of the
  *        	abbreviated version. E.g. use 2005, not 05.
  *        	Do not add leading 0's for years prior to 1000.
  *        	
  * @return int 0 if the dates are equal. 1 if date 1 is later, -1 if
  *         date 1 is earlier.
  *        
  * @access public
  * @static
  *
  */
 static function compareDates($day1, $month1, $year1, $day2, $month2, $year2)
 {
     $ndays1 = Calc::dateToDays($day1, $month1, $year1);
     $ndays2 = Calc::dateToDays($day2, $month2, $year2);
     if ($ndays1 == $ndays2) {
         return 0;
     }
     return $ndays1 > $ndays2 ? 1 : -1;
 }
Exemplo n.º 12
0
$var = subtract(1, 2);
$var2 = returnArray() + 3;
for ($i = 0; $i < $var2; $i++) {
    echo $i;
}
class Calc
{
    public $val = "";
    public $val2 = "";
    public function add()
    {
        echo $this->val + $this->val2;
    }
    public function subtract()
    {
        echo $this->val - $this->val2;
    }
}
$abc = new Calc();
$abc2 = new Calc();
$abc->val = 1;
$abc->val2 = 3;
$abc->add();
$abc->subtract();
//MVC
//Model -> Class Based (Data Sent and Receive)
//View
//Controller -> Class Based (Listen User Requests) M > C = 2 C -> View (USer)
//Essamamdani.com
//Controller
// View---- ----- Model
Exemplo n.º 13
0
<?php

include_once "Calc.php";
if (count($argv) < 3) {
    echo "Usage: 'power.php \$x \$y'\n";
    exit;
}
echo Calc::power((int) $argv[1], (int) $argv[2]);
echo "\n";
Exemplo n.º 14
0
        $this->input1 = (int) $number;
    }
    function setInput2($number)
    {
        $this->input2 = (int) $number;
    }
    function calculate()
    {
        $this->output = $this->input1 * $this->input2;
    }
    function getResult()
    {
        return $this->output;
    }
}
$ex = new Calc();
$ex->setInput1(5);
$ex->setInput2(20);
$ex->calculate();
$ex->getResult();
// if I tries to get the result but just calling the variable $ex->$output
// it throws an error since it is a private variable
//
// A Private variable is one that is only alailable to the class itself...
// however the protected variable is available to the class and all of
// the children classes
// this is a brief example of how the extended class can use the input2
// variable however I still need a function in this new class to return it
// outside the class.
class Test extends Calc
{
Exemplo n.º 15
0
<?php

session_start();
include '../modal/calcClass.php';
$screen = $_POST['screen'];
if ($screen == "NULL") {
    $screen = 0;
}
$add = $_POST['add'];
$calc = new Calc($screen, $add);
if ($add == "is") {
    $antwoord = $calc->berekenen();
} elseif ($add == "del") {
    $antwoord = $calc->verwijder();
} else {
    $antwoord = $calc->toevoegen();
}
$_SESSION['antwoord'] = $antwoord;
header('Location: ../../../?function=calculator');
Exemplo n.º 16
0
 /**
  * translate from width and ratio to dimension
  *
  * @param int $width width of the rectangular dimension
  * @param float $factor a factor to determine height.
  *        bool False to omit height
  * @param string $scale_model model of scaling property
  * @return rendered dimension
  */
 public static function &fromWidth($width, $factor = FALSE, $scale_model = FALSE)
 {
     // validate parameter
     if (!self::isInt($width)) {
         throw new DimensionError('First parameter must be integer or integer string');
         return NULL;
     } elseif ($factor !== FALSE && !is_numeric($factor)) {
         throw new DimensionError('Second parameter must be a number');
         return NULL;
     }
     // render dimension
     $d = new Dimension();
     $d->width = $width;
     if ($factor !== FALSE) {
         $d->height = Calc::rectHeight($width, $factor);
     }
     $d->factor = $factor;
     $d->scale_model = $scale_model;
     return $d;
 }
Exemplo n.º 17
0
 public function testDivisao()
 {
     $calc = new Calc();
     $this->assertTrue($calc->div(6, 2) == 3, "Falha ao dividir");
 }
Exemplo n.º 18
0
<?php

/*重载*/
header('Content-Type:text/html;charset=utf-8');
class Calc
{
    public function area()
    {
        $args = func_get_args();
        if (count($args) == 0) {
            echo '至少传一个参数';
        }
        if (count($args) == 1) {
            echo 3.14 * $args[0];
        }
    }
}
$c = new Calc();
$c->area(10);
Exemplo n.º 19
0
 /**
  * Set the span from the elapsed time between two dates.
  *
  * Set the span from the elapsed time between two dates. The time span
  * is allways positive, so the date's order is not important.
  *
  * @param
  *        	object Date $date1 First Date.
  * @param
  *        	object Date $date2 Second Date.
  *        	
  * @return bool True on success.
  *        
  * @access public
  */
 function setFromDateDiff($date1, $date2)
 {
     if (!is_a($date1, 'date') or !is_a($date2, 'date')) {
         return false;
     }
     $date1->toUTC();
     $date2->toUTC();
     if ($date1->after($date2)) {
         list($date1, $date2) = array($date2, $date1);
     }
     $days = Calc::dateDiff($date1->getDay(), $date1->getMonth(), $date1->getYear(), $date2->getDay(), $date2->getMonth(), $date2->getYear());
     $hours = $date2->getHour() - $date1->getHour();
     $mins = $date2->getMinute() - $date1->getMinute();
     $secs = $date2->getSecond() - $date1->getSecond();
     $this->setFromSeconds($days * 86400 + $hours * 3600 + $mins * 60 + $secs);
     return true;
 }
Exemplo n.º 20
0
 public function calc($expression)
 {
     return Calc::calc($expression);
 }
Exemplo n.º 21
0
<?php

include 'Calc.php';
echo Calc::sum_3_4(1000);
echo "\n";
Exemplo n.º 22
0
<?php

class Calc
{
    static function log($num)
    {
        if ($num < 0) {
            throw new Exception('Logaritmo de un ' . 'negativo es indefinido');
        } else {
            return log($num);
        }
    }
}
try {
    Calc::log(-15);
} catch (Exception $e) {
    echo $e->getMessage();
}
Exemplo n.º 23
0
?>
">
<input type="submit" value="Calc">
</form>
<style type="text/css">
s {
	color: #999;
}
.true {
	color: green;
	font-weight: bold;
}
.false {
	color: #999;
}
</style>

<pre><?php 
include 'calc.php';
$expression = $_GET['expression'];
$calc = new Calc($expression);
echo htmlspecialchars($expression) . "\n";
echo $calc->infix();
echo " => ";
echo $calc->calc() . "\n";
?>
</pre>

  </body>
</html>
Exemplo n.º 24
0
 public function ActualAPR($amount, $closingCost, $interest, $length, $periodPayment)
 {
     if ($amount <= 0) {
         return 0;
     }
     if ($closingCost == $amount) {
         return 0;
     }
     if ($closingCost == 0) {
         return $interest;
     }
     $totalAmount = $amount - $closingCost;
     $aprA = $interest;
     $aprB = $interest;
     $aprX = 0;
     do {
         $aprA = $aprA / 2;
         $payment = Calc::PeriodPayment($totalAmount, $aprA, $length);
     } while ($payment > $periodPayment);
     do {
         $aprB = $aprB * 2;
         $payment = Calc::PeriodPayment($totalAmount, $aprB, $length);
     } while ($payment < $periodPayment);
     do {
         $aprX = ($aprA + $aprB) / 2;
         $payment = Calc::PeriodPayment($totalAmount, $aprX, $length);
         if ($payment > $periodPayment) {
             $aprB = $aprX;
         } else {
             $aprA = $aprX;
         }
     } while (abs($payment - $periodPayment) > 0.001);
     return $aprX;
 }
Exemplo n.º 25
0
 public function test_add()
 {
     $calc = new Calc();
     $this->assertEquals(3, $calc->add(1, 2));
 }