Write a simple telephone directory program in C++ that looks up phone numbers in a file containing a list of names and phone numbers. The user should be prompted to enter a first name and last name, and the program then outputs the corresponding number, or indicates that the name isn't in the directory. After each lookup, the program should ask the user whether they want to look up another number, and then either repeat the process or exit the program. The data on the file should be organized so that each line contains a first name, a last name, and a phone number, separated by blanks. You can return to the beginning of the file by closing it an opening it again.Use functional decomposition to solve the problem and code the solution using functions as appropriate. Be sure to use proper formatting and appropriate comments in your code. The output should be clearly labeled and neatly formatted, and the error messages should be informative.Below is the program I've made, but it's not outputting the phone number. [only asks for name and number]//************************************************// Telephone Directory Program// This program outputs the phone number for// a given person. If person is not found, the// program will indicate that the name isn't in// the telephone directory.//************************************************#include#include#include#include#includeusing namespace std;void FindName(string, string, string);void PhoneNumber(string);int main(){string firstName; // First Namestring lastName; // Last Namestring number; // Phone Numberstring searchName; // First and Last Name Inputifstream inFile;inFile.open("phoneDirectory.dat"); // Opens input fileif ( !inFile ){cout <>}cout <>cin >> firstName >> lastName;searchName = firstName + " " + lastName;cout <><><><>cout <><>cin.get();while (cin.get() == 'y') // If user wants to do another search{cout <>cin >> firstName >> lastName; // Input LinesearchName = firstName + " " + lastName; // Initialize variablecout <><><>cout <><>cin.get();}inFile.close();return 0;}void findName(string, string, string){ifstream inFile;string searchName;inFile.open("phoneDirectory.dat");while (inFile.good()){string lastName, firstName, number;inFile >> firstName >> lastName >> number;searchName = firstName + " " + lastName;}while (inFile.bad()) // If name is not in the directory{cout <>}}void findNumber (string){ifstream inFile;string number;inFile.open("phoneDirectory.dat");}
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here