VB实验课后习题答案常州工学院doc.docx
- 文档编号:26174179
- 上传时间:2023-06-17
- 格式:DOCX
- 页数:51
- 大小:218.72KB
VB实验课后习题答案常州工学院doc.docx
《VB实验课后习题答案常州工学院doc.docx》由会员分享,可在线阅读,更多相关《VB实验课后习题答案常州工学院doc.docx(51页珍藏版)》请在冰豆网上搜索。
VB实验课后习题答案常州工学院doc
1、登录系统
PublicClassForml
DimrightnameAsString
Dimright^passwordAsString
DimkeycountAsInteger=0'输入的次数
DimyhmAsString
DimklAsString
PrivateSubButtonl_Click(ByValsenderAsSystem・Object,ByVaieAsSystem.EventArgs)HandlesButtonl.Click
TextBoxl.Focus()
yhm二Strings.RTrim(TextBoxl.Text)
kl=Strings.RTrim(TextBox2.Text)
Tfyhm=rightnameAndkl=rightpasswordThen
Me.Hide()
Form2.Show()
Elselfyhm<>rightnameThen
Me.Hide()
MessageBox.Show(”登录信息错误,请检查后重新输入!
”,"提示",MessageBoxButtons.OK,
MesscigeBoxlcon.Error)
Me.Show()
TextBoxl.SelectAll()
TextBoxl.Focus()
keycount=keycouni+1
Elselfkl<>right_passwordThen
Me.HideO
MessageBox.Show(”登录信息错误,请检查后重新输入!
”,"提示",MessageBoxButtons.OK,
MessageBoxlcon・Error)
Me.Show()
TextBox2.SeiectAl1()
TcxtBox2.Focus0
keycount二keycount+1
EndIf
Ifkeycount=3Then
Button2Click(sender,e)
EndTf
EndSub
PrivateSubTextBoxl_KeyPressl(ByVaisenderAsObject,ByVaieAs
System・Windows・Forms・KeyPressEventArgs)HandlesTextBox1・KeyPress
Ife.KeyChar=Chr(13)Then
TextBox2.Focus()
EndIf
Ife.KeyChar>="A"Ande.KeyChar<="Z"Ore.KeyChar=Chr(8)Then
e.Handled=False
Else
e・Handled=True
EndIf
EndSub
PrivateSubTextBox2KeyPress(ByValsenderAsObject,ByValeAs
System・Windows・Forms・KeyPressEventArgs)HandlesTcxtBox2・KeyPress
Ife.KeyChar=Chr(13)Then
ButtonlClick(sender,e)
EndIf
EndSub
PrivateSubButton2Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)Handles
Button2.Click
End
EndSub
'''
'''正确的用户名及对应的口令
'''
…
…
'八
PrivateSubFoi'ml_Load(ByValsenderAsSystem・0bject,ByValeAsSystem.EventArgs)HandlesMyBase.Load
rightname="GAOWET"
right_password="123456"
EndSub
EndClass
2、五金商品店
ImportsSystem・10
ImportsSystem・Text
PublicClassForml
'''〈summary〉
'''定义--个结构体,用来存储商品数据
'''
'''
PrivateStructuretagProduct
PublicNoAsInteger
PublicNumericAsInteger
PublicPriceAsSingle
EndStructure
Privatem_productAstagProduct=Nothing'定义-个商品变吊:
,用來保存当前商品
DimcountAsInteger=0
PrivateSubButtonlClick(ByValsenderAsSystem.Object,ByVaieAsSystem.EventArgs)HandlesButtonl.Click
mproduct.No=Vai(TextBoxl.Text)
m_product・Ntime二TextBox2.Text
m_product・Numcric=Vai(TextBox3.Text)
m.product.Price=Convert・ToSingle(TextBox4.Text)
count=count+1
FilePut(1,m_product,count)
EndSub
PrivciteSubButton2_Click(ByVaisenderAsSystem.Object,ByVaieAsSystem.EventArgs)Ikindles
Button2.Click
ListBoxl・Items・Clear()
DimindexAsInteger
Forindex=1Tocount
FileGet(1,m^product,index)
ListBoxl.Items.Add("记录号:
"&Convert.ToString(mproduct.No)&";"匸具名称:
"&m_product.Name&";"&"数最:
"&Convert.ToString(m_product.Numeric)&""
单价"&Convert.ToString(m_product.Price)&
Next
EndSub
PrivateSubForml_Load(ByValsenderAsSystem.0bject,ByVaieAsSystem.EventArgs)HandlesMyBase.Load
I;ileOpen(l,"c:
\hardwarc・txt",OpenMode.Random,,,Len(m_product))
count=LOF(l)/Len(m_product)
DimindexAsInteger
I;orindex=1ToL0I;(l)/Len(m_product)
FileGet(1,mproduct,index)
Ifm_product・No=0Then
count二index-1
ExitFor
EndIf
Next
EndSub
PrivateSubButton3_Click_l(ByVaisenderAsSystem.Object,ByVaieAsSystem.EventArgs)
HandlesButton3.Click
DimiAsInteger
i=ListBox1.Selectedlndex+1
IJstBoxl.Items.RemoveAt(IJstBoxl.SelectedTndex)
DimindexAsInteger
Forindex=iTocount-1
FileGet(1,mproduct,index+1)
FilePut(1,m_product,index)
Next
m_product二Nothing
FilePut(1,mproduct,index)
count=count一1
EndSub
PrivateSubButtondClick(ByValsenderAsSystem.Object,ByVaieAsSystem.EventArgs)Htindles
Button]Click
ToxtBoxl.Text="”
TextBox2.Text="”
TextBox3.Text=
TextBox4.Text="”
EndSub
PrivateSubButton5Click(ByValsenderAsSystem.Object,ByVaieAsSystem.EventArgs)Handles
Button5.Click
End
EndSub
EndClass
3、按件计酬
PublicClassForml八'
定义变量
'''
'''
DimworkAsworker=Newworker
Dimh_workAsh_worker=Newh_worker
DimpersonAsInteger=0
Dims_numAsInteger=0
Dims_feeAsSingle=0.0
DimsaverageAsSingle=0.0
PrivateSubButtonl_Click(ByVaisenderAsSystem・Object,ByVaicAsSystem・EventArgs)Handies
Buttonl.Click
Try
IfCheckBoxl.Checked=FalseThen
work.Name=TextBoxl.Text
work.Num=Vai(TextBox2.Text)
TextBox3.Text二Convert・ToString(work・Fee)
snum=snum+work・Num
MMMM
s_fee二s_fee+work.Fee
Else
h^work・Name=TextBoxl.Text
h_work.Num=Vai(TextBox2.Text)
TextBox3.Text二Convert・ToString(work・Fee)
snum=snum+hwork・Num
MMMM
s_fee二s_fee+h_work.Fee
EndTf
person=person+1
scivertige=s『ee/person
CatchexAsException
MossageBox・Show(ox・Message)
Button?
Click(sender,e)
EndTry
EndSub
'''
'''Clear按钮触发清空所冇内容
'''
‘‘‘
'八
,八
PrivateSubButton2_Click(ByValsenderAsSystem・Object,ByVaieAsSystem.EventArgs)HandlesButton2.Click
TextBoxl.Text="”
TextBox2.Text=
TextBox3.Text="”
CheckBoxl.Checked=False
EndSub
,,
'''计算总件数,总报酬和总人数以及每人平均酬劳
'''
'''
…
'''
PrivateSubButton3_Click(ByVaisenderAsSystem.Object,ByVaieAsSystem.EventArgs)Handles
Button3.Click
TextBoxl.Text=
TextBox4.Text="总件数为:
"&s_num.ToString&Chr(13)&Chr(10)&"总报酬为:
"&s_fee.ToString&Chr(13)&Chr(10)&〃总入数:
〃&person&Chr仃3)&Chr仃0)&"每人平均酬劳:
"&saverage.ToString
EndSub
EndClass
PublicClcissworker
Protectedw_nameAsString
Protectedw_numAsInteger
Protectedw_feeAsSingle
PropertyName()AsString
Get
Returnw_name
EndGet
Set(ByVaivalueAsString)w_namc=value
EndSet
EndProperty
PropertyNum()AsInteger
Get
Returnwnum
EndGet
Set(ByVaivalueAsInteger)
Ifvalue<0Then
ThrowNewArgumentException(z,生产件数为负数!
")Else
Wnum=value
EndIf
EndSet
EndProperty
PublicOverridableFunctionFee()AsSingle
DimsumAsSingle=0.0
Ifwnum>=1Andwnum<=199Thensum=0.5*wnum
Elselfw_num<=399Then
sum二0・55*wnum
Elselfw_num<=599Thensum=0.6*wnum
Elselfwnum>=600Thensum二0.65*w_num
EndIf
Returnsum
EndFunction
EndClass
PublicClassh_worker
Inheritsworker
PublicOverridesFunctionFee()As
DimsumAsSingle=300.0
Ifw_num>=1Andw_num<=199sum=sum+
Elselfw_num<=
Single
Then
sum=sum+Elselfwnum<=
sum=sum+Elselfw_num<=
sum二sum+Elselfwnum>=
sum=sum+
EndIf
0.2*wnum
399Then
0.25*wnum
599Then
0.3*w_num
799Then
0.35*w_num
800Then
0.4*wnum
Returnsum
EndFunction
EndClass
4、StudentGrade
霊Foral
口回凶
InputGrade
1stNames
Text!
:
Text2:
Text3:
Studentname:
Classaverage:
PublicClassForml
PrivateSubBu11on1_C1ick(ByVa1senderAsSystem.Object,ByVaieAsSystem.EventArgs)Handles
Buttonl.Click
DimnameAsString
Dim11,t2,t3AsInteger
DimcivercigeAsSingle
Dimclass_avcrageAsSingle=0・0
DimiAsInteger=1
ntime=TextBox1.Text
11=Vai(TextBox2.Text)
12=Vai(ToxtBox3.Text)
t3=Vai(TextBox4.Text)
average=(tl+t2+t3)/3
ListBoxl・1terns.Add(name&":
〃&average.ToString)
clcisscivertige=(cltisscivercige*(i-1)+tivertige)/i
RichTextBox1.Text=classaverage.ToString
EndSub
EndCltiss
5、Rectangle长度宽度
國Foral□回冈
计篡
退出
PublicCltissForml
PrivciteWithEventsnAsNewRectangle
PrivateSubButtonl_Click(ByVaisenderAsSystem.Object,ByVa1eKsSystem.EventArgs)HandlesButtonl.Click
n.length=Vai(TextBoxl.Text)
n.width=Vai(TextBox2.Text)
Tfn.length<0Orn.width<0Then
Button3_Click(sender,e)
Else
TextBox3.Text=Convert.ToString(n.perimeter)
TextBoxl・Text二Convcrl・ToSlring(n.area)
EndIf
EndSub
PrivateSubButton2_Click(ByVaisenderAsSystem.Object,ByVaieAsSystem.EventArgs)HandlesButton2.Click
Tfn.square=TrueThen
TcxtBoxS.Text="是"
Else
TextBox5.Text="否"
EndTf
EndSub
PrivciteSubButton3Click(ByVaisenderAsSystem.Object,ByVaieAsSystem.EventArgs)Htindles
Button3.Click
TextBoxl.Text=
TextBox2.Text=
TextBox3.Text=
TextBox4.Text="”
TextBox5.Text="”
EndSub
PrivateSubBu11on4_Click(ByVa1senderAsSystem.Object,ByVaicAsSystem.EventArgs)HandlesButton4.Click
End
EndSub
PrivciteSubFormlI.oad(ByValsenderAsSystem.0bject,ByVa1eAsSystem.EventArgs)HandiesMyBase.Load
EndSub
EndClass
PublicClassRectangle
PrivatemlengthAsSingle
Privatem_widthAsSingle
PublicPropertylength()AsSingle
Get
Returnm_length
EndGet
Set(ByVaivalueAsSingle)
Ifvalue>=0.0Andvalue<=20.0Then
m.length=value
Else
m_length=T
HessageBox.Show(”长度超出范围!
","警告",MessageBoxButtons.0K,
MessageBoxlcon.Error)
EndTf
EndSet
EndProperty
PublicPropertywidth()AsSingle
Get
Returnm_width
EndGet
Set(ByVaivalueAsSingle)
Ifvalue>=0.0Andvalue<=20.0Then
mwidth=value
Else
m^width二TMessageBox.Show(,/宽度超出范围!
","警告",MessageBoxButtons.OK,
MessageBoxlcon.Error)
EndIf
EndSet
EndProperty
PublicFunctionperimeter()AsSingle
Return2*(m_length+m_width)
EndFunction
PublicFunctionareaOAsSingle
Returnm_length*m_width
EndFunction
PublicFunctionsquare()AsBoolean
Ifm^length=m_widthThen
ReturnTrue
Else
ReturnFalse
EndIf
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- VB 实验 课后 习题 答案 常州 工学院 doc
![提示](https://static.bdocx.com/images/bang_tan.gif)