PHP Object polymorphism Simple graphing calculator Gaulo PHP

Source: Internet
Author: User

Main Program Page test.php page

<! Doctype html>

Shape abstract Class Shape.class.php page

<?php//Shape abstract class shape{public $name;        Area of abstract function areas ();        Perimeter abstract function circumference ();        Graphical interface abstract function view ();        Shape Verification Method Abstract function validate ($arr); }

Rectangle Class Rectangle.class.php Page

<?php //Rectangle class class rectangle extends shape{    private  $width;     private  $height;     function __construct ($arr =array ()) {         if (!empty ($arr)) {          $this->width   =   $arr [' Width '];          $this->height  =   $arr [' Height '];         }         $this->name   =   ' Rectangle ';     }     function area () {         return  $this->width* $this->height;    }    //circumference     function circumference () {        return  2* ($this->width+ $thiS->height)     }    //graphical Interface   function view () {          $form  =   ' <form action= ' test.php?action= Rectangle " method=" post "> ';         $form  .=  $this- >name. ' Width: <input type= "text"  name= "width"  value= "'. $_post[' width ']."  /> <br/> ';          $form  .=  $this- >name. ' High: <input type= "text"  name= "height"  value= "'. $_post[' height ']."  /> <br/> ';          $form  .=  ' < Input type= "Submit"  name= "Dosubmit"  value= "calculation"  /> <br/> ';           $form  .=  ' </form> ';         echo  $form;     }     //shape Verification Method      function validate ($arr) {          $flag  = true;        if ($arr [' Width ']<0  | |  !is_numeric ($arr [' width '])) {            echo   $this->name. ' The width must be an integer greater than 0 <br/> ';             $flag  =  false;        }         if ($arr [' Height ']<0 | |  !is_numeric ($arr [' height ']) {             echo  $this->name. ' The high must be an integer greater than 0 <br/> ';             $flag  =  false;        }         return  $flag;     }    } 

Triangle Class Triangle.class.php page

<?php //Triangle class class triangle extends shape{    private  $edge 1;     private  $edge 2;    private  $edge 3;     function __construct ($arr =array ()) {        if (!empty ($arr)) {         $this->edge1   =   $arr [' Edge1 '];          $this->edge2   =   $arr [' Edge2 '];          $this->edge3   =   $arr [' Edge3 '];                 }          $this->name   =   ' triangle ';     }     function area () {           $p  = ($this->edge1+ $this->edge2+ $this->edge3)/2;             &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;RETURN&NBSP;SQRT ($p * ($p-$this->edge1) * ($p-$this->edge2) * ($p-$this- Edge3)     }    //circumference     function  Circumference () {        return  ($this->edge1+ $this->edge2+$ THIS-&GT;EDGE3)     }    //graphical Interface   function view () {          $form  =   ' <form action= ' test.php?action= Triangle " method=" post "> ';         $form  .=  $this- >name. ' The first side: <input type= "text"  name= "Edge1"  value= "'. $_post[' Edge1 ']. '"  /> <br/> ';          $form  .=  $this- >name. ' The second side: <input type= "text"  name="Edge2"  value= "'. $_post[' Edge2 ']."  /> <br/> ';          $form  .=  $this- >name. ' Third side: <input type= "text"  name= "Edge3"  value= "'. $_post[' Edge3 ']. '"  /> <br/> ';          $form  .=  ' < Input type= "Submit"  name= "Dosubmit"  value= "calculation"  /> <br/> ';           $form  .=  ' </form> ';         echo  $form;     }    //Shape Verification Method       function validate ($arr) {         $flag  = true;         if ($arr [' Edge1 ']<0 | |  !is_numeric ($arr [' Edge1 '])) {            echo   $this->name. ' The first side must be greater than 0The integer <br/> ';             $flag  =  False;        }        if ($arr [' Edge2 ']<0 | |  !is_numeric ($arr [' Edge2 '])) {            echo   $this->name. ' The second side must be an integer greater than 0 <br/> ';             $flag  =  false;        }         if ($arr [' Edge3 ']<0 | |  !is_numeric ($arr [' Edge3 '])) {            echo   $this->name. ' The third side must be an integer greater than 0 <br/> ';             $flag  =  false;        }         if ($arr [' Edge1 ']+ $arr [' Edge2 ']< $arr [' Edge3 '])  | |   ($arr [' Edge1 ']+ $arr [' Edge3 ']< $arr [' edge2 ']) | | ($arr [' Edge3 ']+ $arr [' Edge2 ']< $arr [' Edge1 '])  ) {             echo  ' triangle definition must be on both sides of the sum greater than the third side <br/> ';              $flag  = false;        }         return  $flag;     }    }

Browser Rectangle page

650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M00/86/B3/wKioL1fH6jyDX36YAAAlAetgXQU441.png-wh_500x0-wm_3 -wmp_4-s_226034738.png "title=" Firefox _2016-09-01t08-42-48.546z.png "alt=" wkiol1fh6jydx36yaaalaetgxqu441.png-wh_50 "/ >

Browser Triangle page

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M02/86/B3/wKiom1fH6pnis5EBAAAsmecwmrE954.png-wh_500x0-wm_3 -wmp_4-s_3044092545.png "title=" Firefox _2016-09-01t08-44-41.873z.png "alt=" wkiom1fh6pnis5ebaaasmecwmre954.png-wh_50 "/ >

This article is from the "Jin Sha Harbor" blog, please be sure to keep this source http://11410485.blog.51cto.com/11400485/1845249

PHP Object polymorphism Simple graphing calculator Gaulo PHP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.