Php.
First of all, the document structure should be in a directory. my documents are as follows.
At the beginning, enter the index. php file.
Graphic calculator (object-oriented)
Graph (area perimeter) calculator) rectangle
| Triangle | circle
Have done so many things
1. you can use the $ GET _ ["action"] method and the $ _ REQUEST ["action"] method to obtain whether the input parameter is rect, triangle, or circle.
2. the Form. class. php and Result. class. php classes are loaded using the echo new form ("index. php") and echo new result () methods.
3. the _ toString method of the two classes is called through echo.
Next, the program loads the form. class. php file.
Action = $ action;/* var_dump ($ this-> action); */$ this-> shape = isset ($ _ REQUEST ["action"])? $ _ REQUEST ["action"]: "rect";/* var_dump ($ this-> shape); */}/* _ toString () method is used to respond to a class when it is treated as a string. For example, echo $ obj; what should be displayed. This method must return a string ** to output a form **/function _ toString () {$ form = ''; return $ form;} private function getRect () {$ input ='Enter | rectangle | length and width:'; $ Input. =' width:
'; $ Input. =' height:
'; $ Input. =''; Return $ input;} private function getTriangle () {$ input ='Enter the three sides of | triangle |:
'; $ Input ='Enter the three sides of | triangle |:
'; $ Input. =' side:
'; $ Input. =' second side:
'; $ Input. =' third side:
'; $ Input. =''; Return $ input;} private function getCircle () {$ input ='Enter the | circle | radius:
'; $ Input. =' radius:
'; $ Input. =''; Return $ input ;}}?>
Another thing php does is to load different types of forms according to $ _ REQUEST ["action"] or GET _ ["action.
Then, once you press the calculation button, the file "result. class. php" will be loaded.
Shape = new Rect (); break; case 'trigger': $ this-> shape = new triangle (); break; case 'circle ': $ this-> shape = new Circle (); break; // if no break exists, default: $ this-> shape = false;} function _ toString () will be executed by default () {if ($ this-> shape) {$ result = $ this-> shape-> shapeName. 'perimeter '. $ this-> shape-> perimeter ().'
'; $ Result. = $ this-> shape-> shapeName.' area '. $ this-> shape-> area ().'
'; Return $ result;} else {return' no such shape '; }}}?>
One thing this file does is to split the file and execute the class file according to the value passed by $ _ POST ["action "].
The next article describes the meaning of each class file.