Question: Write a program that reads a file of phone numbers and names. The user should then be able to enter a name from the keyboard
Phonebook.txt: (104)496-9416 Adele Write a program that reads a file of phone numbers and names. The user should then be able to enter a name from the keyboard and the program will display the phone number of that person. The program s hould continue to ask for names until the user enters "end" The file phonebook.txt has no more than 100 lines where each line contains: phone number individual's phone number in the format (123)456-7890 the name of the person with this phone number. The name might have multiple parts, such as first and last name, separated by spaces. Some names do not. Your program will want to read the file and create PhoneNumber objects with the name and phone number. The PhoneNumber objects should be kept in an array. The PhoneNumber class should have two class instance variables to hold the phone number and name. It will need a constructor to initialize these two variables to constructor parameters. Program outline numberCoun1 = 0 while more data in the filc read the phone number from the file read the name using nextline0 and trim the name create a PhoneNumber object with the number and name put the object in the array increment numberCount read a desired name from the keyboard while the desired name is not "end" found is false for cach element i in the array up to numberCount if the desired name array i.name display desired name and array[i].phone found is true if not found display not found read a desired name from the keyboard Sample output Enter a name >Jay-2 Jay-2 has the phone number (213) 274-1190 Enter a name >Bruce Springsteen Bruce Springsteen has the phone number (481)250-1133 Enter a name >Donald Trump Donald Trump was not found Enter a name >end page I ofI
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
