This article mainly introduces the simple triangle and rectangular perimeter area calculator implemented by PHP. The implementation in this article is relatively simple and provides code file download. For more information, see
This article mainly introduces the simple triangle and rectangular perimeter area calculator implemented by PHP. The implementation in this article is relatively simple and provides code file download. For more information, see
Use PHP object-oriented knowledge to design a graphical calculator and abstract class knowledge. This calculator can calculate the circumference and area of a triangle and the circumference and area of a rectangle. This graphic calculator has four pages: 1. PHP graphical calculator home page index. php; 2. shape abstract class shape. class. php; 3. triangle calculation class triangle. class. php; 4. rect for Rectangle calculation. class. php.
PHP graphics calculator code click to download: PHP graphics calculator. Zip
The Code is as follows:
PHP graphical calculator Home Page:
Simple graphic calculator
Simple graphical calculator rectangle | triangle
<? Php error_reporting (E_ALL &~ E_NOTICE); // sets the class file function _ autoload ($ classname) {include strtolower ($ classname) required to automatically load this program ). ". class. php ";} // determines whether the user has selected to click a shape link if (! Empty ($ _ GET ['action']) {// Step 1: Create a shape object $ classname = ucfirst ($ _ GET ['action']); $ shape = new $ classname ($ _ POST); // Step 2: Call the interface view () $ shape-> view () in the shape object; // Step 3: whether the user submitted the form if (isset ($ _ POST ['dosubmit ']) {// Step 4: Check whether the user output data is correct, if ($ shape-> yan ($ _ POST) {// calculate the circumference and area of the image echo $ shape-> name. "perimeter :". $ shape-> zhou ()."
"; Echo $ shape-> name." area: ". $ shape-> area ()."
";}}// If the user does not click the link, the main program is accessed by default.} else {echo" select a graph to calculate!
";}?>
Abstract class of shape:
Abstract class Shape {// Shape name public $ name; // Shape calculation area method abstract function area (); // Shape calculation perimeter method abstract function zhou (); // shape graphical form interface abstract function view (); // shape verification method abstract function yan ($ arr );}
Triangle computing files: