请教问题,作业问题
问题如下,小弟英文差,麻烦各位大哥帮帮忙!
1.
The VB function, GetCurrencyCode demonstrates the translation between the currency code and currency number. However, the performance of this function is not good enough; the higher order of input number takes much more times to calculate. Please suggest a way to improve the program performance:
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.
Write a function that reverses the order of the words in a string. For instance, your function should transform the string “Do or do not, there is no try.” To “try. No is there not, do or Do”. Assume that all words are space delimited and treat punctuation the same as letters.
Use your most hands-on programming language.
3.
In the following VB program, please states any potential problem(s) and how to correct.
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.
Problem: Use your most hands-on programming language to implement a function that prints all possible combinations of the characters in a string. These combinations range in length from one to the length of the string. Two combinations that differ only in ordering of the characters ARE the same combination. In other words, “12” and “31” are different combinations from the input string “123”, but “21 is the same as “12”.
For example, if we use “wxyz” as parameter for Combination(“wxyz”) the function will print out
w
x
y
z
wx
wy
wz
xy
xz
yz
wxy
wxz
wyz
xyz
wxyz
5.
Module modFree
#Region "clsShape"
Public Class clsShape
Private m_Area As Double
Private m_Sides As Integer
Public Sub New()
m_Area = 0.0
m_Sides = 0
End Sub
Public Sub New(ByVal Sides As Integer)
m_Sides = Sides
End Sub
Public Sub New(ByVal Area As Double)
m_Area = Area
End Sub
Public Sub New(ByVal Area As Double, ByVal Sides As Integer)
m_Area = Area
m_Sides = Sides
End Sub
Public Property Area() As Double
Get
Return m_Area
End Get
Set(ByVal Value As Double)
m_Area = Value
End Set
End Property
Public 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 clsShape
Public Sub New()
MyBase.New(3)
End Sub
Public Sub New(ByVal Area As Double)
MyBase.New(Area, 3)
End Sub
Public Function CalculateArea(ByVal SideBase As Double, ByVal Height As Double, _ Optional ByVal AssignToArea As Boolean = False) As Double
Dim Area As Double = (SideBase * Height) / 2
If AssignToArea Then
Me.Area = Area
End If
Return Area
End Function
End Class
#End Region
Public Sub Main()
Dim objTriangle As New clsTriangle
Dim objShape As New clsShape
objTriangle.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
5.1 Please find the line of code from the procedure Main to cause run-time error.
5.2 Please write the result output from the procedure Main.
问题点数:40、回复次数:7Top
1 楼hyena041(陷入自己的思维中,找不到自己了)回复于 2006-03-04 20:22:39 得分 0
考试题目阿
1大致上说的是下面给出的函数是做转换,并说明下面代码的效率并不高,让你来修改,提出改的方案
使用switch case不要使用if else
下面的没时间看了
呵呵,别人继续吧Top
2 楼zhouxiaotan(夜雨悠扬)回复于 2006-03-04 21:21:23 得分 0
2.
Write a function that reverses the order of the words in a string. For instance, your function should transform the string “Do or do not, there is no try.” To “try. No is there not, do or Do”. Assume that all words are space delimited and treat punctuation the same as letters.
Use your most hands-on programming language.
使用你最拿手的语言写一个程序,程序的要求就是把一句话的语序到过来,比如:
“Do or do not, there is no try.” 转换后就应该成为“try. No is there not, do or Do”. 并且假定所有的单词之间通过空格进行分割并使用相同的标点符号Top
3 楼zhouxiaotan(夜雨悠扬)回复于 2006-03-04 21:23:00 得分 0
3.
In the following VB program, please states any potential problem(s) and how to correct.
找出下面程序中的任何可能存在的问题,并指出如何修正
Top
4 楼zhouxiaotan(夜雨悠扬)回复于 2006-03-04 21:32:43 得分 0
4.
Problem: Use your most hands-on programming language to implement a function that prints all possible combinations of the characters in a string. These combinations range in length from one to the length of the string. Two combinations that differ only in ordering of the characters ARE the same combination. In other words, “12” and “31” are different combinations from the input string “123”, but “21 is the same as “12”.
For example, if we use “wxyz” as parameter for Combination(“wxyz”) the function will print out
问题:使用你最拿手的语言实现一个程序,打印出一个字符串中所有可能的字母组合。组合的范围是从字符串的第一个(字母)到最后一个(字母)。两个仅仅是字符顺序不同的组合作为相同的组合(来处理)。换句话说,“12”和“31”在字符串“123”中是不同的组合,但是“21”和“12”是相同的(组合)。
例如:假如我们使用“wxyz”作为参数传给组合函数的话,应该打印出。。。Top
5 楼terry1021_82(小狐狸)回复于 2006-03-04 21:48:42 得分 0
第2题,不知道这样写,行不?机子上没有装 VS 。调试不成。感觉可能在那三个符号上会抛异常
dim a() as string=textbox1.text.split(" ")
array.reserve(a)
dim b as string
for i as integer=0 to a.getupperbound(0)
b &= a(i)
next
textbox1.text=bTop
6 楼zhouxiaotan(夜雨悠扬)回复于 2006-03-05 12:54:57 得分 0
TextBox2.text=""
for i as integer = TextBox1.Text.Split(" ").Length -1 to 0 step -1
TextBox2.Text=TextBox1.Text.Split(" ")(i) & " "
next iTop
7 楼zhouxiaotan(夜雨悠扬)回复于 2006-03-05 12:55:42 得分 0
忘了一个加号
TextBox2.text=""
for i as integer = TextBox1.Text.Split(" ").Length -1 to 0 step -1
TextBox2.Text+=TextBox1.Text.Split(" ")(i) & " "
next i
Top




