【PHP继承任务】创建程序以使用继承查找Triangle区域。
解
<
?php classgetdata {public $h;
public $b;
public function method1(){$this->
h= $_REQUEST['height'];
$this->
b= $_REQUEST['base'];
} } classfindarea extends getdata {public $area;
public function method2(){$this->
area= ($this->
h* $this->
b)/2;
echo "Area of Triangle is : ".$this->
area;
} } if(isset($_REQUEST['submit'])) {$obj = new findarea();
$obj->
method1();
$obj->
method2();
} ?>
<
html>
<
head>
<
/head>
<
body>
<
form method= "post">
<
table align ="left" border="1">
<
tr>
<
td>
Enter Height <
/td>
<
td>
<
input type = "text" name="height"/>
<
/td>
<
/tr>
<
tr>
<
td>
Enter Base <
/td>
<
td>
<
input type = "text" name="base"/>
<
/td>
<
/tr>
<
tr>
<
td align ="center" colspan="2">
<
input type= "submit"name="submit"value="http://www.srcmini.com/click"/>
<
/td>
<
/tr>
<
/table>
<
/form>
<
/body>
<
/html>
输出
文章图片
文章图片
文章图片
推荐阅读
- PHP多维数组
- PHP数学操作详解
- PHP邮件用法和实例
- PHP is_null()函数
- PHP魔术常量详解
- PHP include_once包含文件
- PHP Heredoc语法
- PHP索引数组
- 实验四 Android开发基础