PHP实现简易图形计算器

本文实例为大家分享了PHP实现简易图形计算器的具体代码,供大家参考,具体内容如下

主函数:index.php





图形计算器


 

 

简易图形计算器

矩形 | 三角形| 圆形
view($_POST); if (isset($_POST['sub'])) { echo ""; } } else { echo "请选择一个图形"; } ?>

先定义一个抽象类



矩形类的编写

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 .= "请输入".$arr['name']."的宽度:
"; $form .= "
"; $form .= "请输入".$arr['name']."的长度:
"; $form .= "
"; $form .= " "; $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 .= "宽不是数字;"; $bz = false; } } if ($arr['height']< 0) { $this->error .= "宽度小于0;"; $bz = false; } else { if (!is_numeric($arr['height'])) { $this->error .= "高不是数字;"; $bz = false; } } return $bz; } } ?>

三角形类:

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 .= "请输入".$arr['name']."的第一条边:
"; $form .= "
"; $form .= "请输入".$arr['name']."的第二条边:
"; $form .= "
"; $form .= "请输入".$arr['name']."的第三条边:
"; $form .= "
"; $form .= " "; $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 .= "第一条边不是数字;"; $bz = false; } } if ($arr['bian2']< 0) { $this->error .= "第二条边小0;"; $bz = false; } else { if (!is_numeric($arr['bian2'])) { $this->error .= "第二条边不是数字;"; $bz = false; } } if ($arr['bian2']< 0) { $this->error .= "第三条边小于0;"; $bz = false; } else { if (!is_numeric($arr['bian2'])) { $this->error .= "第三条边不是数字;"; $bz = false; } } if (($this->bian1+$this->bian2) < $this->bian3 ||($this->bian1+$this->bian3) < $this->bian2 ||($this->bian2+$this->bian3) < $this->bian1) { $this->error .= "三条边不能构成三角形"; $bz = false; } return $bz; } } ?>

其他的类只要按照上面的格式改下就很好写出来了。

PHP实现简易图形计算器_第1张图片

PHP实现简易图形计算器_第2张图片

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

你可能感兴趣的:(PHP实现简易图形计算器)