Blogger Information
Blog 8
fans 0
comment 0
visits 5809
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
计算图形的面积与周长-6
柯二南的博客
Original
586 people have browsed it
<?php

class Riangle extends Shape {

    public $side1 = 0;
    public $side2 = 0;
    public $side3 = 0;

    function __construct() {
        $this->shapeName = '三角形';
        if ($this->validate($_POST['side1'], '第一条边') & $this->validate($_POST['side2'], '第二条边') & $this->validate($_POST['side3'], '第三条边')) {
            if ($this->validateSum($_POST['side1'], $_POST['side2'], $_POST['side3'])) {
                $this->side1 = $_POST['side1'];
                $this->side2 = $_POST['side2'];
                $this->side3 = $_POST['side3'];
            } else {
                echo '<font color="red">三角形的两边之和要大于第三遍</font><br>';
            }
        }
    }

    function area() {
        $s = ($this->side1 + $this->side2 + $this->side3)/2;
        return sqrt($s * ($s - $this->side1) * ($s - $this->side2) * ($s - $this->side3));
    }

    function perimoter() {
        return $this->side1 + $this->side2 + $this->side3;
    }

    private function validateSum($s1, $s2, $s3) {

        if (($s1 + $s2) > $s3 && ($s1 + $s3) > $s2 && ($s3 + $s2) > $s1) {
            return TRUE;
        } else {
            return FALSE;
        }
    }

}


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post