VB解一元二次方程配方法源码.doc

上传人:rrsccc 文档编号:9252853 上传时间:2021-02-12 格式:DOC 页数:9 大小:62.50KB
返回 下载 相关 举报
VB解一元二次方程配方法源码.doc_第1页
第1页 / 共9页
VB解一元二次方程配方法源码.doc_第2页
第2页 / 共9页
VB解一元二次方程配方法源码.doc_第3页
第3页 / 共9页
VB解一元二次方程配方法源码.doc_第4页
第4页 / 共9页
VB解一元二次方程配方法源码.doc_第5页
第5页 / 共9页
点击查看更多>>
资源描述

《VB解一元二次方程配方法源码.doc》由会员分享,可在线阅读,更多相关《VB解一元二次方程配方法源码.doc(9页珍藏版)》请在三一文库上搜索。

1、VB解一元二次方程配方法我也是一个vb的超级菜鸟,但是我运用我所学的数学知识,编辑了一个解一元二次方程的配方法过程的这么一个程序。我是自己原创,至于是不是首创就不知道了。(很多网上直接出答案的都是运用公式法计算的,那么我就想写个有过程的程序,完爆数学老师)好了,废话不说多,现在先上测试图,有图有真相嘛。这个程序有几个重点(后面源码都有注释)1、 a值要变为正数,否则将无法运行2、 开不尽的数要用根号表示,不会像2=1.414这么多小数3、 分母有理化,倒数第二步的分母不能为根号(标准)4、 移项时的符号注意变化。下面是界面介绍:下面直接上源码了,有注释自己可以理解。Dim a$ ,b$,c$,

2、d$,e$,f$,g$,h$Dim jj!Dim ii!Dim pp!Private Sub Command1_Click()a = Text1.Textb = Text2.Textc = Text3.Textd = Text4.TextIf a = 1 Then 第一步,先列出原式Label3.Caption = x2End IfIf a = -1 ThenLabel3.Caption = -x2End IfIf Not a = 1 And Not a = -1 ThenLabel3.Caption = a & x2End IfIf b 0 ThenLabel3.Caption = Labe

3、l3.Caption & + & bElseLabel3.Caption = Label3.Caption & bEnd IfIf c 0 ThenLabel3.Caption = Label3.Caption & x+ & c & = & dElseLabel3.Caption = Label3.Caption & x & c & = & dEnd IfIf a 0 Then 当a为负数时,每个项同时乘以-1a = -ab = -bc = -cd = -dEnd Ifc = c - d 移项,将右边移向左边If a = 0 Then 判断有无解Label3.Caption = Label3.

4、Caption & vbCrLf & 原方程无解End IfIf (b 2) - (4 * a * c) 0 ThenLabel3.Caption = Label3.Caption & + & bElseLabel3.Caption = Label3.Caption & bEnd IfIf c 0 ThenLabel3.Caption = Label3.Caption & x+ & c & =0ElseLabel3.Caption = Label3.Caption & x & c & =0End Ife = (b 2) / (4 * a) 算出适合配方的新c值f = e - c 新c值与原c值

5、的差,两边同时加差值If a = 1 Then 第三步,写出初步配方的结果Label3.Caption = Label3.Caption & vbCrLf & x2End IfIf a = -1 ThenLabel3.Caption = Label3.Caption & vbCrLf & -x2End IfIf Not a = 1 And Not a = -1 ThenLabel3.Caption = Label3.Caption & vbCrLf & a & x2End IfIf b 0 ThenLabel3.Caption = Label3.Caption & + & bElseLabel

6、3.Caption = Label3.Caption & bEnd IfIf e 0 ThenLabel3.Caption = Label3.Caption & x+ & e & = & fElseLabel3.Caption = Label3.Caption & x & e & = & fEnd Ifg = (-b + Sqr(b 2 - 4 * a * c) / (2 * a) 后台使用公式法计算h = (-b - Sqr(b 2 - 4 * a * c) / (2 * a)If g 0 And g 1 Then 给0 y 1的数前加个0g = 0 & gEnd IfIf g -1 The

7、ng = -gg = -0 & gEnd IfIf h 0 And h 1 Thenh = 0 & hEnd IfIf h -1 Thenh = -hh = -0 & hEnd Ifjj = Sqr(a)If a = 1 Then 第四步,运用完全平方公式进行配方Label3.Caption = Label3.Caption & vbCrLf & (xEnd IfIf a = -1 ThenLabel3.Caption = Label3.Caption & vbCrLf & (-xEnd IfIf Not a = 1 And Not a = -1 ThenIf Not Len(CStr(jj

8、- Fix(jj) 4 ThenLabel3.Caption = Label3.Caption & vbCrLf & ( & Sqr(a) & xEnd IfIf Len(CStr(jj - Fix(jj) 4 Then小数大于3位时用根号表示,不直接开方Label3.Caption = Label3.Caption & vbCrLf & ( & a & xEnd IfEnd If-第一层-ii = Sqr(e)If b 0 ThenIf Not Len(CStr(ii - Fix(ii) 4 ThenLabel3.Caption = Label3.Caption & + & Sqr(e) &

9、 )2= & fEnd IfIf Len(CStr(ii - Fix(ii) 4 ThenLabel3.Caption = Label3.Caption & + & & e & )2= & fEnd IfEnd IfIf b 4 ThenLabel3.Caption = Label3.Caption & - & Sqr(e) & )2= & fEnd IfIf Len(CStr(ii - Fix(ii) 4 ThenLabel3.Caption = Label3.Caption & - & & e & )2= & fEnd IfEnd If-第二层-If a = 1 Then 第五步,两边同时

10、开根号Label3.Caption = Label3.Caption & vbCrLf & xEnd IfIf a = -1 ThenLabel3.Caption = Label3.Caption & vbCrLf & -xEnd IfIf Not a = 1 And Not a = -1 ThenIf Not Len(CStr(jj - Fix(jj) 4 ThenLabel3.Caption = Label3.Caption & vbCrLf & & Sqr(a) & xEnd IfIf Len(CStr(jj - Fix(jj) 4 ThenLabel3.Caption = Label3

11、.Caption & vbCrLf & & a & xEnd IfEnd IfIf b 0 ThenIf Not Len(CStr(ii - Fix(ii) 4 ThenLabel3.Caption = Label3.Caption & + & Sqr(e) & =End IfIf Len(CStr(ii - Fix(ii) 4 ThenLabel3.Caption = Label3.Caption & + & & e & =End IfEnd IfIf b 4 ThenLabel3.Caption = Label3.Caption & - & Sqr(e) & =End IfIf Len(C

12、Str(ii - Fix(ii) 4 ThenLabel3.Caption = Label3.Caption & - & & e & =End IfEnd Ifpp = Sqr(f)If Not Len(CStr(pp - Fix(pp) 4 ThenLabel3.Caption = Label3.Caption & & Sqr(f)End IfIf Len(CStr(pp - Fix(pp) 4 ThenLabel3.Caption = Label3.Caption & & fEnd IfLabel3.Caption = Label3.Caption & vbCrLf & x= 第六步,移项

13、,x在左If Len(CStr(jj - Fix(jj) 4 Then 分母有理化(后补分母)Label3.Caption = Label3.Caption & & aEnd IfIf a = 1 ThenIf Not Len(CStr(pp - Fix(pp) 4 ThenLabel3.Caption = Label3.Caption & & Sqr(f)End IfIf Len(CStr(pp - Fix(pp) 4 ThenLabel3.Caption = Label3.Caption & & fEnd IfIf b 0 ThenIf Not Len(CStr(ii - Fix(ii)

14、4 ThenLabel3.Caption = Label3.Caption & - & Sqr(e)End IfIf Len(CStr(ii - Fix(ii) 4 ThenLabel3.Caption = Label3.Caption & - & & eEnd IfEnd IfIf b 4 ThenLabel3.Caption = Label3.Caption & + & Sqr(e)End IfIf Len(CStr(ii - Fix(ii) 4 ThenLabel3.Caption = Label3.Caption & + & & eEnd IfEnd IfEnd If-第一层-If N

15、ot a = 1 ThenIf Not Len(CStr(pp - Fix(pp) 4 ThenLabel3.Caption = Label3.Caption & ( & Sqr(f)End IfIf Len(CStr(pp - Fix(pp) 4 ThenLabel3.Caption = Label3.Caption & ( & fEnd IfIf b 0 ThenIf Not Len(CStr(ii - Fix(ii) 4 ThenLabel3.Caption = Label3.Caption & - & Sqr(e) & )/End IfIf Len(CStr(ii - Fix(ii)

16、4 ThenLabel3.Caption = Label3.Caption & - & & e & )/End IfEnd IfIf b 4 ThenLabel3.Caption = Label3.Caption & + & Sqr(e) & )/End IfIf Len(CStr(ii - Fix(ii) 4 ThenLabel3.Caption = Label3.Caption & + & & e & )/End IfEnd IfIf Not Len(CStr(jj - Fix(jj) 4 ThenLabel3.Caption = Label3.Caption & Sqr(a)End If

17、If Len(CStr(jj - Fix(jj) 4 ThenLabel3.Caption = Label3.Caption & aEnd IfEnd IfLabel3.Caption = Label3.Caption & vbCrLf & x= & g & 或x= & h 第七步,得解End SubPrivate Sub Command2_Click()Text1.Text = Text2.Text = Text3.Text = Text4.Text = Label3.Caption = 解题区域End SubPrivate Sub Command3_Click()a = Text1.Tex

18、tb = Text2.Textc = Text3.Textd = Text4.Textc = c - dLabel6.Visible = TrueLabel7.Visible = TrueLabel8.Visible = TrueLabel9.Visible = TrueLine1.Visible = TrueLine2.Visible = TrueLabel5.Caption = a= & a & ,b= & b & ,c= & c 第一步,列出a、b、c的值(格式严谨)Label5.Caption = Label5.Caption & vbCrLf & =b2-4ac= & (b 2) -

19、 (4 * a * c) 第二步,算出变量b2-4ac的值If (b 2) - (4 * a * c) 0 Then 第三步,判断方程有无解Label5.Caption = Label5.Caption & vbCrLf & b2-4ac 0 ThenLabel7.Caption = - & b & & (b 2) - (4 * a * c) 第四步,写分子ElseLabel7.Caption = -b & & (b 2) - (4 * a * c)End IfEnd IfLabel8.Caption = 2 * a 第四步,写分母g = (-b + Sqr(b 2 - 4 * a * c)

20、/ (2 * a) 公式法运算h = (-b - Sqr(b 2 - 4 * a * c) / (2 * a)If g 0 And g 1 Then 加0g = 0 & gEnd IfIf g -1 Theng = -gg = -0 & gEnd IfIf h 0 And h 1 Thenh = 0 & hEnd IfIf h -1 Thenh = -hh = -0 & hEnd IfLabel9.Caption = x= & g & 或x= & h 第五步,得解End SubPrivate Sub Command4_Click()Label6.Visible = FalseLabel7.Visible = FalseLabel8.Visible = FalseLabel9.Visible = FalseLine1.Visible = FalseLine2.Visible = FalseLabel5.Caption = 解题区域End Sub以上有些代码可能编的有点傻瓜,因为我也只是个菜鸟,能达到效果我就觉得可以的了。更重要的是自己认真的学习一元二次方程,不能依赖程序。感谢读者的支持。

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 社会民生


经营许可证编号:宁ICP备18001539号-1