A computer programmer can use VSCode to create powerful Microsoft Windows applications or as a learning tool as shown by this tutorial on quadratic equations.
How to Solve Quadratic Equations in a Visual Studio Code
Visual Studio Code https://code.visualstudio.com
Quadratic equations are used by school children around the world, and all of those children will (hopefully) know that each quadratic equation can be solved fairly easily by using the quadratic formula.
Quadratic equations are, therefore, a good starting point for anyone learning how to program. When this simple formula is written in a language such as VBScript then the would be programmer can quickly build their confidence in producing a Windows based application.
A quadratic equation, as every school child knows, is one that takes the general form of:
ax² + bx + c = 0 (where a ≠ 0)
The quadratic equation can be solved by using the quadratic formula:
x = (-b ± √ (b² - 4ac))/2a
Two answers (the equation's roots) will be obtained from the formula depending on whether addition or subtraction is used in the numerator, so that:
root 1 = (-b + √ (b² - 4ac))/2a
and:
root 2 = (-b - √ (b² - 4ac))/2a
The next step is to code the formula into VBScript
VBScript is a suitable for learning how to program because:
All that's needed to start programming is a Visual Studio Code. In this case the code will be encapsulated into a subroutine:
sub solve_quad_eq (a, b, c, r1, r2)
The subroutine requires 5 inputs:
if a = 0 then
msgbox "a must be greater than 0"
exit sub
end if
The subroutine must calculate both roots for the equation, but rather than retyping the same formula twice (and then just have + or - in the numerator) the common sections of the formula should be calculated individually:
dim l_numerator : l_numerator = -1 * b
dim r_numerator : r_numerator = sqr (b * b - 4 * a * c)
dim denom : denom = 2 * a
The roots can then be found by using the variables created above:
r1 = (l_numerator + r_numerator) / denom
r2 = (l_numerator - r_numerator) / denom
end sub
All that's left to do is to run the subroutine
The subroutine will needs some inputs for it to be run correctly. First it will need the quadratic equation coefficients:
dim a : a = 5
dim b : b = -3
dim c : c = -2
As well as the coefficients it needs two inputs that will be updated with the values for the equation roots:
dim r1, r2
Then the subroutine can be run with these variables:
solve_quad_eq a, b, c, r1, r2
and the results (the equation roots) can be displayed to the user:
msgbox r1 & " " & r2
If this code is saved to a file (for example c:\vb\quad_eq.vbs) then it can be run by double clicking on it, and the user will see that the roots for 5x²-3x-2=0 are 1 and -0.4.
VBScript is a language that's suitable for programmers starting to build applications for Microsoft Windows. With the minimum of effort equations such as the quadratic formula can be coded and written into subroutines.