Understanding the Math Behind Fraction Division | Maths Explanation for Visual Basic Kids
Visual Basic makes it easy to perform arithmetic operations like dividing fractions. Whether you're simplifying fractions, multiplying them,
or coding a math class project, Visual Basic provides clear syntax and powerful tools for beginners and students alike.
Dividing fractions in Visual Basic is a great way to combine coding with math skills. In this tutorial, junior secondary students
will learn how to use Visual Basic to divide fractions step-by-step. We'll explore how to invert and multiply fractions,
write a Visual Basic class for fraction operations, and understand the logic behind the algorithm.
Division is the inverse operation of multiplication; That is exactly what we'll do with for fractions.
Invert the fractions that come after a division sign, as well as change the division sign to multiplication, and then
follow through with multiplication.
Algorithm Steps to Divide Fractions in VB.Net
Say we are to implement a Visual Basic algorithm to divide the given fractional expression
21/8 ÷ 7/2;
Inverting this will yield
21/8 ÷ 7/2;
Then we can go ahead and multiply.
Create a new VB.Net class file; Project, Add Class.
Call it DivideFraction.vb.
Optionally, Create a new VB.Net module file; Project, Add Module.
Call it DivideFractionModule.vb.
Type out the adjoining Visual Basic (VB.Net) codes for dividing fractions.
Note: You can instead comment out the VB.Net code in
the main module from the previous lesson or simply continue from where it stopped.
So! Visual Basic Fun Practice Exercise - Divide Fractions
As a fun practice exercise, feel free to try out your own fractions with different numerators and denominators,
and see how the Visual Basic code divides those fractions.
VB.Net Code for Dividing Fractions - Class File
Public Class DivideFraction
Inherits MultiplyFraction
Public Function doDivide() As Dictionary(Of String, Integer)
For index = 1 To numerators.Count - 1
Dim temp = numerators(index)
numerators(index) = denominators(index)
denominators(index) = temp
Next index
Return doMultiply()
End Function
End Class
VB.Net Code for Dividing Fractions - Main Module
Module Algebra_DivideFraction
Sub Main()
Dim numerators = {16, 9, 640, 7}
Dim denominators = {9, 20, 27, 20}
Dim fractions As New Dictionary(Of String, Integer())
fractions.Add("numerators", numerators)
fractions.Add("denominators", denominators)
Console.WriteLine(" Solving:")
For Each numerator In fractions.Item("numerators")
Console.Write(String.Format("{0,13}", numerator))
Next
Console.Write(Environment.NewLine & String.Format("{0,12}", " "))
For wasted = 0 To numerators.Count - 2
Console.Write(String.Format("{0}", "- / "))
Next
Console.WriteLine(String.Format("{0,1}", "-"))
For Each denominator In fractions.Item("denominators")
Console.Write(String.Format("{0,13}", denominator))
Next
Console.WriteLine("")
Dim div_fract As New DivideFraction
div_fract._init_(fractions)
Dim fraction = div_fract.doDivide()
Console.WriteLine(Environment.NewLine)
Console.WriteLine(String.Format("{0,25}", fraction.Item("numerator")))
Console.WriteLine(String.Format("{0,25}", "Answer = -"))
Console.WriteLine(String.Format("{0,25}", fraction.Item("denominator")))
End Sub
End Module