版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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 = "x2"end ifif a = -1 thenlabel3.caption = "-x2"end ifif not a = 1 and not a = -1 thenlabel3.caption = a & "x
3、2"end ifif b > 0 thenlabel3.caption = label3.caption & "+" & belselabel3.caption = label3.caption & bend ifif c > 0 thenlabel3.caption = label3.caption & "x+" & c & "=" & delselabel3.caption = label3.caption & "x" &am
4、p; c & "=" & dend ifif a < 0 then '当a为负数时,每个项同时乘以-1a = -ab = -bc = -cd = -dend ifc = c - d '移项,将右边移向左边if a = 0 then '判断有无解label3.caption = label3.caption & vbcrlf & "原方程无解"end ifif (b 2) - (4 * a * c) < 0 thenlabel3.caption = label3.caption &
5、 vbcrlf & "原方程无解"end ifif a = 1 then '第二步,写出移项后的结果label3.caption = label3.caption & vbcrlf & "x2"end ifif a = -1 thenlabel3.caption = label3.caption & vbcrlf & "-x2"end ifif not a = 1 and not a = -1 thenlabel3.caption = label3.caption & vbcrl
6、f & a & "x2"end ifif b > 0 thenlabel3.caption = label3.caption & "+" & belselabel3.caption = label3.caption & bend ifif c > 0 thenlabel3.caption = label3.caption & "x+" & c & "=0"elselabel3.caption = label3.caption & &
7、quot;x" & c & "=0"end ife = (b 2) / (4 * a) '算出适合配方的新c值f = e - c '新c值与原c值的差,两边同时加差值if a = 1 then '第三步,写出初步配方的结果label3.caption = label3.caption & vbcrlf & "x2"end ifif a = -1 thenlabel3.caption = label3.caption & vbcrlf & "-x2"end
8、 ifif not a = 1 and not a = -1 thenlabel3.caption = label3.caption & vbcrlf & a & "x2"end ifif b > 0 thenlabel3.caption = label3.caption & "+" & belselabel3.caption = label3.caption & bend ifif e > 0 thenlabel3.caption = label3.caption & "x+
9、" & 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 = "
10、;0" & gend ifif g < 0 and g > -1 theng = -gg = "-0" & gend ifif h > 0 and h < 1 thenh = "0" & hend ifif h < 0 and h > -1 thenh = -hh = "-0" & hend ifjj = sqr(a)if a = 1 then '第四步,运用完全平方公式进行配方label3.caption = label3.caption &
11、; vbcrlf & "(x"end ifif a = -1 thenlabel3.caption = label3.caption & vbcrlf & "(-x"end ifif not a = 1 and not a = -1 thenif not len(cstr(jj - fix(jj) > 4 thenlabel3.caption = label3.caption & vbcrlf & "(" & sqr(a) & "x"end ifif l
12、en(cstr(jj - fix(jj) > 4 then小数大于3位时用根号表示,不直接开方label3.caption = label3.caption & vbcrlf & "(" & a & "x"end ifend if'-第一层-ii = sqr(e)if b > 0 thenif not len(cstr(ii - fix(ii) > 4 thenlabel3.caption = label3.caption & "+" & sqr(e) &
13、; ")2=" & fend ifif len(cstr(ii - fix(ii) > 4 thenlabel3.caption = label3.caption & "+" & "" & e & ")2=" & fend ifend ifif b < 0 thenif not len(cstr(ii - fix(ii) > 4 thenlabel3.caption = label3.caption & "-" &
14、 sqr(e) & ")2=" & fend ifif len(cstr(ii - fix(ii) > 4 thenlabel3.caption = label3.caption & "-" & "" & e & ")2=" & fend ifend if'-第二层-if a = 1 then '第五步,两边同时开根号label3.caption = label3.caption & vbcrlf & "x&qu
15、ot;end ifif a = -1 thenlabel3.caption = label3.caption & vbcrlf & "-x"end ifif not a = 1 and not a = -1 thenif not len(cstr(jj - fix(jj) > 4 thenlabel3.caption = label3.caption & vbcrlf & "" & sqr(a) & "x"end ifif len(cstr(jj - fix(jj) > 4
16、thenlabel3.caption = label3.caption & vbcrlf & "" & a & "x"end 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.capt
17、ion = label3.caption & "+" & "" & e & "="end 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 = la
18、bel3.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 & "
19、77;" & fend iflabel3.caption = label3.caption & vbcrlf & "x=" '第六步,移项,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.ca
20、ption & "±" & 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 - fi
21、x(ii) > 4 thenlabel3.caption = label3.caption & "-" & "" & eend 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
22、 & "+" & "" & eend ifend ifend if'-第一层-if not 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 & "(±"
23、; & 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) > 4 thenlabel3.caption = label3.caption & "-" & "" & e & ")/"end
24、 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
25、 ifif not len(cstr(jj - fix(jj) > 4 thenlabel3.caption = label3.caption & sqr(a)end ifif len(cstr(jj - fix(jj) > 4 thenlabel3.caption = label3.caption & aend ifend iflabel3.caption = label3.caption & vbcrlf & "x=" & g & "或x=" & h '第七步,得解end s
26、ubprivate sub command2_click()text1.text = ""text2.text = ""text3.text = ""text4.text = ""label3.caption = "解题区域"end subprivate sub command3_click()a = text1.textb = text2.textc = text3.textd = text4.textc = c - dlabel6.visible = truelabel7.visible =
27、 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) - (4 * a * c) '第二步,算出变量b2-4ac的值if (b 2) - (4 * a * c) < 0 then '第三步,判断方程有无解label5.caption = label5.caption & vbcrlf & "b2-4ac < 0,方程无解。"elseif b > 0 thenlabel7.caption
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年四川文化艺术学院单招职业技能测试模拟测试卷及答案1套
- 2026云南怒江州人力资源市场招聘劳务派遣人员1人笔试参考题库及答案解析
- 2026上半年贵州黔东南州天柱县中心血库招聘驾驶员1人笔试参考题库及答案解析
- 2025广西崇左扶绥县事业单位竞争性选聘工作人员29人(公共基础知识)测试题附答案
- 2025年甘肃林业职业技术大学招聘工程项目管理人员备考题库附答案
- 2025年七台河市公益性岗位人员招聘30人(公共基础知识)综合能力测试题附答案
- 2025年12月广东深圳中学光明科学城学校(集团)面向2026年应届毕业生招聘教师11人(深圳定点)(公共基础知识)综合能力测试题附答案
- 2025山东滨州市滨城区招录城市社区工作者58人备考题库附答案
- 2025年信科公司机电分公司招聘57名员工(第三批)考前自测高频考点模拟试题附答案
- 2025年河南省检验检测研究院集团有限公司社会招聘64人笔试备考试题附答案
- 1输变电工程施工质量验收统一表式(线路工程)-2024年版
- 陕西省建筑场地墓坑探查与处理技术规程
- 2022-2023学年四川省乐山市市中区外研版(三起)六年级上册期末测试英语试卷(含听力音频)
- 滕州菜煎饼创新创业计划书
- 2024北京朝阳区初一(上)期末道法试卷及答案
- 假体隆胸后查房课件
- 送货单格式模板
- GB/T 42430-2023血液、尿液中乙醇、甲醇、正丙醇、丙酮、异丙醇和正丁醇检验
- 关于地方储备粮轮换业务会计核算处理办法的探讨
- 上海农贸场病媒生物防制工作标准
- YY 0334-2002硅橡胶外科植入物通用要求
评论
0/150
提交评论