Object-Oriented programming method to realize arithmetic and compute rectangular area

Source: Internet
Author: User
Tags arithmetic

With JavaScript to achieve a similar two tab switching effect, with object-oriented programming approach, to achieve arithmetic and calculate the rectangular area:

catview.php:

<meta http-equiv= "Content-type" content= "TEXT/HTML;CHARSET=GBK"/>
<script language= "JavaScript" >
<!--
Function SelType (val) {
if (val== ' Jishuan ') {
Displays the interface of the arithmetic, while hiding the interface of the computed rectangle
table1.style.display= "Block";
Table2.style.display= "None";
}else if (val== ' area ') {
Displays the interface of the computed rectangle while hiding the arithmetic interface
Table1.style.display= "None";
table2.style.display= "Block";
}
}
-->
</script>
<body>
<form action= "catwork.php" method= "POST" >
<input type= "Radio" name= "sel" value= "AA" onclick= "SelType" (' Jishuan ') "> Arithmetic
<input type= "Radio" name= "sel" value= "BB" onclick= "seltype (' area ')" > Compute Rectangle
<table id= "table1" style= "Display:block" >
<tr><td> Please enter the first number: </td><td><input type= "text" name= "NUM1" ></td></tr>
<tr><td> Please enter a second number: </td><td><input tyep= "text" name= "num2" ></td></tr>
<tr><td> Please select operator: </td><td><select name= "Oper" >
<option value= "+" >+</option>
<option value= "-" >-</option>
<option value= "*" >*</option>
<option value= "/" >/</option>
</select></td></tr>
&LT;TR&GT;&LT;TD colspan= "2" ><input type= "submit" value= "Arithmetic" ></td></tr>
</table>
<!--The following table is used to display the computed rectangle-->
<table id= "table2" style= "Display:none" >
<tr><td> Please enter long: </td><td><input type= "text" name= "Long" ></td></tr>
<tr><td> Please input width: </td><td><input type= "text" name= "WID" ></td></tr>
&LT;TR&GT;&LT;TD colspan= "2" ><input type= "Submit" value= "Start operation" ></td></tr>
</table>
</form>
</body>

catwork.php:

<?php
Receive data
Receive num1,num2, operator symbol
Require_once ' Cat.class.php ';
First receive doing
$sel = $_request[' sel '];
$cat 1 = new Cat ();
if ($sel = = "AA") {
$num 1 = $_request[' num1 '];
$num 2 = $_request[' num2 '];
$oper = $_request[' oper '];
$res = $cat 1->jishuan ($num 1, $num 2, $oper);
echo "The result is:". $res. "<br/>";
else if ($sel = = "BB") {
$long = $_request[' long '];
$wid = $_request[' wid '];
echo "The result is:". $cat 1->juxingarea ($long, $wid);
}
?>
<br/><a href= "catview.php" > Return to Main interface </a>

Cat.class.php:

<?php
Defining classes
Class Cat {
function Juxingarea ($long, $wid) {
return $long * $WID;
}
function Jishuan ($num 1, $num 2, $oper) {
Switch ($oper) {
Case "+":
return $num 1 + $num 2;
Break
Case "-":
Return $num 1-$num 2;
Break
Case "*":
Return $num 1 * $num 2;
Break
Case "/":
return $num 1/$num 2;
Break
}
}
}
?>

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.