Public Class ProperRational Inherits Rational Private whole As Integer Public Sub New() ' Constructor if no input values are used. MyBase.New() whole = 0 End Sub ' Normal constructor. Public Sub New(ByVal whl As Integer, ByVal num As Integer, ByVal denom As Integer) MyBase.New() whole = whl End Sub Public Sub SetProperRational(ByVal whl As Integer, ByVal num As Integer, ByVal denom As Integer) whole = whl numerator = num denominator = denom Reduce(Me) End Sub Protected Overloads Sub Reduce(ByRef myRational As ProperRational) 'MyBase.Reduce(CType(myRational, Rational)) 'MyBase.Reduce(myRational) Dim sign As Integer sign = myRational.RemoveSign() myRational.whole = myRational.whole + (myRational.numerator \ myRational.denominator) ' Integer math myRational.numerator = myRational.numerator Mod myRational.denominator myRational.AddSign(sign) End Sub ' end Reduce Public Sub AddProperRational(ByVal One As ProperRational, ByVal Two As ProperRational) Dim sign As Integer ' First rational. Remove the sign, convert to an improper rational, ' then put the sign back. sign = One.RemoveSign() One.numerator = One.numerator + One.whole * One.denominator One.whole = 0 One.AddSign(sign) ' Second rational. Remove the sign, convert to an improper rational, ' then put the sign back. sign = Two.RemoveSign() Two.numerator = Two.numerator + Two.whole * Two.denominator Two.whole = 0 Two.AddSign(sign) ' Add the improper rationals. MyBase.AddRational(One, Two) ' Convert back to a proper rational. Reduce(One) Reduce(Two) Reduce(Me) End Sub Public Sub SubProperRational(ByVal One As ProperRational, ByVal Two As ProperRational) 'Insert your code here. End Sub Public Sub MulProperRational(ByVal One As ProperRational, ByVal Two As ProperRational) 'Insert your code here. End Sub Public Sub DivProperRational(ByVal One As ProperRational, ByVal Two As ProperRational) 'Insert your code here. End Sub Public Function StringProperRational() As String 'Insert your code here. End Function Public Function DoubleProperRational() As Double 'Insert your code here. End Function Public ReadOnly Property numWhole() As Integer Get Return whole End Get End Property Private Function RemoveSign() As Integer ' Temporarily take the sign out of the rational. Dim sign As Integer = 1 '1 = positive, -1 = negative If ((Me.whole <> 0) And (Me.numerator <> 0) _ And (Math.Abs(Me.whole * Me.numerator) <> (Me.whole * Me.numerator))) Then sign = -1 End If If ((Me.whole = 0) And (Math.Abs(Me.numerator) <> Me.numerator)) Then sign = -1 End If If ((Me.numerator = 0) And (Math.Abs(Me.whole) <> Me.whole)) Then sign = -1 Me.whole = Math.Abs(Me.whole) Me.numerator = Math.Abs(Me.numerator) End If Return sign End Function Private Sub AddSign(ByVal sign As Integer) ' Put the sign back onto the rational. If Me.whole <> 0 Then Me.whole *= sign Else Me.numerator *= sign End If End Sub End Class