1、vb分数类和向量类之间运算程序(Arithmetic program between VB fractional class and vector class)- score class operationThe metabolic score class class modulePrivate, a, B, member variables of the fractional classPublic Function fgcd (a, b) for the common denominatorDim, C, x, yIf a 0 And b 0 Then X = Abs (a): y = A
2、bs (b)While y 0C = x - y * Int (x / y): x = y: y = CWendFgcd = xElseIf a = 0 And B 0 ThenFgcd = Abs (b)ElseIf a 0 And B = 0 ThenFgcd = Abs (a)ElseIf, a = 0, And, B = 0, ThenFgcd = 0ElseEnd IfEnd FunctionPublic Sub CSET (x, y) fractional class constructor 1 (two integers converted to fractions)A = x:
3、, B = yEnd SubPublic Function cshow () displays the scoresIf a * b 0 ThenCshow = Abs (a) / fgcd (Abs (a), Abs (b) & “/ “ (Abs (b) / fgcd (Abs (a), Abs (b)ElseIf a * B “/“) 0A = Val (dtxt (s, “/“, 1): B = Val (dtxt (s, “/“, 2)ElseA = Val (s): B = 1End IfEnd SubLong form codePrivate Sub Cmdys_Click ()
4、 command click buttonDim I, CL1 As New Class1, Cl2 As New Class1, CL3 As New Class1, nFor I = 0, To, Combo1.ListCount - 1If Combo1.Text = Combo1.List (I) Then Exit ForNext II = I + 1: cl1.cset1 Text1.Text: cl2.cset1 Text2.TextIf I = 1 ThenSet CL3 = FADD (CL1, Cl2): Label1.Caption = cl3.cshowElseIf I
5、 = 2 ThenSet CL3 = fsub (CL1, Cl2): Label1.Caption = cl3.cshowElseIf I = 3 ThenSet CL3 = FTIM (CL1, Cl2): Label1.Caption = cl3.cshowElseIf I = 4 ThenSet CL3 = fdiv (CL1, Cl2): Label1.Caption = cl3.cshowElseIf I = 5 ThenN = Val (Text2.Text): Set CL3 = fpow (CL1, n): Label1.Caption = cl3.cshowElseEnd
6、IfEnd SubPrivate Sub Form_Load () form loadingDim IFor I = 1 To 5Combo1.AddItem Choose (I, “+“, “-“, “*“, “/“, “)Next ICombo1.Text = “+“End SubPublic Function FADD (CL1 As Class1, Cl2 As Class1) As Class1 fractional additionDim, Cl, As, New, Class1Call cl.cset (cl1.re (1) * cl2.re (2) + cl1.re (2) *
7、 cl2.re (1), cl1.re (2) * cl2.re (2)Set, FADD = cl:, Set, CL = NothingEnd FunctionPublic Function fsub (CL1 As Class1, Cl2 As Class1) As Class1 class subtractionDim, Cl, As, New, Class1Call cl.cset (cl1.re (1) * cl2.re (2) - cl1.re (2) * cl2.re (1), cl1.re (2) * cl2.re (2)Set, fsub = cl:, Set, CL =
8、NothingEnd FunctionPublic Function FTIM (CL1 As Class1, Cl2 As Class1) As Class1 fractional multiplicationDim, Cl, As, New, Class1Call cl.cset (cl1.re (1) * cl2.king (1), cl1.re (2) * cl2.re (2)set ftim = cl: set cl = nothingend functionpublic function fdiv (cl1 as class1, cl2 as class1) as class1s
9、分数类除法dim cl as new class1call cl.cset (cl1.re (1) * cl2.re (2), cl1.re (2) * cl2.re (1)set fdiv = cl: set cl = nothingend functionpublic function fpow (cl as class1, n) as class1s 分数类乘方dim cl1 as new class1, a1, a2if n = 0 thencall cl1.cset (pow1 (cl.re (1), (n), pow1 (cl.re (2, n)elsecall cl1.cset
10、(pow1 (cl.re (2) - (n), pow1 (cl.re (1) - (n)end ifset fpow = cl1: set cl1 = nothingend functionpublic function pow1 (a, n) is 整数的乘方dim i, f: f = 1for i = 1 to nf = f *next thepow1 = fend function向量类的运算向量类中的代码private x, y, z is 向量类中成员变量public sub c.s.e.t. (a1, a2, a3) is 设置向量类中的成员变量的值x = y = a1: a2:
11、 z = a3end subpublic function (s) 返回向量类的成员变量的值if s = 1 thenking = xelseif s = 2 thenre = yelseif s = 3 thenking = zelseend ifend functionpublic function cshow (r) is 显示向量类中成员变量的值if r = 1 thencshow = “(“ & “,“ & x & y & z & “,“ & “)“elseif r = 2 thencshow = x & u & iif (y = 0, “+“, “-“) & abs (y) & j
12、 & iif (z = 0, “+“, “-“) & abs (z) & “k“elseend ifend function主窗体运算代码options explicitprivate sub cmdjs _ click () is 命令按钮单击dim cl1 as new class2, cl2 as new class2, cl3 as new class2, s1, s2, xs1 = text1. text: s2 = text2. textcall cl1.cset (val (dtxt (s1, “,“, 1), val (dtxt (s1, “,“, 2), val (dtxt
13、(s1, “,“, 3)call cl2.cset (val (dtxt (s2, “,“, 1), val (dtxt (s2, “,“, 2), val (dtxt (s2, “,“, 3)set cl3 = vadd (cl1, cl2): label1. caption = cl3.cshow (1) & “,“ & cl3.cshow (2) & “set cl3 = vsub (cl1, cl2): label2. caption = cl3.cshow (1) & “,“ & cl3.cshow (2) & “set cl3 = vmul1 (cl1, cl2): label3.
14、 caption = cl3.cshow (1) & “,“ & cl3.cshow (2) & “x = cmul2 (cl1, cl2): label4. caption = xset cl3 = vmul3 (cl1, cl2.re (1): label5. caption = cl3.cshow (1) & “,“ & cl3.cshow (2) & “end subpublic function vadd (cl1 as class2, cl2 as class2) as class2s 向量的加法dim cl3 as new class2call cl3.cset (cl1.re
15、(1) + cl2.re (1), cl1.re (2) + cl2.re (2), cl1.re (3) + cl2.re (3)set vadd = cl3: set cl3 = nothingend functionpublic function vmul1 (cl1 as class2, cl2 as class2) as class2s 向量的向量积dim cl3 as new class2call cl3.cset (cl1.re (2) * cl2.re (3) - cl1.re (3) * cl2.re (2), cl1.re (3) * cl2.re (1) - cl1.re
16、 (1) * cl2.re (3), cl1.re (1) * cl2.re (2) - cl1.re (2) * cl2.re (1)设置:设置 vmul1 = CL3 CL3 =没有端功能公共职能 VSUB(CL1 Cl2 为 2,2)作为“向量的减法 2昏暗的 CL3新班叫 CL3。CSET(CL1。再(1)-(1)Cl2。再次,CL1。再(2)-(2)Cl2。再次,CL1。再(3)氯气。再(3) )集 VSUB = CL3:集 CL3 =没有端功能“窗体加载私有子 form_load()“=”、 “文本:中文本=“2。- 8,8”端子公共功能 cmul2(CL1 Cl2 为 2,2)的向量的数量积定义 x:x = CL1。再(1)2。再(1)+ CL1。再(2)*氯气。再(2)+(3)* CL1,Cl2, (3):cmul2 = x端功能公共功能 vmul3(CL1 为 2,N)为 2的向量的数乘昏暗的 CL3新班叫 CL3。CSET(CL1。再(1)N,CL1。再(2)N,CL1。再(3)* N)设置:设置 vmul3 = CL3 CL3 =没有端功能