Write a c++ program that will set up a data base for a phone index. The key will
ID: 654022 • Letter: W
Question
Write a c++ program that will set up a data base for a phone index. The key will be a persons name and the table will supply the phone number. The data base must be implemented as a hash table with the names as the key. The format will be a person name followed by a phone number. Example: Wayne Leton 601-5433 or C J 397-1234. Only one name and one phone number will be on an input line. Set your hash table up to be 31 entries, hash table is 31 in size. Print out the final data base (hash table) and indicate how many collisions (error checking) were made in building the data base.
After building the Phone Index, test run the program with the input data given below to show examples of looking up a name and returning a phone number. Remember to read in the file as a .txt file.
Print out all the data. Make sure that you use Microsoft Visual Studio to generate the output. Use system("pause); to keep the output on screen.
-Input Data-
Taylor marie 939-1512
james wilis thomas 261-8342
Stone Rock 544-2372
lea high lee 266-8324
stephens reynolds 696-9231
mack russell 123-1234
Lewis Michelle Tee 828-2148
john marshall 888-2891
Moto hasey 823-8000
oe vey 177-1423
Twoseeor knocksee 823-8321
Legg T. 587-2839
Hofstra M. 601-3225
Malioneyh P. J. 287-4344
Morier G. E. 544-2319
Hauser M. 606-2940
Currie W. D. 701-4281
Hoos R. Dadie 818-3821
Smelly Tau 707-7281
Tobe Cir 613-2414
Tyosn Chicken 602-3152
TooB OrNot 283-5214
SixOne Other 843-2343
Big Tow 384-5624
Zevent Heaven 834-2563
Mighty Mouse 222-2222
G P Morier 832-4562
Explanation / Answer
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
#include <cmath>
using namespace std;
int main()
{
ifstream inFile1;
string firstName;
string lastName;
string phoneNumber;
string firstNamedoc;
string lastNamedoc;
string phoneNumberdoc;
int playagain;
//getline(cin, phoneNumberdoc);
//ifstream Infile1;
inFile1.open("TelephoneDirectory.txt");
//exit if file cannot be opened
if (!inFile1)
{
cout <<"Cannot open input file."<<endl;
return 0;
}
//Order of data from file
inFile1 >>firstNamedoc >> lastNamedoc >> phoneNumberdoc;
do
{
//Ask user to enter first and last name.
cout<<"Please enter the first and last name to look up, seperated by a space: " <<endl;
cin>> firstName >> lastName;
{
//inFile1 >> firstNamedoc >> lastNamedoc>>phoneNumberdoc;
if( firstName == firstNamedoc && lastName == lastNamedoc)
cout<< phoneNumberdoc <<endl;
else
cout<<"Number was not in directory."<<endl;
}
cout <<"Want to continue looking? 0 for no, 1 for yes. " <<endl;
cin >>playagain;
}
while (playagain == 1);
system("PAUSE");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.