// 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

Edited 3 Years Ago by mike_2000_17: Fixed formatting

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

As a new member, maybe you can help us out. Is there something we can do when someone becomes a new member so that they will read the rules about posting as requested? What would have enticed you to read them?

Just looking for a little input... Thanks.

Since you read the record into tempString , then tempString.find would work better.

Also read this about while (!inFile.eof()) (feof() is identical to .eof())

sorry i wasnt aware i broke a rule i did read the "read this before posting" before i posted the only rule i could think that i broke was the "only a small snippet" but i figured since i highlighted the code i was working on that sufficed. I figured putting the rest of the code in there would show my effort that i put into this program, so you could see i wasnt looking for someone to do my homework. Sorry for whatever rule i broke.
Anyway thanks for your reply, but it seems whatever string i use to do a .find it returns an error and doesnt seem to work, i used the userChoice to store whatever the user inputed, so i was curious how tempString would work to find search text? thank in advance for the help!

I guess i just dont really understand the whole search thing, if you didnt already notice this is a phone book program, and i need it to be able to search for and display results that the user inputs and display how many matches it found

I figured putting the rest of the code in there would show my effort that i put into this program, so you could see i wasnt looking for someone to do my homework.

Sure it shows your effort, but there's no indentation that makes the code readable.
Justlikeinenglishifyoudontusespacingcorrectlyyoucanteasilyreadthesentence.

...but it seems whatever string i use to do a .find it returns an error and doesnt seem to work, i used the userChoice to store whatever the user inputed, so i was curious how tempString would work to find search text? thank in advance for the help!

Since we have no idea what you tried, no idea what was in the variables, no clue what the error was, what would you like me to tell you?

This article has been dead for over six months. Start a new discussion instead.