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

I need helpt on writing address book in C++ Following are the requirements for t

ID: 3763821 • Letter: I

Question

I need helpt on writing address book in C++

Following are the requirements for the address book.

// File: record.h

Definition of record.h

// File: llist.h

class llist
{
  private:
    record *    start;
    char        filename[16];
    int         readfile();
    int         writefile();
    record *    reverse(record * );
    void        cleanup();

  public:
    llist();
    llist(char[]);
    ~llist();
    int addRecord(char[], char[], int, char[]);
    int printRecord(char[]);
    int modifyRecord(char[], char[], char[]);
    void printAll();
    int deleteRecord(char[]);
    void reverse();
};

Requirements:

Define the two following constructors function but you may use either one in your main function

llist mylist;     // Instance of class llist

llist mylist( "proj2.txt" );

You cannot change the class definition without consent

You may create any other functions you like or add to the menu in the interface.

You cannot use any of the C I/O functions. Use the C++ versions instead.

No global variables may be used.

Name may have spaces and addresses may have multiple lines (use getline).

Use ifndef directives for the C++ header files

deleteRecord will delete all records, including duplicates based on the name.

addRecord will create a record even if it already exists with the same name

addRecord must add the record to the end of the list

modifyRecord will modify all records with the same name

printRecord will print on the screen information for all records with the name specified

printAll will print the entire address book on the screen

A make file must be used.

New Requirements:

Implement the reverse method using recursion and add an option to the menu

This will reverse the list without printing it.

Overload the << operator so it replaces the calling of the printAll method in the user-interface. It should not call the printAll method.

Implement debug mode using preprocessor directives, instead of command line arguments.

Explanation / Answer

#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <sstream>

using namespace std;

struct Person
{
string name;
string addr;
string phone;
string id;
};

const int MAX_SIZE = 8;
void addData(Person list[], int& size);
void dispData(const Person list[], int size);
void delData (const Person list[], int size);
void saveFile(const Person list[], int size);
void openFile(Person list[], int& size);
char getMenuResponse();  
int main(int argc, char *argv[])
{
Person contactList[MAX_SIZE];
int numOfRecs = 0;
bool run = true;
do
{
cout << "Address Book - " << numOfRecs << " Number of Contacts" << endl;
switch ( getMenuResponse() )
{
case 'A': addData(contactList, numOfRecs); break;
case 'D': dispData(contactList, numOfRecs); break;
case 'T': delData(contactList, numOfRecs); break;
case 'O': openFile(contactList, numOfRecs); break;
case 'S': saveFile(contactList, numOfRecs); break;
case 'Q': run = false; break;
default : cout << "That is NOT a valid choice" << endl;
}
} while (run);
cout << endl << "Program Terminated" << endl;


return EXIT_SUCCESS;
}

void addData(Person list[], int& size)
{
Person tmp;
char response;
char str[256];
if (size < MAX_SIZE) {
system("cls");
cout << "Enter Contact Information" << endl << endl;
cout << "Name: ";

cin.getline(str, 256, ' ');
tmp.name = str;
cout << endl;
cout << "Address: ";
cin.getline(str, 256, ' ');
tmp.addr = str;
cout << endl;
cout << "Phone Number: ";
cin.getline(str, 256, ' ');
tmp.phone = str;
cout << endl;
cout << "E-mail id Address: ";
cin.getline(str, 256, ' ');
tmp.id = str;
cout << endl;
  
cout << "Add Contact to Address Book? (y/n) ";
cin >> response;
if (toupper(response) == 'Y')
list[size++] = tmp;
} else {
cout << "Sorry, Address Book is currently full." << endl;
system("pause");
}
system("cls");
}

void dispData(const Person list[], int size)
{
system("cls");

if(size < 1)
{
cout << "Nothing to display" << endl;
} else {
cout << "Contacts :" << endl << endl;
cout << fixed << setprecision(2);
cout << "Contact Name Address Phone No. ID" << endl;
  

cout << left;
for (int i = 0; i < size; i++)
{
cout << setw(10) << list[i].name << right
<< setw(10) << list[i].addr<<right
<< setw(10) << list[i].phone<<left
<< setw(15) << list[i].id<<left<<endl;
}


cout << right << setw(3) << size;
cout << " Contacts"<< endl;
}

system("PAUSE");
system("cls");
}

void delData(const Person list[],int size) {
vector<Person> :: iterator vItr = Contact.begin();
while (vItr != Contact.end() )
{
if (vItr->Name == Name)
{
vItr = Contact.erase (vItr);
break;
}
else
vItr++;
}


void saveFile(const Person list[], int size) {
string fileName;
ofstream outfi;
cout<<"Enter file name: ";
getline(cin,fileName);
outfi.open(fileName.c_str());


if (!outfi.fail()) {
system("cls");
cout << "Saving Address Book to the disc ";

for(int i = 0; i < size; i++) {
outfi << list[i].name << ';'
<< list[i].addr<< ';';

if (i < size-1) outfi << endl;
}
cout << endl << size << " Address Book in the disc." << endl;
outfi.close();
system("PAUSE");
system("cls");
}
else {
cout << "ERROR: problem with file" << endl;
system("PAUSE");
system("cls");
}
}


void openFile(Person list[], int& size)
{
ifstream infi("AddressBook.txt");
string str;
stringstream strstrm;


if (!infi.fail()) {

system("cls");
cout << "Reading Address Book from the disc ";

size = 0;
while(!infi.eof() && size < MAX_SIZE)
{

getline(infi, str, ';');
list[size].name = str;


getline(infi, str, ';');
strstrm.str(""); strstrm.clear();
strstrm << str;
strstrm >> list[size].addr;

}
cout << endl << size << " read contacts from the disc." << endl;


system("PAUSE");
system("cls");
}
else {
cout << "ERROR :file not accepted" << endl;
system("PAUSE");
system("cls");
}

}

char getMenuResponse()

{
char response;
cout << endl << "take chioce" << endl
<< "(A)dd contact, (D)isplay contact0, (O)pen File, (S)ave File, (Q)uit" << endl
<< "> ";
cin >> response;
cin.ignore(256, ' ');  

return toupper(response);

}