Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program to implement a simple address book that stores phone numbers, na

ID: 3861262 • Letter: W

Question

Write a program to implement a simple address book that stores phone numbers, names, and addresses and allows the user to look up an entry based on any of them. After each lookup the program should ask the user if they want to look up another until they are done. The file should be structured so that a person's first name, last name, and phone number are stored on one line separated by commas and the next line has their address. (Note: The program does not need to create the file, just read an already existing file.) Submit: Fully documented and compilable source code along with data file used. IN C++ PLEASE

Explanation / Answer

#include <iostream.h>

#include <fstream.h>

#include <sstream.h>

#include <vector.h>

using namespace std;

void readFile(istream &input, vector< vector<string> > &output)

{

   string ourLine,Flag;

    while( getline(input, ourLine) )

    {

            istringstream ourStream(ourLine);

            vector<string> ourColumn;

            string ourElement;

            while( getline(ourStream, ourElement, ',') )

            {

                 ourColumn.push_back(ourElement);

            }

            output.push_back(ourColumn);

        Cout<<”Do you want to read another entry(Y/N)”;

        Cin>>flag;

        If (flag==”Y”)

        {

                ourLine++;

        }

        If (flag==”N”)

        {

               Exit();

        }

   }

}

int main()

{

    ofstream myfile;

    string a;

    fstream file("File.csv", ios::in);

    myfile.open ("File.csv");

    if(!file.is_open())

    {

           cout << "File not found! ";

            return 1;

}

File.csv contains Phone numbers, names and addresses stored in a structured format in one line with comma separation.

First we will give the file as input in main() function, next it searches for file in the directory, it opens the file if it exists otherwise it throws an error like “file not found”. After opening the file it read each entry in the file through “ReadFile()” function, Here we define a vector which reads the entire row and stores it in an vector object, Later prints the output based on user requirement.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote