Sample data is available.
/* Brian Baker CS 121 | 18 Oct 96 */
/******************************** PHONE.CPP *********************************
* This program demonstrates the PhoneBook class, located in the files *
* phonebk.h and phonebk.cpp. The program asks for the name of a data file, *
* which contains commands and data for the program. Commands can consist of*
* A (add), D (delete), or L (lookup). "A" should be followed by the *
* complete set of data, while "D" and "L" are followed simply by the last *
* and first name of the person. The program also uses a second input *
* bound to the input file in order to echo the command line. *
**************************************************************** 18 Oct 96 */
#include <iostream.h>
#include <fstream.h>
#include <conio.h>
#include <ctype.h>
#include bool.h
#include "phonebk.cpp"
int main()
{
ifstream input;
ifstream echo; // to echo commands
char inputline[81]; // for echoing commands
char inputfilename[41];
char command;
Boolean success; // command completed successfully
PhoneBook book;
char dummy; // to eat newline characters
PhoneNumType found_number;
AddressType found_address;
PhoneRec temp;
NameType temp_name;
clrscr();
cout << "PHONE.EXE\n";
cout << "A virtual phonebook, by Brian Baker\n";
cout << "Written 18 Oct 96, for CS 121 at Bradley University\n";
do
{
cout << "\nPlease enter the name of the input file (*.fon): ";
cin >> inputfilename;
input.open(inputfilename);
echo.open(inputfilename);
} while (!input);
do
{
success=FALSE;
echo.getline(inputline, 81);
cout << "\nCOMMAND: " << inputline;
input >> command;
switch (toupper(command)) {
case 'A' : input >> temp.number.areaCode >> temp.number.prefix
>> temp.number.lastDigs >> temp.name.last
>> temp.name.first >> temp.spouse.last
>> temp.spouse.first >> temp.address.city;
input.get(dummy);
input.get(temp.address.address, 60, '\n');
book.AddPhone(temp, success);
if (success)
cout << "Entry added for " << temp.name.first << ' '
<< temp.name.last << ".\n";
else cout << "Entry could not be added for "
<< temp.name.first << ' ' << temp.name.last
<< ".\n";
break;
case 'D' : input >> temp_name.last >> temp_name.first;
book.DelPhone(temp_name, success);
if (success)
cout << "Entry for " << temp_name.first << ' '
<< temp_name.last << " deleted.\n";
else
cout << "Entry for " << temp_name.first << ' '
<< temp_name.last << " was not deleted.\n";
break;
case 'L' : input >> temp_name.last >> temp_name.first;
book.LookupByName(temp_name, success, found_number,
found_address);
if (success) {
cout << "The following entry was found:\n\n";
cout << temp_name.first << ' ' << temp_name.last
<< endl << found_address.address << ' '
<< found_address.city << endl << '('
<< found_number.areaCode << ')'
<< found_number.prefix << '-'
<< found_number.lastDigs << endl;
}
else cout << "Entry was not found for "
<< temp_name.first << ' ' << temp_name.last
<< endl;
break;
}
} while (input.good()); // continue processing until EOF
return 0;
}