php计算出某个形状的总面积(数学)

时间:2014-03-12 22:40:12

标签: php

我正在尝试制作一个能够解决不同形状的区域和周长的php产品。有不同的形状,例如正方形,矩形,圆形,三角形等 我目前拥有所有形状的总面积,计算出有多少形状,最高工作周长以及代码,

EDIT2:

abstract class Shapes
{
protected $name;
protected $colour;
function __construct($n, $c)
{
$this->name   = $n;
$this->colour = $c;
}
abstract public function area();
abstract public function perimeter();
public function printShape()
{

}

感谢

1 个答案:

答案 0 :(得分:1)

在Shapes类中,创建一个名为getName的getter(方法),它返回$ name属性。

e.g。

abstract class Shapes
{
    protected $name;
    protected $colour;

    function __construct($n, $c)
    {
        $this->name   = $n;
        $this->colour = $c;
    }

    abstract public function area();

    abstract public function perimeter();

    public function printShape()
    {
        print "<h6>The area of the " . $this->colour . " " . $this->name . " is " . $this->area(
            ) . " and the perimeter is " . $this->perimeter() . "</h6>";
    }

    public function getName()
    {
        return $this->name;
    }

}