Cone of volume using the OOP of php

using accesser method,property,

</p>

<p>&lt;?php
  class Cone1{
  const PI = 3.14;
  private $radius;
  private $height;</p>

<p>public function setRadius($base){
    $this-&gt;radius = $base;
  }
  public function setHeight($height){
    $this-&gt;height = $height;
  }
  public function getRadius(){
    return $this-&gt;radius;
  }
  public function getHeight(){
    return $this-&gt;height;
  }
  ///
  public function getVolume(){
    $area = pow($this-&gt;radius,2) * self::PI;
    return $area * $this-&gt;height / 3;
  }
}</p>

<p>?&gt;
&lt;!DOCTYPE html&gt;
&lt;html&gt;
  &lt;head&gt;
    &lt;meta charset=&quot;utf-8&quot;&gt;
    &lt;title&gt;The volume of the cone&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;h2&gt;use OOP of PrivateAccesser&lt;/h2&gt;
    &lt;p&gt;
      &lt;?php
        require_once 'Cone1.php';
        $obj = new Cone1();
        $obj-&gt;setRadius(10);
        $obj-&gt;setHeight(50);
        print &quot;The bottom surface of the radius: {$obj-&gt;getRadius()}&quot; . '&lt;br&gt;';
        print &quot;The height of the cone: {$obj-&gt;getHeight()}&quot; . '&lt;br&gt;';</p>

<pre><code>    print &amp;quot;The volume of the cone: {$obj-&amp;gt;getVolume()}&amp;quot;;
   ?&amp;gt;
&amp;lt;/p&amp;gt;
</code></pre>

<p>&lt;/body&gt;
&lt;/html&gt;

(Visited 1 times, 1 visits today)

コメントを残す

メールアドレスが公開されることはありません。