Основы офисного программирования и язык VBA


Пример 4.5


Public Function Plus(a As Rational) As Rational Dim d As Integer, u As Integer, v As Integer Dim R As New Rational

u = m * a.Знаменатель + n * a.Числитель v = n * a.Знаменатель d = nod(u, v) R.Числитель = u \ d R.Знаменатель = v \ d Set Plus = R End Function

Public Function Minus(a As Rational) As Rational Dim d As Integer, u As Integer, v As Integer Dim R As New Rational

u = m * a.Знаменатель - n * a.Числитель v = n * a.Знаменатель d = nod(u, v) R.Числитель = u \ d R.Знаменатель = v \ d Set Minus = R End Function

Public Function Mult(a As Rational) As Rational Dim d As Integer, u As Integer, v As Integer Dim R As New Rational

u = m * a.Числитель v = n * a.Знаменатель d = nod(u, v) R.Числитель = u \ d R.Знаменатель = v \ d Set Mult = R End Function

Public Function Divide(a As Rational) As Rational Dim d As Integer, u As Integer, v As Integer Dim R As New Rational u = m * a.Знаменатель v = n * a.Числитель If v = 0 Then MsgBox ("деление на нуль невозможно") Else d = nod(u, v) R.Числитель = u \ d R.Знаменатель = v \ d Set Divide = R End If End Function

Public Sub PrintRational() Debug.Print (m & "/" & n) End Sub

Пример 4.5.

Закрыть окно






Начало  Назад  Вперед