1.<!--主程序index.php-->
<html>
<head>
<title>图形计算器</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
</head>
<body>
<center>
<h1>图形计算器</h1>
<a href="index.php?action=rect">矩形</a>||
<a href="index.php?action=triangle">三角形</a>||
<a href="index.php?action=circle">圆形</a>
</center>
<hr><br>
<?php
//设置自动加载这个程序所需要的类文件
error_reporting(@notice);
function __autoload($classname){
include strtolower($classname).".class.php";
}
//如果没有点击图形链接
if(!empty($_GET['action'])){
//1.创建一个形状对象;
$classname=ucfirst($_GET['action']);
$shape=new $classname($_POST);
//2.调用形状类中的view表单界面;
$shape->view();
//3.用户是否提交了对应图形界面的表单
if(isset($_POST['sub'])){
//4.查看用户输入的数据是否正确(在形状类中已经定义过)
if($shape->validate()){
//5.计算出图形的周长和面积
echo "{$shape->name}的周长为:".$shape->circum();
echo "<br>";
echo "{$shape->name}的面积为:".$shape->area();
}
}
}
//如果没有点击图形链接,则提示
else{
echo "您没有选择要输出的图形,请选择要一个要输出的图形!";
}
?>
</body>
<html>
<head>
<title>图形计算器</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
</head>
<body>
<center>
<h1>图形计算器</h1>
<a href="index.php?action=rect">矩形</a>||
<a href="index.php?action=triangle">三角形</a>||
<a href="index.php?action=circle">圆形</a>
</center>
<hr><br>
<?php
//设置自动加载这个程序所需要的类文件
error_reporting(@notice);
function __autoload($classname){
include strtolower($classname).".class.php";
}
//如果没有点击图形链接
if(!empty($_GET['action'])){
//1.创建一个形状对象;
$classname=ucfirst($_GET['action']);
$shape=new $classname($_POST);
//2.调用形状类中的view表单界面;
$shape->view();
//3.用户是否提交了对应图形界面的表单
if(isset($_POST['sub'])){
//4.查看用户输入的数据是否正确(在形状类中已经定义过)
if($shape->validate()){
//5.计算出图形的周长和面积
echo "{$shape->name}的周长为:".$shape->circum();
echo "<br>";
echo "{$shape->name}的面积为:".$shape->area();
}
}
}
//如果没有点击图形链接,则提示
else{
echo "您没有选择要输出的图形,请选择要一个要输出的图形!";
}
?>
</body>
</html>
2.<!-- 这是一个定义图形的抽象类,方便后续图形类文件的扩展,形成多态特性!文件名shape.class.php-->
<?