「php」カテゴリーアーカイブ

Cone of volume using the OOP of php

using accesser method,property,

[php]

<?php
class Cone1{
const PI = 3.14;
private $radius;
private $height;

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

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

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

</body>
</html>
[/html]