Example #1
0
        return $a - $b;
    }
    public function division($a, $b)
    {
        $this->checkParams($a, $b);
        sleep(8);
        if ($b === 0) {
            throw new RuntimeException('Division by 0');
        }
        return $a / $b;
    }
    public function calculDivers($a, $b)
    {
        return $this->division($this->soustraction($a, $b), $this->somme($a, $b));
    }
    public function checkParams()
    {
        foreach (func_get_args() as $arg) {
            if (is_numeric($arg) === false) {
                throw new RuntimeException('NaN');
            }
        }
    }
    public static function main()
    {
        $calculator = new self();
        echo $calculator->calculDivers(5, 10);
    }
}
Calculatrice::main();
Example #2
0
/*
 * Multiplication
 * */
//$Calc->setValeurs([3,3]);
//echo "3x3=".$Calc->multiplication()."<br>";
//$Calc->setValeurs([4,2]);
//echo "4/2=".$Calc->division()."<br>";
?>

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="">
    <title>Calculatrice</title>
</head>
<body>
    <?php 
echo Vue::formulaire();
if (isset($_POST['ok']) && !empty($_POST['numbers']) && !empty($_POST['calcul'])) {
    $v = explode(',', $_POST['numbers']);
    $calc = new Calculatrice($v);
    $res = $calc->calculer($_POST['calcul']);
    echo 'Resultat : ' . $res;
}
?>
</body>
</html>


Example #3
0
 function somme($a, $b)
 {
     $c = Calculatrice::somme($a, $b);
     return $c;
 }