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

hey can I get an working example of how to do this program without using the \"S

ID: 3700928 • Letter: H

Question

hey can I get an working

example of how to do this program without using the "STL"standard library data structures

Write an address book program that will accomplish the tollowing 1. Read name and address data from the user either from the keyboard or from a fie. 2 While reading the names and addresses, put the names into an appropniate data structure and addresses, allow user to search for names and change the names or addresses in the container data structure 4 Allow user to write out the container data structure to a comma delimited file, this file is diffterent from the input file The input fle wil have the following form, 1 line for the name the next line for e address address address

Explanation / Answer

// AddressBook.cpp : Defines the entry point for the console application.

//

#include "stdafx.h"

#include <string>

#include <vector>

#include <fstream>

#include <iostream>

using namespace std;

struct Address {

string name_;

string address_;

Address(string name, string address)

{

name_ = name;

address_ = address;

}

string ToString() const

{

return name_ + "," + address_;

}

};

vector<Address> AddressBook;

void ReadFromFile()

{

string fileName;

cout << "Enter file name: ";

cin >> fileName;

ifstream inFile(fileName);

string line, name, address;

bool isName = true;

while (getline(inFile, line))

{

if (isName)

{

name = line;

isName = false;

continue;

}

address = line;

Address address(name, line);

AddressBook.emplace_back(address);

isName = true;

}

}

void ModifyEntry(Address& address)

{

string name, addr;

cout << "Enter new value for name: ";

cin >> name;

cout << "Enter new value for address: ";

cin >> addr;

address.name_ = name;

address.address_ = addr;

cout << "Entry modified.";

}

void Search()

{

string name;

int input;

cout << "Enter name to search: ";

cin >> name;

for (auto& item : AddressBook)

{

if (item.name_ == name)

{

cout << "Entry found: " << endl << "Name- " << item.name_ << endl << "Address- " << item.address_<< endl;

cout << "Press 1 if you want to edit the entry. Press 0 otherwise";

cin >> input;

if (input == 0)

return;

ModifyEntry(item);

break;

}

}

cout << "No entry found with name- " << name;

}

void SaveToFile()

{

string fileName = "address_book.txt";

if (AddressBook.empty())

return;

ofstream outFile(fileName);

for (const auto& item : AddressBook)

{

outFile << item.ToString() << endl;

}

cout << "Phonebook saved to " << fileName;

}

int main()

{

int input;

while (1)

{

cout << "MENU" << endl << "1. Read from file" << endl << "2. Search" << endl << "3. Save to a file" << endl << "4. Exit";

cin >> input;

switch (input)

{

case 1:

ReadFromFile();

break;

case 2:

Search();

break;

case 3:

SaveToFile();

break;

case 4:

break;

break;

default:

break;

}

}

system("pause");

return 0;

}