1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
#include <cstdlib>
#include <conio.h>
#include "addressbook.h"
#include "menu.h"
using namespace std;
using derek::Menu;
using derek::PERSON;
using derek::addressBook;
void addPerson();
void getPerson();
void searchLast();
void getPerson();
void searchBoth();
void searchLast();
void printBook();
void ExitBook();
void sortBook();
int main()
{
Menu *mnu = Menu::Instance();
addressBook *ab = addressBook::Instance();
mnu->addMenu("1. Add To Address Book", addPerson);
mnu->addMenu("2. Get Person ", getPerson);
mnu->addMenu("3. Search by last name", searchLast);
mnu->addMenu("4. Search by first & last name", searchBoth);
mnu->addMenu("5. Print Address Book", printBook);
mnu->addMenu("6. Sort Address Book", sortBook);
mnu->addMenu("7. Exit Address Book " , ExitBook);
mnu->runMenu();
/*
PERSON p;
// use this to test overloaded constructor
PERSON people[] =
{{"Glenn","Stevenson","123 South"},
{"Joe","Smith","1 main st."},
{"Bob","Black","28237 La Piedra"}
};
addressBook ab1(people,3);
*/
return 0;
}
void addPerson()
{
Menu *mnu = Menu::Instance();
addressBook *ab = addressBook::Instance();
PERSON p;
cin >> p.fName;
cin >> p.lName;
cin >> p.Address;
ab->addPerson(p);
mnu->waitKey();
}
void getPerson()
{
Menu *mnu = Menu::Instance();
addressBook *ab = addressBook::Instance();
bool status;
PERSON p;
status = ab->getPerson(p);
if(status)
cout << p.fName << "\t" << p.lName << " " << p.Address << endl;
else
cout << "Sorry The address book is empty " << endl;
mnu->waitKey();
}
void searchLast()
{
Menu *mnu = Menu::Instance();
addressBook *ab = addressBook::Instance();
bool status;
PERSON p;
char lName[50];
cout << "Enter a last name " << endl;
cin >> lName;
status = ab->findPerson(lName,p);
if(status)
cout << p.fName << "\t" << p.lName << " " << p.Address << endl;
else
cout << "Sorry, Name not found " << endl;
mnu->waitKey();
}
void searchBoth()
{
Menu *mnu = Menu::Instance();
addressBook *ab = addressBook::Instance();
bool status;
char lName[50];
char fName[50];
PERSON p;
cout << "Enter last name " << endl;
cin >> lName;
cout << "Enter first name " << endl;
cin >> fName;
status = ab->findPerson(lName, fName, p);
if(status)
cout << p.fName << "\t" << p.lName << " " << p.Address << endl;
else
cout << "Sorry, Name not found " << endl;
mnu->waitKey();//Lab 8 related
}
void printBook()
{
int recBook = 1;
Menu *mnu = Menu::Instance();
addressBook *ab = addressBook::Instance();
ab->printBook();
ab->writeRecord();
mnu->waitKey();
}
void sortBook()
{
Menu *mnu = Menu::Instance();
addressBook *ab = addressBook::Instance();
cout << "Sorting Book, Please wait" << endl;
ab->sort();
cout << "Address Book is sorted, press any key to continue" << endl;
mnu->waitKey();
}
void ExitBook()
{
cout << "Thanks for using the address book " << endl;
exit(0);
}
| |