<formAction= "? Act=1"Method= "POST">
<inputtype= "text"name= "NUM1"value= "<?php echo isset ($_post[' num1 ')" $_post[' NUM1 ']: ";?>" />
<Selectname= "Ty">
<option<?php if (isset ($_post[' Ty ')) && $_post[' Ty ']= = ' + ') { Echo ' selected ';} ?>Value= "+" >+</option>
<option<?php if (isset ($_post[' Ty ')) && $_post[' Ty ']= = '-') { Echo ' selected ';} ?>Value= "-" >-</option>
<option<?php if (isset ($_post[' Ty ')) && $_post[' Ty ']= = ' * ') { Echo ' selected ';} ?>Value= "*" >*</option>
<option<?php if (isset ($_post[' Ty ')) && $_post[' Ty ']= = '/') { Echo ' selected ';} ?>Value= "/" >/</option>
</Select>
<inputtype= "text"name= "Num2"value= "<?php echo isset ($_post[' num2 ')" $_post[' num2 ']: ";?>" />
<inputtype= "Submit"value= "Calculation" />
</form>
#Factory mode Simple calculator
Abstractclasscore{
Abstract Public functionGetValue ($num 1,$num 2);
}
classJiaextendscore{
PublicfunctionGetValue ($num 1,$num 2){
return$num 1+$num 2;
}
}
classJianextendscore{
PublicfunctionGetValue ($num 1,$num 2){
return$num 1-$num 2;
}
}
classChengextendscore{
PublicfunctionGetValue ($num 1,$num 2){
return$num 1*$num 2;
}
}
classChuextendscore{
PublicfunctionGetValue ($num 1,$num 2){
if($num 2==0) { die(' divisor cannot be 0 '); }
return$num 1/$num 2;
}
}
classgetres{
Static PublicfunctionRevalue ($ty){
Switch($ty){
Case' + ':
return NewJia ();
Break;
Case‘-‘:
returnNewJian ();
Break;
Case‘*‘:
returnNewCheng ();
Break;
Case‘/‘:
returnNewChu ();
Break;
}
}
}
if(isset($_get[' act ']) &&$_post[' Num1 ']!= ' &&$_post[' num2 ']!= ') {
$ty=$_post[' Ty '];
$num 1=Trim($_post[' NUM1 ']);
$num 2=Trim($_post[' num2 ']);
$getRes= Getres::revalue ($ty);
$res=$getRes->getvalue ($num 1,$num 2);
Echo$res;
}
PHP Factory mode Simple Calculator