Recruitment Quiz Paper A Prepare By 2GoTrade Ltd. Version: 1.0 6 Jan 2006 Please complete the following 8 questions within 2 hours. Question 1 The VB Function ,()function, GetCurrencyCode demonstrates the translation between the currency code and currency number. However, the performance of this Function is()functionisnot 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()Function GetCurrencyCode(ByValinputAsString) AsString Ifinput="01"Then return="AFA" ElseIfinput="02"Then return="ALL" ElseIfinput="03"Then return="DZD" ElseIfinput="04"Then return="USD" ElseIfinput="05"Then return="HKD" ElseIfinput="75"Then return="EUR" ElseIfinput="76"Then return="XCD" ElseIfinput="77"Then return="AMD" EndIf End Function Answer: Function GetCurrencyCode()Function GetCurrencyCode(ByValinputAsString) AsStringSelectCaseinputCase"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" CaseElse: return="unknown"EndSelectEnd Function Question 2 Write a Function that()function that reverses the order of the words in a string. For instance, your Function should()function should transform the string “Doordonot, there is no try.” To “try. No is there not, doorDo”. Assume that all words are space delimited and treat punctuation the same as letters. Use your most hands-on programming language. Answer: JavaScript Version: Function ReversesOrder()function ReversesOrder() { var OldStr ="Do or do not, there is no try." var NewStr =""; var ArrayStr = OldStr.split(""); for (var i = ArrayStr.length -1 ;i >=0 ; i--) { NewStr += ArrayStr[i] +""; } return NewStr; } Question 3 Study the following VB program: Imports System Imports System.IO Module Module1Module Module1 Public ArtList As ArrayList End Module PublicClass Form1Class Form1 Inherits System.Windows.Forms.Form Windows Form Designer generated code#Region " Windows Form Designer generated code " … #End Region <[Serializable]()>PublicClass ArtClass Art Public Title AsString Public Des AsString Public Value AsInteger Public Price AsDouble Public Picture AsString End Class PrivateSub Button1_Click_1()Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim myArt AsNewObject Dim hashtable AsNew Collections.Hashtable Dim key AsString Try myArt =New Art With myArt .Title ="Title" .Des ="Desc" .Value =123 .Price =321.05 EndWith 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) EndTry End Sub End Class A form is created on which a button control is placed. When the Button1_Click is fired, a message box is popup: What is the problem and how tofix it? Answer: Question 4 In the following VB program, please states any potential problem(s) and how to correct. PrivateSub btnCalc_Click()Sub btnCalc_Click( ) Dim result AsInteger 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!") EndTry End Sub Answer: Question 5 GetRecordset() is a VB Function that()function that returns a ADODB.Recordset object: Ref_ID Qty Price Row 000123100060.50 Row 100123200060.00 Row 200123350059.50 Row 300124300060.50 Row 400125200059.50 Row 500125100058.00 (This recordset is sorted by Ref_ID) The following program Dim rst as ADODB.Recordset Rst = GetRecordset DoWhileNot rst.EOF Console.writeline(rst.Fields("Ref_ID") & vbcrlf & rst.Fields("Qty") & vbcrlf & rst.Fields("Price")) rst.MoveNext() Loop Can generate the following output: Output: 00123100060.50 00123200060.00 00123350059.50 00124300060.50 00125200059.50 00125100058.00 Please suggest how to modify the above program to generate the following output: Output: 00123 100060.50 200060.00 350059.50 --------- 650060.00 00124 300060.50 --------- 300060.50 00125 200059.50 100058.00 --------- 300058.75 Answer: Dim rst as ADODB.Recordset Rst = GetRecordset DoWhileNot rst.EOF Console.writeline(rst.Fields("Ref_ID") & vbcrlf & rst.Fields("Qty") & vbcrlf & rst.Fields("Price")) rst.MoveNext() Loop Question 6 Problem: Use your most hands-on programming language to implement a Function that()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 inputstring “123”, but “21is the same as “12”. For example, if we use “wxyz” as parameter for Combination(“wxyz”) the Function will()function will print out w x y z wx wy wz xy xz yz wxy wxz wyz xyz wxyz Answer: Question 7 Module modFreeModule modFree clsShape#Region "clsShape" PublicClass clsShapeClass clsShape Private m_Area AsDouble Private m_Sides AsInteger PublicSub New()SubNew() m_Area =0.0 m_Sides =0 End Sub PublicSub New()SubNew(ByVal Sides AsInteger) m_Sides = Sides End Sub PublicSub New()SubNew(ByVal Area AsDouble) m_Area = Area End Sub PublicSub New()SubNew(ByVal Area AsDouble, ByVal Sides AsInteger) m_Area = Area m_Sides = Sides End Sub PublicProperty Area()Property Area() AsDouble Get Return m_Area EndGet Set(ByVal Value AsDouble) m_Area = Value EndSet End Property PublicProperty Sides()Property Sides() AsInteger Get Return m_Sides EndGet Set(ByVal Value AsInteger) m_Sides = Value EndSet End Property End Class #End Region clsTriangle#Region "clsTriangle" PublicClass clsTriangleClass clsTriangle Inherits clsShape PublicSub New()SubNew() MyBase.New(3) End Sub PublicSub New()SubNew(ByVal Area AsDouble) MyBase.New(Area, 3) End Sub PublicFunction CalculateArea()Function CalculateArea(ByVal SideBase AsDouble, ByVal Height AsDouble, _ OptionalByVal AssignToArea AsBoolean=False) AsDouble Dim Area AsDouble= (SideBase * Height) /2 If AssignToArea Then Me.Area = Area EndIf Return Area End Function End Class #End Region PublicSub Main()Sub Main() Dim objTriangle AsNew clsTriangle Dim objShape AsNew 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 7.1 Please find the line of code from the procedure Main to cause run-time error. Answer: 7.2 Please write the result output from the procedure Main. Answer: Question 8 Consider the following account and customer tables: cust_tbl cust_id title e_first_name e_last_name address1 . 0 MR Martin Ma . 1 MR Kirs Cheung . 2 MR Ricky Chan . 3 MR Tom Kwan . 4 MR Corporate Default Corporate Default . 5 MRS Mary Mok . . . . . . acc_grp_cust_tbl acc_group Cust_id1 Cust_id2 Cust_id3 Cust_id4 1400012 150034 16005 . . . . . . . . . . The acc_grp_cust_tbl table is responsible to store the customer ID, and the cust_tbl table is responsible to store customer personal information such as name, address, etc… Please write a SQL query in order to provide following result. ACC_GROUP PAYEENAMES 1400 Ma Martin/Cheung Kris/Chan Ricky 1500 Kwan Tom/Corporate Default Corporate Default 1600 Mok Mary . . . . Answer: