[Web+Math | Example Applications ]

Overview

This is a simple program that demonstrates Web+'s conditional processing and math functions. It allows users to calculate the roots (both real and complex numbers) of a equation.
This example demonstrates how you can control the flow of your Web+ scripts

Implementation File

File Name Type Function
ROOT.WML Template

root-p.wml

<webSet #dir# = "/webmath">
<webSet #CGIPath# = "#path##dir#">
<webInclude Script="#path#/header.wml">
<webInclude Script="#path#/gearbox.wml">


<h3>Overview</h3>
<webPrint>
<table width="600">
<tr><td class="textstyle">#calculation#</td></tr>
</table>
</webPrint>


<h3>y = A x&#178; + Bx + C = 0</h3>
<webPrint>#roots# </webPrint>
<br />

root1: x1 = [-B + (B&#178; - 4AC)^0.5] / (2A) <br />
root2: x2 = [-B - (B&#178; - 4AC)^0.5] / (2A) <br />

<hr />

<webif #parameterexists(A)#>
<webset #Avalue#=#A#>
<webelse>
<webset #Avalue#=1>
</webif>
<webif #parameterexists(B)#>
<webset #Bvalue#=#B#>
<webelse>
<webset #Bvalue#=1>
</webif>
<webif #parameterexists(C)#>
<webset #Cvalue#=#C#>
<webelse>
<webset #Cvalue#=1>
</webif>


<form action="<webPrint>#CGIPath#</webPrint>/root.wml#Result" method="post" id="webpForm_1" onsubmit="return _Webp_checkForm_1(this)">

<p>Please enter the function:</p>
<table><tr><td class="textstyle">
<h3>
y= <webprint><input size="5" name="a" value="#Avalue#" /></webprint>
x&#178; + <webprint><input size="6" name="B" value="#Bvalue#" /></webprint> x +
<webprint><input size="6" name="C" value="#Cvalue#" /></webprint>=0
</h3>
</td></tr></table>

<p><input type="submit" name="Calculate" value=" Calculate "/>
<input type="reset" name="reset" value="Clear Entries" /></p>

</form>

<webIf #ParameterExists(Calculate) = 0#>
<webSet #Calculate# ="">
</webIf>


<webIf #Calculate ? "Calculate"#>
<hr />
<webPrint>Your entered: y = #A# x&##178; + #B# x + #C# = 0</webPrint>
<p>

<webPrint>#calculated#</webPrint>

<webSet #p# = #(B ^2 - ( 4 * A * C) ) #>
<webIf #A = 0 #>
<webIf #B = 0 #>
<webPrint><font color="red">No Results.<br> Your input is : C = #C# <br/></font></webPrint>
</webIf>
</webIf>
</font>
<webIf #A = 0 #>
<webIf #B != 0 #>
<webPrint><font size="-1" color="red">
Because A = 0, there is only one root.</font>
<h3>Answer: </h3>
x = # (-1)*C / B # <br/>
</webPrint>
</webIf>
</webIf>

<webIf #A != 0 #>
<webIf # p gte 0.0#>
<webPrint>
<font size="1" color="red">

Because (B&##178; - 4AC) >= 0, both roots are real numbers.

<h3>Answer: </h3>
root1: x1 = # ((-1) * B + p^0.5) / ( 2 * A)# <br />
root2: x2 = # ((-1) * B - p^0.5) / ( 2 * A)# <br />

</webPrint>
</webIf>
</webIf>

<webIf #A != 0.0 #>
<webIf # p lt 0.0#>
<webPrint>
<font size="-1" color="red">
Because (B&##178; - 4AC) < 0, both roots are complex numbers.
<h3>Answer: </h3>
root1: x1 = # (-1) * B /( 2 * A) # + #(((-1.0)*p)^0.5) / ( 2 * A)# i <br />
root2: x2 = # (-1) * B /( 2 * A) # - #(((-1.0)*p)^0.5) / ( 2 * A)# i <br />

</webPrint>
</webIf>
</webIf>

</webIf>



root.wml

<webNoOutput>
<!---
| Description: Examples to illustrate some basic math operations works.
|
| CVS History:
| $Log: root.wml,v $
| Revision 1.2 2006/04/03 18:03:06 vidyar
| daily commit
|
| Revision 1.1 2006/03/29 02:30:45 vidyar
| adding files
|
| Revision 1.4 2006/03/20 16:54:12 vidyar
| daily commit
|
| Revision 1.3 2006/03/10 08:30:07 vidyar
| daily commit
|
|
|
--->
<webCall script=#application.FUNCPATH & "/geturl.wml"# destScript="root.wml" url=#nextURL# byref sessionID="">
<!--- generate text strings --->
<webCall script=#application.FUNCPATH & "/gettext.wml"# textString="calculation" result=#calculation# byref lang=#client.lang# langFile=#langFile#>
<webCall script=#application.FUNCPATH & "/gettext.wml"# textString="roots" result=#roots# byref lang=#client.lang# langFile=#langFile#>
<webCall script=#application.FUNCPATH & "/gettext.wml"# textString="calculated" result=#calculated# byref lang=#client.lang# langFile=#langFile#>
</webNoOutput>
<webSet #javascriptFile# = "root.wml">
<webInclude script=#application.SCRIPTPATH & "/template.wml"#>


 

Copyright © 2009 Webplus, Inc. (talentsoft). All Rights Reserved.
webmaster@webplus.com