/* * Joseph Otero - s1109073 * CSIS 123 - Murtha * Program 13 - Address Book * Search and create contact records, it's a hoot! */ #include #include #include using namespace std; string userName; int main() { // prompt for the user name cout << "Please enter your name to begin: "; // input the user name: getline(cin,userName); // clear the screen system("cls"); // display the menu: displayMenu(); return 0; } // end main() void addRecord() { string contact; ofstream addRec; addRec.open('C:\\PhoneBook.txt', ios::app); cout << "Enter the phone book information to save:" << endl; getline(cin,contact); addRec << contact << endl; addRec.close(); // clear the screen system("cls"); cout << "\n New record added.\n\n"; displayMenu(); } // end addRecord void displayMenu() { // declare variable for user selection int selection; // display pretty formatted menu cout << "***********************\n"; cout << " " + userName + "'s Phone Book:\n"; cout << " 1. Add Record\n"; cout << " 2. Search for Record\n"; cout << " 3. Quit\n"; cout << "***********************\n"; cout << " Your selection: "; // user inputs selection cin >> selection; cin.ignore(); // condition for option 1 if(selection == 1) { // call addRecord() function addRecord() } // condition for option 2 else if(selection == 2) { // call searchRecords() function searchRecords() } // condition for option 3 else if(selection == 3) { // exit application } // a message for morons and fat fingered people else { // clear screen system("cls") // suggest valid input cout << "\n Please enter 1, 2, or 3.\n\n; // display the menu displayMenu() } } // end displayMenu() void searchRecords() { ifstream inFile, record; string query; int i = 0; inFile.open('C:\\PhoneBook.txt'); cout << "Enter text to find: "; getline(cin,query); while(inFile >> record) { if(record.find(query) != string::npos) { i++; cout << endl << record << endl; } } // stuff goes here if(i == 0) { cout << "\n\nNo matching records found.\n\n"; } else if(i == 1) { cout << "\n\nOne matching record found.\n\n"; } else { cout << "\n\n" << i << " matching records found.\n\n"; } inFile.close(); // clear screen system("cls") // display the menu displayMenu() } // end searchRecords()