第一道,要求我调整算法,使它的运行速度提高
Function GetCurrencyCode(ByVal input As String) As String
If input = "01" Then
return = "AFA"
ElseIf input = "02" Then
return = "ALL"
ElseIf input = "03" Then
return = "DZD"
ElseIf input = "04" Then
return = "USD"
ElseIf input = "05" Then
return = "HKD"
ElseIf input = "75" Then
return = "EUR"
ElseIf input = "76" Then
return = "XCD"
ElseIf input = "77" Then
return = "AMD"
End If
End Function第2道 问运行后错的原因,以及如何修改...
Imports System
Imports System.IO
Module Module1
Public ArtList As ArrayList
End ModulePublic Class Form1
Inherits System.Windows.Forms.Form#Region " Windows Form Designer generated code "

#End Region<[Serializable]()> Public Class Art
Public Title As String
Public Des As String
Public Value As Integer
Public Price As Double
Public Picture As String
End ClassPrivate Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myArt As New Object
Dim hashtable As New Collections.Hashtable
Dim key As StringTry
myArt = New Art
With myArt
.Title = "Title"
.Des = "Desc"
.Value = 123
.Price = 321.05
End With
key = myArt.Title & myArt.Des & CStr(myArt.Value) & CStr(myArt.Price)
hashtable.Add(key, myArt)
ArtList.Add(myArt)Catch ex As Exception 'This is the line 94’
MsgBox(ex.Message & vbCrLf & ex.StackTrace)
End Try
End Sub
End Class第3道 改错
Private Sub btnCalc_Click( )
Dim result As Integer
Try
Me.Cursor = Windows.Forms.Cursors.WaitCursor
result = Convert.ToInt32(txtInput1.Text) / Convert.ToInt32(txtInput2.Text)
txtResult.Text = result
Me.Cursor = Windows.Forms.Cursors.Default
Catch ex As Exception
MsgBox(ex.StackTrace)
Catch ex As ArgumentNullException
MsgBox("Input Test box cannot be null.")
Catch ex As OverflowException
MsgBox("Input Test box 2 cannot be zero!")
Catch ex As FormatException
MsgBox("Input Test box should be numeric format!")
End Try
End Sub
第4道 问错在那里,如何改正,输出的正确结果应该是什么?
Module modFree
#Region "clsShape"
Public Class clsShape
Private m_Area As Double
Private m_Sides As IntegerPublic Sub New()
m_Area = 0.0
m_Sides = 0
End SubPublic Sub New(ByVal Sides As Integer)
m_Sides = Sides
End SubPublic Sub New(ByVal Area As Double)
m_Area = Area
End SubPublic Sub New(ByVal Area As Double, ByVal Sides As Integer)
m_Area = Area
m_Sides = Sides
End SubPublic Property Area() As Double
Get
Return m_Area
End Get
Set(ByVal Value As Double)
m_Area = Value
End Set
End PropertyPublic Property Sides() As Integer
Get
Return m_Sides
End Get
Set(ByVal Value As Integer)
m_Sides = Value
End Set
End Property
End Class
#End Region
#Region "clsTriangle"
Public Class clsTriangle
Inherits clsShapePublic Sub New()
MyBase.New(3)
End SubPublic Sub New(ByVal Area As Double)
MyBase.New(Area, 3)
End SubPublic Function CalculateArea(ByVal SideBase As Double, ByVal Height As Double, _ Optional ByVal AssignToArea As Boolean = False) As Double
Dim Area As Double = (SideBase * Height) / 2If AssignToArea Then
Me.Area = Area
End IfReturn Area
End Function
End Class
#End RegionPublic Sub Main()
Dim objTriangle As New clsTriangle
Dim objShape As New clsShapeobjTriangle.Area = -330
objTriangle.Sides = 5.5
objTriangle.CalculateArea(10.0, 2.5)objShape.Area = 123
objShape.Sides = -2
objShape = CType(objShape, clsTriangle)Console.WriteLine(TypeOf objTriangle Is clsShape)
Console.WriteLine(TypeOf objShape Is clsTriangle)
Console.WriteLine(objTriangle.Area)
End Sub
End Module这只是2小时题里的一半,看了一小时左右偶的放弃了,郁闷非常....

解决方案 »

  1.   

    第一题:采用查表算法(使用Choose函数);
    第二题:
    '下面语句出错,原因在于myArt为明确数据类型
    myArt = New Art
    With myArt
    .Title = "Title"
    .Des = "Desc"
    .Value = 123
    .Price = 321.05
    End With
    '修改
    With CType(myArt, Art)
    .....
    End With第三题:错误语句:result = Convert.ToInt32(txtInput1.Text) / Convert.ToInt32(txtInput2.Text)
    应该为result = Convert.ToInt32(txtInput1.Text) \ Convert.ToInt32(txtInput2.Text)第四题:
    错误语句,原因数据类型不明确,无法调用基类构造函数
    Public Sub New()
    MyBase.New(3)
    End Sub
    修改如下:
    Public Sub New()
    MyBase.New(3%)' MyBase.New (Ctype(3, Integer))
    End Sub
    或者
    Public Sub New()
    MyBase.New(3#)' MyBase.New (Ctype(3, Double))
    End Sub不知道对不对。
      

  2.   

    第一个用select case 语句
    后面的没时间看了
      

  3.   

    呵呵, 第一题原来的算法速度不慢啊, 除非比对都用整型来代替,那样也需要转换,换成查表或者select case 不见得速度快, 这个不能靠感觉的. 好像题出的有问题.
      

  4.   

    你确定第一道题不是改错的么?Return = XXXX ?
    VB中的Return是和GoSub搭配使用的,和返回值完全是2码事,他要那个数是干什么的?
    要是需要返回值应该写成:GetCurrencyCode = XXXXX怎么出的题这是,这样地方不去也罢
      

  5.   

    又看了一下,越来越纳闷,这是考VB么?
    好多东西都不是VB的啊,譬如 Try,Imports 等东西在VB中可咋用呢?
      

  6.   

    放错地方了.Not 刚接触 帮你顶
      

  7.   

    第一题明显是让你用SELECT来取代的,SELECT在VB的COMPILER里是经过优化处理的。(阅读自微软某专家的文章)。继续看。
      

  8.   

    哇,后面全是。NET的,还没学呢。