// David Barkman
// CSIS 123 - Murtha
// Program 13
//
#include <string>
#include <iostream>
#include <fstream>
using namespace std;
void displayMenu();
void addRecord();
void searchRecords();
string userName;
int main()
{
// Prompt fior 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()
{
// Allocate memory storage
ofstream outFile;
string userString;
// Prompt the user for information
cout << "Please enter the information you wish to add to the file: " << endl;
cin.ignore(100 , '\n');
getline(cin, userString);
// Open the file
outFile.open("c:\\PhoneBook.txt", ios::app);
// Write to the file
outFile << userString << endl;
// Close the file
outFile.close();
// Clear the screen
system("cls");
// Give feedback to the user
cout << "New record has been added." << endl;
} // end addRecord()
void searchRecords()
{
// Allocate memory storage
string userChoice;
ifstream inFile;
string tempString;
int i = 0;
// Prompt the user for search text
cout << "Please enter the text you wish to search for: " << endl;
getline(cin, userChoice);
// Open the file
inFile.open("c:\\PhoneBook.txt");
// Read from the file
while (!inFile.eof())
{
getline(inFile, tempString);
(tried userChoice.find not sure what to do)
cout << tempString << endl;
i++;
} // End While
} // end searchRecord()
void displayMenu()
{
// Allocate memory storage
int userSelection;
while (userSelection != 3)
{
cout << "***************************" << endl;
cout << userName << "'s Phone Book:" << endl;
cout << "1. Add Record" << endl;
cout << "2. Search for Record" << endl;
cout << "3. Quit" << endl;
cout << "***************************" << endl;
// Prompt user for selection
cout << "Your Selection: ";
cin >> userSelection;
// Clear the screen
system("cls");
switch(userSelection)
{
case 1:
addRecord();
break;
case 2:
searchRecords();
break;
case 3:
// End the Program
break;
default:
cout << "Please select 1, 2, or 3" << endl;
} // end Switch
} // end while
} // end displayMenu()
i cant seem to figure out how to write the void function void (searchRecords() ) of Search for matching records tried numerous things, what i need it to do is just search for a record and display it to the user how many matches found, thanks in advance for any assistance rendered