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

Using Visual Studio The 10 names on the txt file Robert Smith John Adams Charles

ID: 658656 • Letter: U

Question

Using Visual Studio

The 10 names on the txt file

Robert Smith
John Adams
Charles Xavier
Clark Kent
Eric Clapton
Pat Benetar
Abraham Lincoln
Paul Revere
Jimi Hendrix
Angelina Jolie

For this lab: you will write a program that reads in a list of ten names from a data file (lab 12data.txt). It will then ask the user for a name to search for; and form the user if the name is on the list. It will then ask the user if they want to search for another name, and if so: repeat the process. What name do you want to search for: Clark Kent The name Clark Kent was found on the list Do you want to search for another name ? Y What name do you want to search for: Bruce Wayne The name Bruce Wayne was not found on the list Do you want to search for another name ?n Press any key to continue ..

Explanation / Answer

Program:

// this is vb program done in visual studio 2012 express

// create console application

Module Module1

    Sub Main()

        Dim key As String

        Dim choice As String = "Y"

        Dim i As Integer

        Dim flag As Integer = 0

        Dim names(20) As String

        Dim fileReader As System.IO.StreamReader

        Dim count As Integer = 0

        fileReader =

        My.Computer.FileSystem.OpenTextFileReader("C:\lab12data.txt")

        Dim sLine As String

        Do

            sLine = fileReader.ReadLine()

            If Not sLine Is Nothing Then

                names(count) = sLine

                count = count + 1

            End If

        Loop Until sLine Is Nothing

        Do Until (StrComp(choice, "Y", CompareMethod.Text) = 0)

            Console.WriteLine("What name do you want to search for:")

            key = Console.ReadLine()

            For i = 0 To 10

                If (StrComp(names(i), key, CompareMethod.Text) = 0) Then

                    Console.WriteLine("The name " + key + " was found on the list")

                    flag = 1

                    Exit For

                End If

            Next

            If flag = 0 Then

                Console.WriteLine("The name " + key + " was not found on the list")

            End If

            Console.WriteLine("Do you want to search for other name:<Y/N>")

            choice = Console.ReadLine()

        Loop

    End Sub

End Module

Output:

What name do you want to search for:

Paul Revere

The name Paul Revere was found on the list

Do you want to search for other name: <Y/N>

Y

What name do you want to search for:

Obama

The name Obama was found on the list

Do you want to search for other name: <Y/N>

N

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