7.10.2 PHP图形计算器功能设计

7.10.2 PHP图形计算器功能设计

rect.class.php

<?php
/*
 * 这个类是一个矩形的类, 这个类要按形状的规范去实现
 *
 */
class Rect extends Shape {
    private $width;
    private $height;

    function __construct($arr) {

        $this->width = $arr['width'];
        $this->height = $arr['height'];
        $this->name = $arr['name'];
    }
    
    function area() {
        return $this->width * $this->height;
    }

    function zhou() {
        return 2*($this->width + $this->height);
    }

    function view() {
        $form = '<form action="index.php" method="post">';
        $form .= $this->name.'的宽:<input type="text" name="width" value="" /><br>';
        $form .= $this->name.'的高:<input type="text" name="height" value="" /><br>';
        $form .= '<input type="submit" name="dosubmit" value="计算"><br>';
        $form .='<form>';
    }

    function yan($arr) {
        $bg = true;
        if($arr['width'] < 0) {
            echo $this->name."的宽不能为0!<br>";
            $bg = false;    
        }

        if($arr['height'] < 0) {
            echo $this->name."的高度不能小于0!<br>";
            $bg = false;
        }

        return $bg;
    }

}

shape.class.php

<?php
/*
 * 这是一个形状的抽象类
 *
 * 定义子类必须实现的一些方法
 *
 *
 */
abstract class  {
    //形状的名称
    protected $name;

    //形状的计算面积方法
    abstract function area();

    //形状的计算周长的方法
    abstract function zhou();

    //形状的图形表单界面
    abstract function view();
    //形状的验证方法
    abstract function yan();

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • PHP 学习目录 ├─PHP视频教程 1 LAMP网站构建 │ ├─PHP教程 1.1.1 新版视频形式介绍│ ...
    曹渊说创业阅读 16,175评论 29 417
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 172,870评论 25 708
  • 2017.08.7. 星期一 晴天 今天晚上,吃好饭,爸爸妈妈就带着我一起去九龙公园散步。我还带了一个篮球,边走...
    王紫杨阅读 3,547评论 3 6
  • 1. 单行文本省略 { overflow: hidden; text-overflow: ellipsis; wh...
    echo_me阅读 301评论 0 0
  • Spring之IOC(DI) 控制反转 Inversion of Control依赖注入 Dependency I...
    cslrx阅读 239评论 0 1