国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Overall code display

1,Project directory

微信圖片_20180309123704.png

##2,All code display:

index.php:

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>圖形計(jì)算器</title>
    <style>
        * {
            margin: 0px;
            padding: 0px;
        }
        #contains {
            width: 500px;
            margin: 20px auto;
            background: skyblue;
            text-align: center;
        }
        h1 {
            width: 500px;
            height: 60px;
        }
        a {
            font-size: 20px;
            text-decoration: none;
        }
        #footer {
            width: 300px;
            background: #fff;
            margin: 0 auto;
            padding: 5px 10px;
            border-radius: 150px;
        }
    </style>
</head>
<body>
<div id="contains">
    <h1>簡(jiǎn)易圖形計(jì)算器</h1>
    <a href='index.php?action=rect'>矩形</a> |
    <a href='index.php?action=triangle'>三角形</a> |
    <a href='index.php?action=cirle'>圓形</a> |
    <a href='index.php?action=sphere'>球體</a>
    <hr>
    <?php
    ini_set("display_errors", "On"); //開(kāi)啟錯(cuò)誤調(diào)試
    //設(shè)置錯(cuò)誤報(bào)告的級(jí)別,除了無(wú)關(guān)緊要的'注意',其他的報(bào)告都輸出
    error_reporting(E_ALL & ~E_NOTICE);
    function __autoload($classname) { //魔術(shù)方法 自動(dòng)加載類(lèi)
        require "./$classname.class.php"; //將類(lèi)名轉(zhuǎn)化成小寫(xiě)
    }
    if (!empty($_GET['action'])) {
        //  echo "傳送成功";
        $classname = ucfirst($_GET['action']);
        $shape = new $classname($_POST);
        $shape->view($_POST);
        if (isset($_POST['sub'])) {
            echo "<div id='footer'>";
            if($shape->name!='球體'){
            if ($shape->yan($_POST)) {
                echo "<b>".$shape->name."的周長(zhǎng)".$shape->zhou()."</b>"."<br>";
                echo "<br>";
                echo "<b>".$shape->name."的面積".$shape->area()."</b>"."<br>";
            }else {
                echo "<b>錯(cuò)誤:$shape->error</b>";
            }
            echo "</div>";
            }else{
                if ($shape->yan($_POST)) {
                    echo "<b>".$shape->name."的表面積".$shape->area()."</b>"."<br>";
                    echo "<br>";
                    echo "<b>".$shape->name."的體積".$shape->zhou()."</b>"."<br>";
                }else {
                    echo "<b>錯(cuò)誤:$shape->error</b>";
                }
                echo "</div>";
            }
        }
    } else {
        echo "請(qǐng)選擇一個(gè)圖形";
    }
    ?>
</div>
</body>
</html>


##Shape.class.php:


<?php
abstract class Shape {
    private $name;
    private $error;
    abstract function area();
    abstract function zhou();
    abstract function view($arr);
    abstract function yan($arr);
}
?>


##Rect.class.php:

<?php
class Rect extends Shape {
    private $width;
    private $height;
    function __construct($arr = array()) {
        if (!empty($arr)) {
            $this->width = $arr['width'];
            $this->height = $arr['height'];
        }
        $this->name = "矩形";
        $this->error = '';
    }
    function area() {
        return $this->width * $this->height;
    }
    function zhou() {
        return ($this->width+$this->height) * 2;
    }
    function view($arr) {
        $form='';
        $form .= "<form action='index.php?action=rect' method='post'>";
        $form .= "請(qǐng)輸入".$arr['name']."的寬度:<input type='text' name='width' value='".$_POST['width']."'/><br>";
        $form .= "<br>";
        $form .= "請(qǐng)輸入".$arr['name']."的長(zhǎng)度:<input type='text' name='height' value='".$_POST['height']."'/><br>";
        $form .= "<br>";
        $form .= "<input type='submit' name='sub' value='提交'/>    ";
        $form .= "<input type='reset' name='ret' value='重置'/>";
        $form .= "</form>";
        echo $form;
    }
    function yan($arr) {
        $bz = true;
        if ($arr['width']< 0) {
            $this->error .= "寬度小于0;";
            $bz = false;
        } else {
            if (!is_numeric($arr['width'])) {
                $this->error .= "寬不是數(shù)字;";
                $bz = false;
            }
        }
        if ($arr['height']< 0) {
            $this->error .= "寬度小于0;";
            $bz = false;
        } else {
            if (!is_numeric($arr['height'])) {
                $this->error .= "高不是數(shù)字;";
                $bz = false;
            }
        }
        return $bz;
    }
}
?>


Triangle.class.php:

<?php
class Triangle extends Shape {
    private $bian1;
    private $bian2;
    private $bian3;
    function __construct($arr = array()) {
        if (!empty($arr)) {
            $this->bian1 = $arr['bian1'];
            $this->bian2 = $arr['bian2'];
            $this->bian3 = $arr['bian3'];
        }
        $this->name = "三角形";
        $this->error = '';
    }
    function area() {
        $p = ($this->bian1 + $this->bian2 + $this->bian3) / 2;
        //  p(p-a)(p-b)(p-c)
        return sqrt($p*($p-$this->bian1)*($p-$this->bian2)*($p-$this->bian3));
    }
    function zhou() {
        return $this->bian1+$this->bian2+$this->bian3;
    }
    function view($arr) {
        $form='';
        $form .= "<form action='index.php?action=triangle' method='post'>";
        $form .= "請(qǐng)輸入".$arr['name']."的第一條邊:<input type='text' name='bian1' value='".$_POST['bian1']."'/><br>";
        $form .= "<br>";
        $form .= "請(qǐng)輸入".$arr['name']."的第二條邊:<input type='text' name='bian2' value='".$_POST['bian2']."'/><br>";
        $form .= "<br>";
        $form .= "請(qǐng)輸入".$arr['name']."的第三條邊:<input type='text' name='bian3' value='".$_POST['bian3']."'/><br>";
        $form .= "<br>";
        $form .= "<input type='submit' name='sub' value='提交'/>    ";
        $form .= "<input type='reset' name='ret' value='重置'/>";
        $form .= "</form>";
        echo $form;
    }
    function yan($arr) {
        $bz = true;
        if ($arr['bian1']< 0) {
            $this->error .= "第一條邊小于0;";
            $bz = false;
        } else {
            if (!is_numeric($arr['bian1'])) {
                $this->error .= "第一條邊不是數(shù)字;";
                $bz = false;
            }
        }
        if ($arr['bian2']< 0) {
            $this->error .= "第二條邊小0;";
            $bz = false;
        } else {
            if (!is_numeric($arr['bian2'])) {
                $this->error .= "第二條邊不是數(shù)字;";
                $bz = false;
            }
        }
        if ($arr['bian2']< 0) {
            $this->error .= "第三條邊小于0;";
            $bz = false;
        } else {
            if (!is_numeric($arr['bian2'])) {
                $this->error .= "第三條邊不是數(shù)字;";
                $bz = false;
            }
        }
        if (($this->bian1+$this->bian2) < $this->bian3 ||($this->bian1+$this->bian3) < $this->bian2 ||($this->bian2+$this->bian3) < $this->bian1) {
            $this->error .= "三條邊不能構(gòu)成三角形";
            $bz = false;
        }
        return $bz;
    }
}
?>


Cirle. class.php:

<?php
class Cirle extends Shape {
    private $r;
    function __construct($arr = array()) {
        if (!empty($arr)) {
            $this->r = $arr['r'];
        }
        $this->name = "圓形";
        $this->error = '';
    }
    function area() {
        return pi()* $this->r* $this->r; ;
    }
    function zhou() {
        return 2*$this->r*pi();
    }
    function view($arr) {
        $form='';
        $form .= "<form action='index.php?action=cirle' method='post'>";
        $form .= "請(qǐng)輸入".$arr['name']."的半徑:<input type='text' name='r' value='".$_POST['r']."'/><br>";
        $form .= "<br>";
        $form .= "<input type='submit' name='sub' value='提交'/>    ";
        $form .= "<input type='reset' name='ret' value='重置'/>";
        $form .= "</form>";
        echo $form;
    }
    function yan($arr) {
        $bz = true;
        if ($arr['r']< 0) {
            $this->error .= "半徑小于0;";
            $bz = false;
        } else {
            if (!is_numeric($arr['r'])) {
                $this->error .= "半徑不是數(shù)字;";
                $bz = false;
            }
        }
        return $bz;
    }
}
?>


Sphere.class.php:

<?php
class Sphere extends Shape {
    private $r;
    function __construct($arr = array()) {
        if (!empty($arr)) {
            $this->r = $arr['r'];
        }
        $this->name = "球體";
        $this->error = '';
    }
    //4π(R的平方),體積 4/3π*r的立方
    //球的面積
    function area() {
        return 4*pi()* $this->r* $this->r; ;
    }
    //求的體積
    function zhou() {
        return pow((4/3)*$this->r*pi(),3);
    }
    function view($arr) {
        $form='';
        $form .= "<form action='index.php?action=sphere' method='post'>";
        $form .= "請(qǐng)輸入".$arr['name']."的半徑:<input type='text' name='r' value='".$_POST['r']."'/><br>";
        $form .= "<br>";
        $form .= "<input type='submit' name='sub' value='提交'/>    ";
        $form .= "<input type='reset' name='ret' value='重置'/>";
        $form .= "</form>";
        echo $form;
    }
    function yan($arr) {
        $bz = true;
        if ($arr['r']< 0) {
            $this->error .= "半徑小于0;";
            $bz = false;
        } else {
            if (!is_numeric($arr['r'])) {
                $this->error .= "半徑不是數(shù)字;";
                $bz = false;
            }
        }
        return $bz;
    }
}
?>

Continuing Learning
||
<?php echo "整體代碼展示";
submitReset Code