同济大学数据库-实验一-答案

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

1实验一讲解ByZhuJing20.主窗体主窗体MainForm运行界面0.主窗体主窗体MainForm运行界面0.主窗体3项目解决方案资源管理器主窗体主要属性设置:IsMdiContainer为True(设置主窗体为多文档界面容器);WindowState为Maximized(运行时最大化)4•主窗体代码:PublicClassMainFormPrivateSub退出ToolStripMenuItem_Click(…)…Application.Exit()EndSubPrivateSub实验1ToolStripMenuItem_Click(…)…Dimf1AsNewshiyan1()f1.MdiParent=Mef1.Show()EndSubPrivateSub实验2ToolStripMenuItem_Click(…)…Dimf2AsNewshiyan2()f2.MdiParent=Mef2.Show()EndSub5PrivateSub实验3ToolStripMenuItem_Click(…)…Dimf3AsNewshiyan3()f3.MdiParent=Mef3.Show()EndSubPrivateSub实验4ToolStripMenuItem_Click(…)…Dimf4AsNewshiyan4()f4.MdiParent=Mef4.Show()EndSubPrivateSub实验5ToolStripMenuItem_Click(...)…Dimf5AsNewshiyan5()f5.MdiParent=Mef5.Show()EndSub.6PrivateSub实验6ToolStripMenuItem_Click(…)…Dimf6AsNewshiyan6()f6.MdiParent=Mef6.Show()EndSubPrivateSub实验7ToolStripMenuItem_Click(…)…Dimf7_1AsNewshiyan7_1()f7_1.Show()EndSubPrivateSub实验8ToolStripMenuItem_Click(…)…Dimf8AsNewshiyan8()f8.MdiParent=Mef8.Show()EndSubEndClass71.实验1:文本框练习实验1运行界面8•实验1代码:PublicClassshiyan1PrivateSubButton1_Click(…)…'隶书按钮TextBox1.Font=NewFont(隶书,25,FontStyle.BoldOrFontStyle.Italic)EndSubPrivateSubButton2_Click(…)…'幼圆按钮TextBox1.Font=NewFont(幼圆,18,FontStyle.ItalicOrFontStyle.Underline)EndSub9PrivateSubButton3_Click(…)…'复制按钮TextBox2.Text=TextBox1.SelectedTextTextBox2.Font=TextBox1.FontEndSubEndClass102.实验2:求鸡和兔的个数实验2运行界面11实验2代码:PublicClassshiyan2PrivateSubTextBox2_KeyDown(…)…Ife.KeyCode=Keys.EnterThenDimx,yAsInteger'x--鸡数,y--兔数IfNotIsNumeric(TextBox1.Text.Trim)ThenMessageBox.Show('头数'必须输入数字,警告)TextBox1.Text=TextBox3.Text=ExitSubEndIf12IfNotIsNumeric(TextBox2.Text.Trim)ThenMessageBox.Show('脚数'必须输入数字,警告)Me.TextBox2.Text=Me.TextBox3.Text=ExitSubEndIfIfVal(TextBox2.Text.trim)Mod20ThenMessageBox.Show(脚必须是双数,警告)TextBox2.Focus()ExitSubEndIf13x=Val(4*TextBox1.Text-TextBox2.Text)/2y=Val(TextBox2.Text-2*TextBox1.Text)/2Ifx0Ory0Then'若头数是负数MsgBox(荒唐解,请重新输入!)Me.TextBox3.Text=ElseTextBox3.Text=x&&yEndIfEndIfEndSubEndClass143.实验3:求解1元2次方程的根实验3运行界面15实验3代码:ImportsSystem.MathPublicClassshiyan3Dima,b,c,disc,realpart,imagpartAsDoublePrivateSubButton1_Click(…)…'计算按钮IfString.IsNullOrEmpty(TextBox1.Text.Trim())AndString.IsNullOrEmpty(TextBox2.Text.Trim())ThenMsgBox(请为a,b赋值)ExitSubEndIfIfTextBox1.Text.Trim()=ThenTextBox1.Text=0EndIf16IfTextBox2.Text.Trim()=ThenTextBox2.Text=0EndIfIfTextBox3.Text.Trim()=ThenTextBox3.Text=0EndIfa=TextBox1.Text.Trimb=TextBox2.Text.Trimc=TextBox3.Text.TrimIfa=0Then'a为0时Ifb0Then'a为0,b不为0时TextBox4.Text=Round(-c/b,2)TextBox5.Text=GroupBox1.Text=不是2次方程,只有一个根Else'a,b都为0时MsgBox(a,b不能同时为0)EndIf17Elsedisc=b*b-4*a*cIfdisc=0Then'disc为0时GroupBox1.Text=有两个相同的实根TextBox4.Text=Round(-b/(2*a),2)TextBox5.Text=Round(-b/(2*a),2)ElseIfdisc0Then'disc大于0时GroupBox1.Text=有两个不同的实根TextBox4.Text=Round((-b+Sqrt(disc))/(2*a),2)TextBox5.Text=Round((-b-Sqrt(disc))/(2*a),2)Else'disc小于0时GroupBox1.Text=有两个不同的虚根realpart=Round(-b/(2*a),2)imagpart=Round(Sqrt(-disc)/(2*a),2)18TextBox4.Text=realpart&+&imagpart&iTextBox5.Text=realpart&-&imagpart&iEndIfEndIfEndSubPrivateSubButton2_Click(…)…'结束按钮Me.Close()EndSubEndClass194.实验4:生成随机数实验4运行界面20实验4代码:ImportsSystem.MathPublicClassshiyan4Dima(9),iAsIntegerDimmax,minAsIntegerDimavgAsDecimalPrivateSubshiyan4_Load(…)…avg=0max=0min=100Randomize()'为随机函数产生不同的初始种子Fori=0To9a(i)=Int(Rnd(i)*(100-30+1)+30)'生成一个随机数,int是强制类型转换函数21Ifmina(i)Thenmin=a(i)Ifmaxa(i)Thenmax=a(i)avg=avg+a(i)Nextavg=Round(avg/10,2)'求平均值,四舍五入到小数后2位Fori=0To9TextBox1.Text&=a(i)&NextTextBox1.Text&=vbCrLf&vbCrLf&min=&min&&max=&max&&avg=&avg'vbCrLf为:回车+换行EndSubEndClass225.实验5:判断回文数实验5运行界面23实验5代码设计:ModuleModule1'实验5中使用的函数FunctionIsH(ByValsAsString)AsBooleanish=TrueForiAsInteger=1Tos.LengthIfMid(s,i,1)Mid(s,s.Length-i+1,1)Thenish=FalseExitForEndIfNextEndFunctionEndModulea.首先为“实验一”项目添加一个模块module1,在其中定义一个判断回文数函数ISH。24PublicClassshiyan5PrivateSubTextBox1_KeyDown(…)…Ife.KeyCode=Keys.EnterThen'如果用户按了回车键IfString.IsNullOrEmpty(TextBox1.Text.Trim())ThenExitSub'如果文本框没有输入东西,退出过程EndIfIfNotIsNumeric(TextBox1.Text)Then'必须输入数值数据MsgBox(必须输入数值数据)TextBox1.Text=TextBox1.Focus()ExitSubEndIfb.其次为shiyan5窗体设计代码。25IfIsH(TextBox1.Text)ThenListBox1.Items.Add(TextBox1.Text&★)ElseListBox1.Items.Add(TextBox1.Text)EndIfTextBox1.Text=EndIfEndSubEndClass266.实验6:配置电脑实验6运行界面27实验6代码:PublicClassshiyan6PrivateSubButton1_Click(...)…ListBox1.Items.Clear()'清除上次的选择'选择电脑品牌IfComboBox1.Text.Trim.Length=0ThenMsgBox(请选择电脑品牌)ComboBox1.Focus()ExitSubElseListBox1.Items.Add(ComboBox1.Text)EndIf28'选择内存IfNot(RadioButton1.CheckedOrRadioButton2.Checked)ThenMsgBox(请选择内存)ExitSubEndIfIfRadioButton1.CheckedThenListBox1.Items.Add(RadioButton1.Text)EndIfIfRadioButton2.CheckedThenListBox1.Items.Add(RadioButton2.Text)EndIf'选择CPUIfNot(RadioButton3.CheckedOrRadioButton4.CheckedOrRadioButton5.Checked)Then29MsgBox(请选择CPU)ExitSubEndIfIfRadioButton3.CheckedThenListBox1.Items.Add(RadioButton3.Text)EndIfIfRadioButton4.CheckedThenListBox1.Items.Add(RadioButton4.Text)EndIfIfRadioButton5.CheckedThenListBox1.Items.Add(RadioButton5.Text)EndIf30'选择其它设备IfCheckBox1.CheckedThenListBox1.Items.Add(CheckBox1.Text)EndIfIfCh

1 / 46
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功