I wrote a program for calculating the graphic area according to the book, but did not perform the calculation. I would like to know where the error occurred.

Source: Internet
Author: User
I wrote a program for calculating the graphic area according to the book, but did not perform the calculation. what is the last example of the error in chapter 8th of php. You can create a form, but an error occurs after you click calculate. Could you kindly advise the interface: class _ Shape. php & lt ;? Php & nbsp;
The last example in chapter 8th of php. You can create a form, but an error occurs after you click calculate. Thank you!
Interface: class _ Shape. php
Interface Shape {
Function area ();
Function perimeter ();
}
?>
Rectangle: class _ Rect. php
Class Rect implements Shape {
Private $ width;
Private $ length;

Function _ construct ($ size = ""){
$ This-> width = $ size ["width"];
$ This-> length = $ size ["length"];
}
Function area (){
Return $ this-> length * $ this-> width;
}
Function perimeter (){
Return 2 * ($ this-> width + $ this-> length );
}
}
?>
Triangle: class _ Triangle. php
Class Triangle implements Shape {
Private $ length1;
Private $ leng2;
Private $ length3;

Function _ construct ($ size = ""){
$ This-> length1 = $ size ["length1"];
$ This-> lengh2 = $ size ["leng2"];
$ This-> length3 = $ size ["length3"];
}
Function area (){
$ S = ($ this-> length1 + $ this-> length1 + $ this-> length3)/2;
Return sqrt ($ s * ($ s-$ this-> length1) * ($ s-$ this-> length1) * ($ s-$ this-> length3 ));
}
Function perimeter (){
Return $ this-> length1 + $ this-> length1 + $ this-> length3;
}
}
?>
Circle: class _ Circle. php
Class Circle implements Shape {
Private $ radius;

Function _ construce ($ size = ""){
$ This-> radius = $ size ["radius"];
}
Function area (){
Return pi () * $ this-> radius;
}
Function perimeter (){
Return 2 * pi () * $ this-> radius;
}
}
?>
Table: class _ Form. php
Class Form {
Private $ formName;
Private $ request;
Private $ action;
Private $ method;
Private $ target;

Function _ construct ($ formName, $ request, $ action = "index. php", $ method = "get", $ target = "_ self "){
$ This-> formName = $ formName;
$ This-> request = $ request;
$ This-> action = $ action;
$ This-> method = $ method;
$ This-> target = $ target;
}
Function _ toString (){
$ Str =" ";
$ Str. ="". $ This-> formName ."";
$ Str. =" Action. "method =". $ this-> method. "target = $ this-> target ";

Switch ($ this-> request ["action"]) {
Case 1:
$ Str. ="Rectangular length:";
$ Str. =" Request ["length"]. ">";
$ Str. ="Rectangle width:";
$ Str. =" Request ["width"]. ">";
Break;
Case 2:
$ Str. ="Triangle side length 1:";
$ Str. =" Request ["length1"]. ">";
$ Str. ="Triangle side length 2:";
$ Str. =" Request ["leng2"].">";
$ Str. ="Triangle side length 3:";

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.