Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

User-Operated Directory Assistance. Have you ever tried to call a person at thei

ID: 3634475 • Letter: U

Question

User-Operated Directory Assistance. Have you ever tried to call a person at their business and been told to type in some of the letters of their name on your telephone’s keypad in order to obtain their extension? Write a program to simulate this type of directory assistance. Suppose the names and telephone extensions of all the employees of a company are contained in the text file EMPLOYEES.TXT. Each set of three lines of the file has the three pieces of information: last name, first and middle names(s), and the telephone extension. (The file is filled with the names of the U.S. presidents so that the names will be familiar.) The use should be asked to press buttons for the first three letters of the person’s last name followed by the first letter of the first name. For instance, if the person’s name is Gary Land, the user should type in 5264. The number 5264 is referred to as the “push-button encoding” of the name. (Note: People with different names can have the same push-button encoding – for instance, Herb James and Gary Land.)

The program should declare an array of structures to hold full names, extensions, and push-button encodings. The array should be filled while making a single pass through the file and then sorted by push-button encoding. After the user presses four keys on the keypad, the program should display the names and extensions of all employees having the specified push-button encoding.

Explanation / Answer

Dim fileext(1 To 42) As String Dim code(1 To 42) As String Dim lastname(1 To 42) As String Dim firstname(1 To 42) As String Dim pushbuttonButton As String Dim codestring As String Dim labelcode As String Private Sub cmdExit_Click() End End Sub Private Sub cmdInstruction_Click() Dim instructions As String instructions = "Please enter the first three letters of the person's last name " instructions = instructions & vbCrLf & "followed by the first letter of the first name." MsgBox (instructions), vbInformation, ("Directory Assistance") End Sub Private Sub cmdKey_Click(Index As Integer) lblCodeNumber.Caption = lblCodeNumber.Caption & Right(Str(Index), 1) If Len(lblCodeNumber.Caption) = 4 Then labelcode = lblCodeNumber.Caption For i = 1 To 42 If labelcode = code(i) Then picDisplay.Cls picDisplay.Print lastname(i), firstname(i), fileext(i) End If picDisplay.Print lastname(i), firstname(i), fileext(i) Next i End If If Len(lblCodeNumber.Caption) > 4 Then lblCodeNumber.Caption = "" End If End Sub Private Sub cmdLookUp_Click() lblCodeNumber.Caption = Clear picDisplay.Cls End Sub Private Sub Form_Load() Dim i As Integer, c As Integer j = 1 Open "c:employee.txt" For Input As #1 Do Until EOF(1) Input #1, lastname(j), firstname(j), fileext(j) codestring = Left(lastname(j), 3) codestring = codestring & Left(firstname(j), 1) For i = 1 To 42 Select Case Mid(codestring, i, store) Case "a" To "c" pushButton = pushButton & "2" Case "d" To "f" pushButton = pushButton & "3" Case "g" To "i" pushButton = pushButton & "4" Case "j" To "l" pushButton = pushButton & "5" Case "m" To "o" pushButton = pushButton & "6" Case "p" To "s" pushButton = pushButton & "7" Case "t" To "v" pushButton = pushButton & "8" Case "w" To "z" pushButton = pushButton & "9" End Select code(j) = pushButton Next i pushButton = "" j = j + 1 Loop Close #1 End Sub

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote