RecruitmentQuiz
PaperA
PrepareBy
2GoTradeLtd.
Version:
1.0
6
Jan
2006
Pleasecompletethefollowing
8
questionswithin
2
hours.
Question
1
TheVB
Function,()
function
,GetCurrencyCodedemonstratesthetranslationbetweenthecurrencycode
and
currencynumber.However,theperformanceofthis
Functionis()
function
is
not
goodenough;thehigherorderof
input
numbertakesmuchmoretimes
to
calculate.Pleasesuggestaway
to
improvetheprogramperformance:
FunctionGetCurrencyCode()
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
EndFunction
Answer:
FunctionGetCurrencyCode()
Function
GetCurrencyCode(
ByVal
input
As
String
)
As
String
Select
Case
input
Case
"
01
"
:
return
=
"
AFA
"
Case
"
02
"
:
return
=
"
ALL
"
Case
"
03
"
:
return
=
"
DZD
"
Case
"
04
"
:
return
=
"
USD
"
Case
"
05
"
:
return
=
"
HKD
"
Case
"
75
"
:
return
=
"
EUR
"
Case
"
76
"
:
return
=
"
XCD
"
Case
"
77
"
:
return
=
"
AMD
"
Case
Else
:
return
=
"
unknown
"
End
Select
EndFunction
Question
2
Write
a
Functionthat()
function
thatreversestheorderofthewords
in
a
string
.
For
instance,your
Functionshould()
function
shouldtransformthe
string
“
Do
or
do
not
,there
is
no
try
.”
To
“
try
.No
is
there
not
,
do
or
Do
”.Assumethatallwordsare
space
delimited
and
treatpunctuationthesame
as
letters.
Useyourmosthands
-
on
programminglanguage.
Answer:
JavaScriptVersion:
FunctionReversesOrder()
function
ReversesOrder()
{
varOldStr
=
"
Doordonot,thereisnotry.
"
varNewStr
=
""
;
varArrayStr
=
OldStr.split(
"
"
);
for
(vari
=
ArrayStr.length
-
1
;i
>=
0
;i
--
)
{
NewStr
+=
ArrayStr[i]
+
"
"
;
}
return
NewStr;
}
Question
3
StudythefollowingVBprogram:
Imports
System
Imports
System.IO
ModuleModule1
Module
Module1
Public
ArtList
As
ArrayList
EndModule
Public
ClassForm1
Class
Form1
Inherits
System.Windows.Forms.Form
WindowsFormDesignergeneratedcode
#Region
"WindowsFormDesignergeneratedcode"
…
#EndRegion
<
[Serializable]()
>
Public
ClassArt
Class
Art
Public
Title
As
String
Public
Des
As
String
Public
Value
As
Integer
Public
Price
As
Double
Public
Picture
As
String
EndClass
Private
SubButton1_Click_1()
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
String
Try
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
'
Thisistheline94’
MsgBox
(ex.Message
&
vbCrLf
&
ex.StackTrace)
End
Try
EndSub
EndClass
Aform
is
created
on
whichabuttoncontrol
is
placed.WhentheButton1_Click
is
fired,amessagebox
is
popup:
What
is
theproblem
and
how
to
fix
it?
Answer:
Question
4
In
thefollowingVBprogram,pleasestatesanypotentialproblem(s)
and
how
to
correct.
Private
SubbtnCalc_Click()
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
(
"
InputTestboxcannotbenull.
"
)
Catch
ex
As
OverflowException
MsgBox
(
"
InputTestbox2cannotbezero!
"
)
Catch
ex
As
FormatException
MsgBox
(
"
InputTestboxshouldbenumericformat!
"
)
End
Try
EndSub
Answer:
Question
5
GetRecordset()
is
aVB
Functionthat()
function
thatreturnsaADODB.Recordset
object
:
Ref_IDQtyPrice
Row
0
00123
1000
60.50
Row
1
00123
2000
60.00
Row
2
00123
3500
59.50
Row
3
00124
3000
60.50
Row
4
00125
2000
59.50
Row
5
00125
1000
58.00
(Thisrecordset
is
sortedbyRef_ID)
Thefollowingprogram
Dim
rst
as
ADODB.Recordset
Rst
=
GetRecordset
Do
While
Not
rst.EOF
Console.writeline(rst.Fields(
"
Ref_ID
"
)
&
vbcrlf
&
rst.Fields(
"
Qty
"
)
&
vbcrlf
&
rst.Fields(
"
Price
"
))
rst.MoveNext()
Loop
Cangeneratethefollowingoutput:
Output:
00123
1000
60.50
00123
2000
60.00
00123
3500
59.50
00124
3000
60.50
00125
2000
59.50
00125
1000
58.00
Pleasesuggesthow
to
modifytheaboveprogram
to
generatethefollowingoutput:
Output:
00123
1000
60.50
2000
60.00
3500
59.50
----
-----
6500
60.00
00124
3000
60.50
----
-----
3000
60.50
00125
2000
59.50
1000
58.00
----
--
评论