资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

PHP对象多态性简单图形计算器高洛峰细说PHP-创新互联

主程序页面 test.php页面

我们提供的服务有:做网站、成都网站建设、微信公众号开发、网站优化、网站认证、襄州ssl等。为1000+企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的襄州网站制作公司     简单的图形计算器          
    

简单的图形计算器

    矩形   ||        三角形     
    

    view();         //第三步:用户是否提交了对应的图形界面的表单         if(isset($_POST['dosubmit'])){             //第四步:查看用户输入的数据是否合法,不合法则提示             if($shape->validate($_POST)){             //第五步:计算图形的面积和周长             echo $shape->name.'的面积为:'.$shape->area().'
';             echo $shape->name.'的周长为:'.$shape->circumference().'
';             }         }             }else{//如果用户没有单击则默认访问主程序         echo '请选择一个要计算的图形';     }     ?>

形状抽象类Shape.class.php页面

矩形类Rectangle.class.php页面

width   =  $arr['width'];         $this->height  =  $arr['height'];         }         $this->name   =  '矩形';     }      function area(){         return $this->width*$this->height;     }     //周长     function circumference(){         return 2*($this->width+$this->height);     }     //图形界面   function view(){         $form =  '';         $form .= $this->name.'的宽: 
';          $form .= $this->name.'的高: 
';          $form .= ' 
';          $form .= '';         echo $form;     }     //形状验证方法      function validate($arr){         $flag = true;         if($arr['width']<0 || !is_numeric($arr['width'])){             echo $this->name.'的宽必须是大于0的整数
';             $flag = false;         }         if($arr['height']<0 || !is_numeric($arr['height'])){             echo $this->name.'的高必须是大于0的整数
';             $flag = false;         }         return $flag;     }      }

三角形类Triangle.class.php页面

edge1   =  $arr['edge1'];         $this->edge2   =  $arr['edge2'];         $this->edge3   =  $arr['edge3'];                 }         $this->name   =  '三角形';     }      function area(){          $p =($this->edge1+$this->edge2+$this->edge3)/2;                  return sqrt($p*($p-$this->edge1)*($p-$this->edge2)*($p-$this->edge3));     }     //周长     function circumference(){         return ($this->edge1+$this->edge2+$this->edge3);     }     //图形界面   function view(){         $form =  '';         $form .= $this->name.'的第一个边: 
';          $form .= $this->name.'的第二个边: 
';          $form .= $this->name.'的第三个边: 
';          $form .= ' 
';          $form .= '';         echo $form;     }     //形状验证方法      function validate($arr){         $flag = true;         if($arr['edge1']<0 || !is_numeric($arr['edge1'])){             echo $this->name.'的第一边必须是大于0的整数
';             $flag = false;         }         if($arr['edge2']<0 || !is_numeric($arr['edge2'])){             echo $this->name.'的第二边必须是大于0的整数
';             $flag = false;         }         if($arr['edge3']<0 || !is_numeric($arr['edge3'])){             echo $this->name.'的第三边必须是大于0的整数
';             $flag = false;         }         if(($arr['edge1']+$arr['edge2']<$arr['edge3']) || ($arr['edge1']+$arr['edge3']<$arr['edge2'])||($arr['edge3']+$arr['edge2']<$arr['edge1']) ){             echo '三角形定义必须两边之和大于第三边
';             $flag = false;         }         return $flag;     }      }

浏览器 矩形页面

PHP 对象  多态性 简单图形计算器 高洛峰 细说PHP

浏览器 三角形页面

PHP 对象  多态性 简单图形计算器 高洛峰 细说PHP

另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


本文题目:PHP对象多态性简单图形计算器高洛峰细说PHP-创新互联
文章出自:http://cdkjz.cn/article/dicedg.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220