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

You will be making a digital rolodex using a doubly linked list. Your program wi

ID: 3913276 • Letter: Y

Question

You will be making a digital rolodex using a doubly linked list. Your program will have the following criteria: 1. Each node in the list will contain the following information about the person: 1. First Name 2. Last Name 3. Address 4. Phone Number 5. Email Address 6. twitter handle. 2. When the program opens it will read contact information from a text file and create a doubly linked list with the information. 3. The user will be able to: search for and display specific user by any piece of information. Exact matches only is fine. Should be able to navigate through a list if there are multiple results. thus, you probably want to sort first. add a contact to the rolodex delete a user from the rolodex sort the rolodex by any piece of information and navigate through it, displaying one contact at a time. (they will need to be able to exit this navigation mode) quit the program. 4. Upon quitting, all contact information should be written back to the text file. The program should be in C++

#include <iostream> #include <string> #include <fstream> using namespace std; struct Address { int streetNumber; string street; string streetType; string city; string state; int zipcode; }; struct Contact { string firstName; string lastName; Address address; string phoneNumber; string emailAddress; string twitterHandle; Contact* next; Contact* prev; }; enum sortBy{FIRST=1,LAST,STREET,CITY,STATE,PHONE,EMAIL,TWITTER}; Contact* loadList(string fileName); Contact* remove_(Contact* contact); Contact* insert_(Contact* contact); void saveList(Contact* head, string fileName); Contact* navigateRolodex(Contact* start, Contact* end); void displayContact(Contact* contact); Contact* search(Contact* head); void addContact(Contact* & head); void removeContact(Contact* & head); void sort(Contact* & head); int main() { string fileName = "contacts.txt"; Contact* rolodex = loadList(fileName); if (rolodex != nullptr) { int command = 0; while (command != 6) { cout << "Welcome to Mr. Orme's Rolodex!" << endl; cout << "What would you like to do? " << endl; cout << " 1. Naviagate through Rolodex" << endl; cout << " 2. Search for a Contact" << endl; cout << " 3. Sort Contacts" << endl; cout << " 4. Add a Contact" << endl; cout << " 5. Remove a Contact" << endl; cout << " 6. Quit" << endl; cin >> command; switch (command) { case 1: navigateRolodex(rolodex, nullptr); break; case 2: search(rolodex); break; case 3: sort(rolodex); break; case 4: addContact(rolodex); break; case 5: removeContact(rolodex); break; case 6: break; default: cout << "Please enter a valid command!" << endl; break; } system("PAUSE"); system("CLS"); } } saveList(rolodex, fileName); } Contact * loadList(string fileName) { ifstream fin; fin.open(fileName); if (!fin.is_open() && !fin.eof()) { cout << "ERROR! No rolodex file! Exiting program" << endl; return nullptr; } //create doubly linked list here! fin.close(); return head; } //removes underscores from street name and city name Contact * remove_(Contact * contact) { for (int i = 0; i < contact->address.street.size(); i++) { if (contact->address.street[i] == '_') contact->address.street[i] = ' '; } for (int i = 0; i < contact->address.city.size(); i++) { if (contact->address.city[i] == '_') contact->address.city[i] = ' '; } return contact; } //replace spaces with underscores. Contact * insert_(Contact * contact) { for (int i = 0; i < contact->address.street.size(); i++) { if (contact->address.street[i] == ' ') contact->address.street[i] = '_'; } for (int i = 0; i < contact->address.city.size(); i++) { if (contact->address.city[i] == ' ') contact->address.city[i] = '_'; } return contact; } void saveList(Contact * head, string fileName) { ofstream fout; fout.open(fileName); //store file here! fout.close(); } Contact* navigateRolodex(Contact * start, Contact * end) { //this function is to display an entry in the rolodex and navigate from "start" to "end" return nullptr; //change this! } void displayContact(Contact * contact) { cout << contact->firstName << " " << contact->lastName << endl << contact->address.streetNumber << " " << contact->address.street << " " << contact->address.streetType << endl << contact->address.city << ", " << contact->address.state << " " << contact->address.zipcode << endl << "Phone: " << contact->phoneNumber << " Email: " << contact->emailAddress << " Twitter: " << contact->twitterHandle << endl; } void displayMenu() { cout << " 1. First Name" << endl << " 2. Last Name" << endl << " 3. Street" << endl << " 4. City" << endl << " 5. State" << endl << " 6. Phone Number" << endl << " 7. Email" << endl << " 8. Twitter Handle" << endl << " 9. CANCEL" << endl; } void addContact(Contact *& head) { //create new contact cout << "Contact Added!!!" << endl; system("PAUSE"); } void removeContact(Contact *& head) { cout << "How do you want to search for the contact: " << endl; Contact* toDelete = search(head); if (toDelete != nullptr) { system("CLS"); cout << "Are you sure you want to delete this contact (y/n):" << endl; displayContact(toDelete); char command = ' '; cin >> command; if (command == 'y' || command == 'Y') { //delete node and update doublly linked list here! cout << "Contacted Deleted!!!" << endl; } else { cout << "Nothing deleted. Returning to main menu" << endl; } } system("PAUSE"); } void swap(Contact* & head, Contact* & contact1, Contact* contact2) { //swap the location of two contacts in the rolodex! //used in sorting! } void sort(Contact *& head, sortBy sortKey) { //if this > 100 lines, there is a better way to do it! } void sort(Contact* & head) { //this is called by the main program. Doesn't do the sorting! system("CLS"); cout << "Sort by: " << endl; displayMenu(); int command; cin >> command; if (command != 9) sort(head, (sortBy)command); } Contact* search(Contact * head) { system("CLS"); //options are same as sortBy enum!!! cout << "Search by: " << endl; displayMenu(); //linear search is the way to go! }

Explanation / Answer

//Answer:

Code:
//Include libraries
#include<cstdlib>
#include<cstdio>
#include<fstream>
#include<string>
#include<iostream>

using namespace std;
//Structure Definition

struct digitalRolodex
{
//Variable Declaration
string FName;
string LName;
string Addr;
string PhnNum;
string EmailAddr;
struct digitalRolodex *next;
struct digitalRolodex *prev;
}*start;
//Class Defination
class DoubleLinkedList
{
//Define access specifier
public:
//Define method
void createRec();
void insRecFirst();
void delRec();
void searchRec();
void displayRec();
DoubleLinkedList();
};
//Define main method
int main()
{
//Declare variables
int choice, element, position;
fstream fp;
fp.open("rolodex.dat", ios::out|ios::app);
DoubleLinkedList dl;
//Loop
while (1)
{
cout<<endl<<"----------------------------"<<endl;
cout<<endl<<" Digital Rolodex Operations"<<endl;
cout<<endl<<"----------------------------"<<endl;
cout<<"1. Create Record"<<endl;
cout<<"2. Insert Record"<<endl;
cout<<"3. Delete Record"<<endl;
cout<<"4. Display All Records"<<endl;
cout<<"5.Quit"<<endl;
cout<<"Enter your choice : ";
cin>>choice;
//Define switch case
switch (choice)
{
case 1:
cout<<" Enter record information: ";
dl.createRec();
cout<<endl;
break;
case 2:
cout<<" Enter record information: ";
dl.insRecFirst();
cout<<endl;
break;
case 3:
if (start == NULL)
{
cout<<"List empty, nothing to delete."<<endl;
break;
}
cout<<" Enter record information to DELETE: ";
dl.delRec();
cout<<endl;
break;
case 4:
if (start == NULL)
{
cout<<"List empty, nothing to display."<<endl;
break;
}
dl.displayRec();
cout<<endl;
break;
case 5:
exit(1);
default:
cout<<"Wrong choice! Try again."<<endl;
}
}
//Pause console window
system("pause");   
return 0;
}
//Define method
DoubleLinkedList::DoubleLinkedList()
{
start = NULL;
}
//Define method
void accept(struct digitalRolodex *temp)
{
cout<<" Enter First Name: ";
cin>>temp->FName;
cout<<" Enter Last Name: ";
cin>>temp->LName;
cout<<" Enter Addr: ";
cin>>temp->Addr;
cout<<" Enter Phone Number: ";
cin>>temp->PhnNum;
cout<<" Enter Email Addr: ";
cin>>temp->EmailAddr;
}
//Define method
void display(struct digitalRolodex *temp)
{
cout<<" Enter First Name: "<<temp->FName;
cout<<" Enter Last Name: "<<temp->LName;
cout<<" Enter Addr: "<<temp->Addr;
cout<<" Enter Phone Number: "<<temp->PhnNum;
cout<<" Enter Email Addr: "<<temp->EmailAddr;
}
//Define method
void DoubleLinkedList::createRec()
{
struct digitalRolodex *s, *temp;
temp = new(struct digitalRolodex);
accept(temp);
temp->next = NULL;
if (start == NULL)
{
temp->prev = NULL;
start = temp;
}
else
{
s = start;
while (s->next != NULL)
s = s->next;
s->next = temp;
temp->prev = s;
}
}
//Define method
void DoubleLinkedList::insRecFirst()
{
if (start == NULL)
{
cout<<"First Create the list."<<endl;
return;
}
struct digitalRolodex *temp;
temp = new(struct digitalRolodex);
temp->prev = NULL;
accept(temp);
temp->next = start;
start->prev = temp;
start = temp;
cout<<"Element Inserted"<<endl;
}
//Define method
void DoubleLinkedList::delRec()
{
struct digitalRolodex *temp = new(struct digitalRolodex), *q= new(struct digitalRolodex);
accept(temp);
if (start->FName == temp->FName && start->LName == temp->LName)
{
temp = start;
start = start->next;
cout<<"Element Deleted"<<endl;
free(temp);
return;
}
q = start;
while (q->next->next != NULL)
{
if (q->next->FName == temp->FName && q->next->LName == temp->LName)
{
temp = q->next;
q->next = temp->next;
temp->next->prev = q;
cout<<"Element Deleted"<<endl;
free(temp);
return;
}
q = q->next;
}
if (q->next->FName == temp->FName && q->next->LName == temp->LName)
{
temp = q->next;
free(temp);
q->next = NULL;
cout<<"Element Deleted"<<endl;
return;
}
cout<<"Element "<<temp->FName<<" not found"<<endl;
}
//Define method
void DoubleLinkedList::displayRec()
{
struct digitalRolodex *q;
if (start == NULL)
{
cout<<"List empty,nothing to display"<<endl;
return;
}
q = start;
cout<<"The Doubly Link List is :"<<endl;
while (q != NULL)
{
display(q);
q = q->next;
}
cout<<"NULL"<<endl;
}

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