Php: Graphic Calculator 1 for Brothers

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.