SlideShare a Scribd company logo
1 of 31
#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 << "t1. Naviagate through Rolodex" <<
endl;
cout << "t2. Search for a Contact" << endl;
cout << "t3. Sort Contacts" << endl;
cout << "t4. Add a Contact" << endl;
cout << "t5. Remove a Contact" << endl;
cout << "t6. 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;
}
Contact* head = nullptr;
Contact * currNode = head;
Contact * temp = nullptr;
while (!fin.eof())
{
temp = new Contact;
temp->next = nullptr;
temp->prev = nullptr;
fin >> temp->firstName;
fin >> temp->lastName;
fin >> temp->address.streetNumber;
fin >> temp->address.street;
fin >> temp->address.streetType;
fin >> temp->address.city;
fin >> temp->address.state;
fin >> temp->address.zipcode;
fin >> temp->phoneNumber;
fin >> temp->emailAddress;
fin >> temp->twitterHandle;
temp = remove_(temp);
if (currNode == nullptr)
{
head = temp;
currNode = head;
}
else
{
currNode->next = temp;
temp->prev = currNode;
currNode = currNode->next;
}
}
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);
Contact * currNode = head;
while (currNode != nullptr)
{
currNode = insert_(currNode);
fout << currNode->firstName << " ";
fout << currNode->lastName << endl;
fout << currNode->address.streetNumber << " ";
fout << currNode->address.street << " ";
fout << currNode->address.streetType << " ";
fout << currNode->address.city << " ";
fout << currNode->address.state << " ";
fout << currNode->address.zipcode << endl;
fout << currNode->phoneNumber << " ";
fout << currNode->emailAddress << " ";
fout << currNode->twitterHandle;
if (currNode->next != nullptr)
cout << endl;
currNode = currNode->next;
}
fout.close();
}
Contact* navigateRolodex(Contact * start, Contact * end)
{
//can't start navigating from nowhere.
if (start == nullptr) return nullptr;
//when end is nullptr, we want to go to the end of the list
//so we need to change end to the last item of the list.
if (end == nullptr)
{
end = start;
while (end->next != nullptr)
{
end = end->next;
}
}
Contact* currContact = start;
char command = ' ';
while (command != 'q')
{
system("CLS");
displayContact(currContact);
cout << "<<(p)revious, (q)uit, (n)ext>>";
cin >> command;
switch (command)
{
case 'p':
if (currContact != start)
{
currContact = currContact->prev;
}
break;
case 'n':
if (currContact != end)
{
currContact = currContact->next;
}
break;
case 'q':
break;
default:
cout << "Invalid Command!" << endl;
system("PAUSE");
break;
}
}
return currContact;
}
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 << "t1. First Name" << endl
<< "t2. Last Name" << endl
<< "t3. Street" << endl
<< "t4. City" << endl
<< "t5. State" << endl
<< "t6. Phone Number" << endl
<< "t7. Email" << endl
<< "t8. Twitter Handle" << endl
<< "t9. CANCEL" << endl;
}
void addContact(Contact *& head)
{
//create new contact and make new head.
Contact* temp = new Contact;
temp->next = head;
temp->prev = nullptr;
head->prev = temp;
head = temp;
//get information
cout << "Please enter the contact's information: " << endl;
cout << "First and Last name: ";
cin >> temp->firstName >> temp->lastName;
cout << "Street (i.e. 123 W_Main St): ";
cin >> temp->address.streetNumber >> temp-
>address.street >> temp->address.streetType;
cout << "City (put an underscore _ between words): ";
cin >> temp->address.city;
do {
cout << "State (2 letter abbreviation): ";
cin >> temp->address.state;
} while (temp->address.state.size() != 2);
cout << "Zipcode: ";
cin >> temp->address.zipcode;
cout << "Phone (xxx-xxx-xxxx): ";
cin >> temp->phoneNumber;
cout << "Email Address: ";
cin >> temp->emailAddress;
cout << "Twitter Handle: ";
cin >> temp->twitterHandle;
remove_(temp);
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')
{
if (toDelete == head)
head = toDelete->next;
if (toDelete->next != nullptr)
toDelete->next->prev = toDelete->prev;
if (toDelete->prev != nullptr)
toDelete->prev->next = toDelete->next;
delete toDelete;
cout << "Contacted Deleted!!!" << endl;
}
else
{
cout << "Nothing deleted. Returning to main
menu" << endl;
}
}
system("PAUSE");
}
void swap(Contact* & head, Contact* & contact1, Contact*
contact2)
{
//deal with head.
if (contact1 == head)
{
head = contact2;
}
else if (contact2 == head)
{
head = contact1;
}
//take care of other things pointing at swappers, but only if
they are not adjacent. . .
if (contact1->next != nullptr && contact1->next !=
contact2)
contact1->next->prev = contact2;
if (contact2->next != nullptr && contact2->next !=
contact1)
contact2->next->prev = contact1;
if (contact1->prev != nullptr && contact1->prev !=
contact2)
contact1->prev->next = contact2;
if (contact2->prev != nullptr && contact2->prev !=
contact1)
contact2->prev->next = contact1;
//take care of swappers previous and next
if (contact1->next == contact2) //adjacent, option 1
{
contact1->next = contact2->next;
contact2->next = contact1;
contact2->prev = contact1->prev;
contact1->prev = contact2;
}
else if (contact2->next == contact1) //adjacent, option 2
{
contact2->next = contact1->next;
contact1->next = contact2;
contact1->prev = contact2->prev;
contact2->prev = contact1;
}
else // not adjacent
{
Contact * temp = contact1->next;
contact1->next = contact2->next;
contact2->next = temp;
temp = contact1->prev;
contact1->prev = contact2->prev;
contact2->prev = temp;
}
contact1 = contact2;
}
void sort(Contact *& head, sortBy sortKey)
{
Contact* sorted = head;
Contact* currContact = nullptr;
Contact* smallest = nullptr;
while (sorted != nullptr)
{
currContact = sorted;
smallest = sorted;
//find smallest
while (currContact != nullptr)
{
bool smallestContact = false;
switch (sortKey)
{
case FIRST:
if (currContact->firstName < smallest-
>firstName)
smallestContact = true;
break;
case LAST:
if (currContact->lastName < smallest-
>lastName)
smallestContact = true;
break;
case STREET:
{
string fullAddress =
to_string(currContact->address.streetNumber) + " " +
currContact->address.street + " " + currContact-
>address.streetType;
string smallestFullAddress =
to_string(smallest->address.streetNumber) + " " + smallest-
>address.street + " " + smallest->address.streetType;
if (fullAddress <
smallestFullAddress) smallestContact = true;
break;
}
case CITY:
if (currContact->address.city < smallest-
>address.city) smallestContact = true;
break;
case STATE:
if (currContact->address.state < smallest-
>address.state) smallestContact = true;
break;
case PHONE:
if (currContact->phoneNumber < smallest-
>phoneNumber) smallestContact = true;
break;
case EMAIL:
if (currContact->emailAddress < smallest-
>emailAddress) smallestContact = true;
break;
case TWITTER:
if (currContact->twitterHandle < smallest-
>twitterHandle) smallestContact = true;
break;
}
if (smallestContact)
{
smallest = currContact;
}
currContact = currContact->next;
}
//swap
swap(head, sorted, smallest);
sorted = sorted->next;
}
}
void sort(Contact* & head)
{
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();
int command = 0;
cin >> command;
if (command != 9)
{
//sort the list
sort(head, (sortBy)command);
cout << "Search text: ";
string searchString;
cin >> searchString;
//search the list
Contact* start = nullptr, *end = nullptr, *currContact
= head;
bool found;
do
{
found = false;
switch (command)
{
case 1:
if (currContact->firstName ==
searchString) found = true;
break;
case 2:
if (currContact->lastName == searchString)
found = true;
break;
case 3:
{
string fullAddress =
to_string(currContact->address.streetNumber) + " " +
currContact->address.street + " " + currContact-
>address.streetType;
if (fullAddress == searchString)
found = true;
break;
}
case 4:
if (currContact->address.city ==
searchString) found = true;
break;
case 5:
if (currContact->address.state ==
searchString) found = true;
break;
case 6:
if (currContact->phoneNumber ==
searchString) found = true;
break;
case 7:
if (currContact->emailAddress ==
searchString) found = true;
break;
case 8:
if (currContact->twitterHandle ==
searchString) found = true;
break;
}
if (found)
{
if (start == nullptr)
{
start = currContact;
end = currContact; //in case there is
only one. . .
}
else
{
end = currContact;
}
}
currContact = currContact->next;
} while ((end == nullptr || found == true) &&
currContact != nullptr);
if (start == nullptr && end == nullptr)
{
cout << searchString << " not found!!" << endl;
return nullptr;
}
else
{
return(navigateRolodex(start, end));
}
}
}

More Related Content

Similar to #include iostream#include string#include fstreamusi.docx

-- main-cpp #include -iostream- #include -ContactNode-h- int main().docx
-- main-cpp #include -iostream- #include -ContactNode-h-   int main().docx-- main-cpp #include -iostream- #include -ContactNode-h-   int main().docx
-- main-cpp #include -iostream- #include -ContactNode-h- int main().docxAndrewGmjOliverf
 
-- main-cpp #include -iostream- #include -ContactNode-h- int main().docx
-- main-cpp #include -iostream- #include -ContactNode-h-   int main().docx-- main-cpp #include -iostream- #include -ContactNode-h-   int main().docx
-- main-cpp #include -iostream- #include -ContactNode-h- int main().docxStevenHO9Kellyp
 
Help with the following code1. Rewrite to be contained in a vecto.pdf
Help with the following code1. Rewrite to be contained in a vecto.pdfHelp with the following code1. Rewrite to be contained in a vecto.pdf
Help with the following code1. Rewrite to be contained in a vecto.pdfezzi97
 
#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdfharihelectronicspune
 
I have the following code and I need to know why I am receiving the .pdf
I have the following code and I need to know why I am receiving the .pdfI have the following code and I need to know why I am receiving the .pdf
I have the following code and I need to know why I am receiving the .pdfezzi552
 
Getting the following errorsError 1 error C2436 {ctor} mem.pdf
Getting the following errorsError 1 error C2436 {ctor}  mem.pdfGetting the following errorsError 1 error C2436 {ctor}  mem.pdf
Getting the following errorsError 1 error C2436 {ctor} mem.pdfherminaherman
 
Doublylinklist
DoublylinklistDoublylinklist
Doublylinklistritu1806
 
In C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdfIn C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdffantoosh1
 
Rewrite this code so it can use a generic type instead of integers. .pdf
Rewrite this code so it can use a generic type instead of integers. .pdfRewrite this code so it can use a generic type instead of integers. .pdf
Rewrite this code so it can use a generic type instead of integers. .pdfalphaagenciesindia
 
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdfTHE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdffathimahardwareelect
 
#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docx#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docxajoy21
 
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdfAssignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdfformicreation
 
Solution#includestdio.h#includeconio.h#includealloc.h.pdf
Solution#includestdio.h#includeconio.h#includealloc.h.pdfSolution#includestdio.h#includeconio.h#includealloc.h.pdf
Solution#includestdio.h#includeconio.h#includealloc.h.pdfpoddaranand1
 
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjhlinked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjhvasavim9
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfEricvtJFraserr
 
i nsert+in+ link list
i nsert+in+ link listi nsert+in+ link list
i nsert+in+ link listEAJAJAhamed
 
There are a number of errors in the following program- All errors are.docx
There are a number of errors in the following program- All errors are.docxThere are a number of errors in the following program- All errors are.docx
There are a number of errors in the following program- All errors are.docxclarkjanyce
 
C++Write a method Node Nodereverse() which reverses a list..pdf
C++Write a method Node Nodereverse() which reverses a list..pdfC++Write a method Node Nodereverse() which reverses a list..pdf
C++Write a method Node Nodereverse() which reverses a list..pdfarjunenterprises1978
 

Similar to #include iostream#include string#include fstreamusi.docx (20)

-- main-cpp #include -iostream- #include -ContactNode-h- int main().docx
-- main-cpp #include -iostream- #include -ContactNode-h-   int main().docx-- main-cpp #include -iostream- #include -ContactNode-h-   int main().docx
-- main-cpp #include -iostream- #include -ContactNode-h- int main().docx
 
-- main-cpp #include -iostream- #include -ContactNode-h- int main().docx
-- main-cpp #include -iostream- #include -ContactNode-h-   int main().docx-- main-cpp #include -iostream- #include -ContactNode-h-   int main().docx
-- main-cpp #include -iostream- #include -ContactNode-h- int main().docx
 
Help with the following code1. Rewrite to be contained in a vecto.pdf
Help with the following code1. Rewrite to be contained in a vecto.pdfHelp with the following code1. Rewrite to be contained in a vecto.pdf
Help with the following code1. Rewrite to be contained in a vecto.pdf
 
#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf
 
I have the following code and I need to know why I am receiving the .pdf
I have the following code and I need to know why I am receiving the .pdfI have the following code and I need to know why I am receiving the .pdf
I have the following code and I need to know why I am receiving the .pdf
 
Getting the following errorsError 1 error C2436 {ctor} mem.pdf
Getting the following errorsError 1 error C2436 {ctor}  mem.pdfGetting the following errorsError 1 error C2436 {ctor}  mem.pdf
Getting the following errorsError 1 error C2436 {ctor} mem.pdf
 
Doublylinklist
DoublylinklistDoublylinklist
Doublylinklist
 
DSA(1).pptx
DSA(1).pptxDSA(1).pptx
DSA(1).pptx
 
In C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdfIn C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdf
 
Rewrite this code so it can use a generic type instead of integers. .pdf
Rewrite this code so it can use a generic type instead of integers. .pdfRewrite this code so it can use a generic type instead of integers. .pdf
Rewrite this code so it can use a generic type instead of integers. .pdf
 
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdfTHE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
 
#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docx#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docx
 
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdfAssignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
 
Solution#includestdio.h#includeconio.h#includealloc.h.pdf
Solution#includestdio.h#includeconio.h#includealloc.h.pdfSolution#includestdio.h#includeconio.h#includealloc.h.pdf
Solution#includestdio.h#includeconio.h#includealloc.h.pdf
 
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjhlinked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
linked List.docx vhjgvjhvgjhjhbbjkhkjhkjh
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdf
 
DS Code (CWH).docx
DS Code (CWH).docxDS Code (CWH).docx
DS Code (CWH).docx
 
i nsert+in+ link list
i nsert+in+ link listi nsert+in+ link list
i nsert+in+ link list
 
There are a number of errors in the following program- All errors are.docx
There are a number of errors in the following program- All errors are.docxThere are a number of errors in the following program- All errors are.docx
There are a number of errors in the following program- All errors are.docx
 
C++Write a method Node Nodereverse() which reverses a list..pdf
C++Write a method Node Nodereverse() which reverses a list..pdfC++Write a method Node Nodereverse() which reverses a list..pdf
C++Write a method Node Nodereverse() which reverses a list..pdf
 

More from mayank272369

NEW YORK STATE It is important to identify and develop vario.docx
NEW YORK STATE It is important to identify and develop vario.docxNEW YORK STATE It is important to identify and develop vario.docx
NEW YORK STATE It is important to identify and develop vario.docxmayank272369
 
Next, offer your perspective on transparency. In Chapter 3 of th.docx
Next, offer your perspective on transparency. In Chapter 3 of th.docxNext, offer your perspective on transparency. In Chapter 3 of th.docx
Next, offer your perspective on transparency. In Chapter 3 of th.docxmayank272369
 
New research suggests that the m ost effective executives .docx
New research suggests that the m ost effective executives .docxNew research suggests that the m ost effective executives .docx
New research suggests that the m ost effective executives .docxmayank272369
 
NewFCFF2StageTwo-Stage FCFF Discount ModelThis model is designed t.docx
NewFCFF2StageTwo-Stage FCFF Discount ModelThis model is designed t.docxNewFCFF2StageTwo-Stage FCFF Discount ModelThis model is designed t.docx
NewFCFF2StageTwo-Stage FCFF Discount ModelThis model is designed t.docxmayank272369
 
Negotiation StylesWe negotiate multiple times every day in e.docx
Negotiation StylesWe negotiate multiple times every day in e.docxNegotiation StylesWe negotiate multiple times every day in e.docx
Negotiation StylesWe negotiate multiple times every day in e.docxmayank272369
 
Neurological SystemThe nervous system is a collection of nerves .docx
Neurological SystemThe nervous system is a collection of nerves .docxNeurological SystemThe nervous system is a collection of nerves .docx
Neurological SystemThe nervous system is a collection of nerves .docxmayank272369
 
Neuroleadership is an emerging trend in the field of management..docx
Neuroleadership is an emerging trend in the field of management..docxNeuroleadership is an emerging trend in the field of management..docx
Neuroleadership is an emerging trend in the field of management..docxmayank272369
 
Network security A firewall is a network security device tha.docx
Network security A firewall is a network security device tha.docxNetwork security A firewall is a network security device tha.docx
Network security A firewall is a network security device tha.docxmayank272369
 
Network Forensics Use the Internet or the Strayer Library to.docx
Network Forensics Use the Internet or the Strayer Library to.docxNetwork Forensics Use the Internet or the Strayer Library to.docx
Network Forensics Use the Internet or the Strayer Library to.docxmayank272369
 
Negotiation Process in the International ArenaNegotiation is.docx
Negotiation Process in the International ArenaNegotiation is.docxNegotiation Process in the International ArenaNegotiation is.docx
Negotiation Process in the International ArenaNegotiation is.docxmayank272369
 
Needs to be 150 word min. Perform a scholarly search (using Pu.docx
Needs to be 150 word min. Perform a scholarly search (using Pu.docxNeeds to be 150 word min. Perform a scholarly search (using Pu.docx
Needs to be 150 word min. Perform a scholarly search (using Pu.docxmayank272369
 
Needing assistance with powerpoint presentation for Sociology in the.docx
Needing assistance with powerpoint presentation for Sociology in the.docxNeeding assistance with powerpoint presentation for Sociology in the.docx
Needing assistance with powerpoint presentation for Sociology in the.docxmayank272369
 
Need to write essay on 1000 words about Guns and Crimes , in context.docx
Need to write essay on 1000 words about Guns and Crimes , in context.docxNeed to write essay on 1000 words about Guns and Crimes , in context.docx
Need to write essay on 1000 words about Guns and Crimes , in context.docxmayank272369
 
Need Research Paper related to the course Related topic in the.docx
Need Research Paper related to the course Related topic in the.docxNeed Research Paper related to the course Related topic in the.docx
Need Research Paper related to the course Related topic in the.docxmayank272369
 
Need it in about 12 hours. There are 3 docx file each one of.docx
Need it in about 12 hours. There are 3 docx file each one of.docxNeed it in about 12 hours. There are 3 docx file each one of.docx
Need it in about 12 hours. There are 3 docx file each one of.docxmayank272369
 
Need plagiarism very important Select one type of cryptography o.docx
Need plagiarism very important Select one type of cryptography o.docxNeed plagiarism very important Select one type of cryptography o.docx
Need plagiarism very important Select one type of cryptography o.docxmayank272369
 
Need the below with in 24 hours.Provide 2 references,500 words.docx
Need the below with in 24 hours.Provide 2 references,500 words.docxNeed the below with in 24 hours.Provide 2 references,500 words.docx
Need the below with in 24 hours.Provide 2 references,500 words.docxmayank272369
 
Need it within 12-14 hours of time.One paragraph with 300 words .docx
Need it within 12-14 hours of time.One paragraph with 300 words .docxNeed it within 12-14 hours of time.One paragraph with 300 words .docx
Need it within 12-14 hours of time.One paragraph with 300 words .docxmayank272369
 
Need it to be 300 words. Two paragraphs only. What would you co.docx
Need it to be 300 words. Two paragraphs only.  What would you co.docxNeed it to be 300 words. Two paragraphs only.  What would you co.docx
Need it to be 300 words. Two paragraphs only. What would you co.docxmayank272369
 
Need it for tomorrow morning!!!!For your synthesis essay, yo.docx
Need it for tomorrow morning!!!!For your synthesis essay, yo.docxNeed it for tomorrow morning!!!!For your synthesis essay, yo.docx
Need it for tomorrow morning!!!!For your synthesis essay, yo.docxmayank272369
 

More from mayank272369 (20)

NEW YORK STATE It is important to identify and develop vario.docx
NEW YORK STATE It is important to identify and develop vario.docxNEW YORK STATE It is important to identify and develop vario.docx
NEW YORK STATE It is important to identify and develop vario.docx
 
Next, offer your perspective on transparency. In Chapter 3 of th.docx
Next, offer your perspective on transparency. In Chapter 3 of th.docxNext, offer your perspective on transparency. In Chapter 3 of th.docx
Next, offer your perspective on transparency. In Chapter 3 of th.docx
 
New research suggests that the m ost effective executives .docx
New research suggests that the m ost effective executives .docxNew research suggests that the m ost effective executives .docx
New research suggests that the m ost effective executives .docx
 
NewFCFF2StageTwo-Stage FCFF Discount ModelThis model is designed t.docx
NewFCFF2StageTwo-Stage FCFF Discount ModelThis model is designed t.docxNewFCFF2StageTwo-Stage FCFF Discount ModelThis model is designed t.docx
NewFCFF2StageTwo-Stage FCFF Discount ModelThis model is designed t.docx
 
Negotiation StylesWe negotiate multiple times every day in e.docx
Negotiation StylesWe negotiate multiple times every day in e.docxNegotiation StylesWe negotiate multiple times every day in e.docx
Negotiation StylesWe negotiate multiple times every day in e.docx
 
Neurological SystemThe nervous system is a collection of nerves .docx
Neurological SystemThe nervous system is a collection of nerves .docxNeurological SystemThe nervous system is a collection of nerves .docx
Neurological SystemThe nervous system is a collection of nerves .docx
 
Neuroleadership is an emerging trend in the field of management..docx
Neuroleadership is an emerging trend in the field of management..docxNeuroleadership is an emerging trend in the field of management..docx
Neuroleadership is an emerging trend in the field of management..docx
 
Network security A firewall is a network security device tha.docx
Network security A firewall is a network security device tha.docxNetwork security A firewall is a network security device tha.docx
Network security A firewall is a network security device tha.docx
 
Network Forensics Use the Internet or the Strayer Library to.docx
Network Forensics Use the Internet or the Strayer Library to.docxNetwork Forensics Use the Internet or the Strayer Library to.docx
Network Forensics Use the Internet or the Strayer Library to.docx
 
Negotiation Process in the International ArenaNegotiation is.docx
Negotiation Process in the International ArenaNegotiation is.docxNegotiation Process in the International ArenaNegotiation is.docx
Negotiation Process in the International ArenaNegotiation is.docx
 
Needs to be 150 word min. Perform a scholarly search (using Pu.docx
Needs to be 150 word min. Perform a scholarly search (using Pu.docxNeeds to be 150 word min. Perform a scholarly search (using Pu.docx
Needs to be 150 word min. Perform a scholarly search (using Pu.docx
 
Needing assistance with powerpoint presentation for Sociology in the.docx
Needing assistance with powerpoint presentation for Sociology in the.docxNeeding assistance with powerpoint presentation for Sociology in the.docx
Needing assistance with powerpoint presentation for Sociology in the.docx
 
Need to write essay on 1000 words about Guns and Crimes , in context.docx
Need to write essay on 1000 words about Guns and Crimes , in context.docxNeed to write essay on 1000 words about Guns and Crimes , in context.docx
Need to write essay on 1000 words about Guns and Crimes , in context.docx
 
Need Research Paper related to the course Related topic in the.docx
Need Research Paper related to the course Related topic in the.docxNeed Research Paper related to the course Related topic in the.docx
Need Research Paper related to the course Related topic in the.docx
 
Need it in about 12 hours. There are 3 docx file each one of.docx
Need it in about 12 hours. There are 3 docx file each one of.docxNeed it in about 12 hours. There are 3 docx file each one of.docx
Need it in about 12 hours. There are 3 docx file each one of.docx
 
Need plagiarism very important Select one type of cryptography o.docx
Need plagiarism very important Select one type of cryptography o.docxNeed plagiarism very important Select one type of cryptography o.docx
Need plagiarism very important Select one type of cryptography o.docx
 
Need the below with in 24 hours.Provide 2 references,500 words.docx
Need the below with in 24 hours.Provide 2 references,500 words.docxNeed the below with in 24 hours.Provide 2 references,500 words.docx
Need the below with in 24 hours.Provide 2 references,500 words.docx
 
Need it within 12-14 hours of time.One paragraph with 300 words .docx
Need it within 12-14 hours of time.One paragraph with 300 words .docxNeed it within 12-14 hours of time.One paragraph with 300 words .docx
Need it within 12-14 hours of time.One paragraph with 300 words .docx
 
Need it to be 300 words. Two paragraphs only. What would you co.docx
Need it to be 300 words. Two paragraphs only.  What would you co.docxNeed it to be 300 words. Two paragraphs only.  What would you co.docx
Need it to be 300 words. Two paragraphs only. What would you co.docx
 
Need it for tomorrow morning!!!!For your synthesis essay, yo.docx
Need it for tomorrow morning!!!!For your synthesis essay, yo.docxNeed it for tomorrow morning!!!!For your synthesis essay, yo.docx
Need it for tomorrow morning!!!!For your synthesis essay, yo.docx
 

Recently uploaded

How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17Celine George
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxAdelaideRefugio
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...Nguyen Thanh Tu Collection
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...EduSkills OECD
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...Nguyen Thanh Tu Collection
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMELOISARIVERA8
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjMohammed Sikander
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project researchCaitlinCummins3
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxCeline George
 
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfcupulin
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSean M. Fox
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptxVishal Singh
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................MirzaAbrarBaig5
 
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdfRich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdfJerry Chew
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportDenish Jangid
 

Recently uploaded (20)

How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptx
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
 
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdfRich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 

#include iostream#include string#include fstreamusi.docx

  • 1. #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 {
  • 2. 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);
  • 3. 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 << "t1. Naviagate through Rolodex" << endl; cout << "t2. Search for a Contact" << endl;
  • 4. cout << "t3. Sort Contacts" << endl; cout << "t4. Add a Contact" << endl; cout << "t5. Remove a Contact" << endl; cout << "t6. 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);
  • 5. 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); }
  • 6. 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; } Contact* head = nullptr; Contact * currNode = head; Contact * temp = nullptr; while (!fin.eof()) { temp = new Contact; temp->next = nullptr;
  • 7. temp->prev = nullptr; fin >> temp->firstName; fin >> temp->lastName; fin >> temp->address.streetNumber; fin >> temp->address.street; fin >> temp->address.streetType; fin >> temp->address.city; fin >> temp->address.state; fin >> temp->address.zipcode; fin >> temp->phoneNumber; fin >> temp->emailAddress; fin >> temp->twitterHandle; temp = remove_(temp); if (currNode == nullptr) { head = temp; currNode = head;
  • 8. } else { currNode->next = temp; temp->prev = currNode; currNode = currNode->next; } } 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-
  • 9. >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++)
  • 10. { if (contact->address.city[i] == ' ') contact- >address.city[i] = '_'; } return contact; } void saveList(Contact * head, string fileName) { ofstream fout; fout.open(fileName); Contact * currNode = head; while (currNode != nullptr) { currNode = insert_(currNode); fout << currNode->firstName << " ";
  • 11. fout << currNode->lastName << endl; fout << currNode->address.streetNumber << " "; fout << currNode->address.street << " "; fout << currNode->address.streetType << " "; fout << currNode->address.city << " "; fout << currNode->address.state << " "; fout << currNode->address.zipcode << endl; fout << currNode->phoneNumber << " "; fout << currNode->emailAddress << " "; fout << currNode->twitterHandle; if (currNode->next != nullptr) cout << endl; currNode = currNode->next; } fout.close(); }
  • 12. Contact* navigateRolodex(Contact * start, Contact * end) { //can't start navigating from nowhere. if (start == nullptr) return nullptr; //when end is nullptr, we want to go to the end of the list //so we need to change end to the last item of the list. if (end == nullptr) { end = start; while (end->next != nullptr) { end = end->next; } } Contact* currContact = start; char command = ' '; while (command != 'q')
  • 13. { system("CLS"); displayContact(currContact); cout << "<<(p)revious, (q)uit, (n)ext>>"; cin >> command; switch (command) { case 'p': if (currContact != start) { currContact = currContact->prev; } break; case 'n': if (currContact != end) { currContact = currContact->next; }
  • 14. break; case 'q': break; default: cout << "Invalid Command!" << endl; system("PAUSE"); break; } } return currContact; } void displayContact(Contact * contact) { cout << contact->firstName << " " << contact->lastName << endl << contact->address.streetNumber << " " << contact- >address.street << " " << contact->address.streetType << endl << contact->address.city << ", " << contact-
  • 15. >address.state << " " << contact->address.zipcode << endl << "Phone: " << contact->phoneNumber << " Email: " << contact->emailAddress << " Twitter: " << contact- >twitterHandle << endl; } void displayMenu() { cout << "t1. First Name" << endl << "t2. Last Name" << endl << "t3. Street" << endl << "t4. City" << endl << "t5. State" << endl << "t6. Phone Number" << endl << "t7. Email" << endl << "t8. Twitter Handle" << endl << "t9. CANCEL" << endl; }
  • 16. void addContact(Contact *& head) { //create new contact and make new head. Contact* temp = new Contact; temp->next = head; temp->prev = nullptr; head->prev = temp; head = temp; //get information cout << "Please enter the contact's information: " << endl; cout << "First and Last name: "; cin >> temp->firstName >> temp->lastName; cout << "Street (i.e. 123 W_Main St): "; cin >> temp->address.streetNumber >> temp- >address.street >> temp->address.streetType; cout << "City (put an underscore _ between words): "; cin >> temp->address.city; do {
  • 17. cout << "State (2 letter abbreviation): "; cin >> temp->address.state; } while (temp->address.state.size() != 2); cout << "Zipcode: "; cin >> temp->address.zipcode; cout << "Phone (xxx-xxx-xxxx): "; cin >> temp->phoneNumber; cout << "Email Address: "; cin >> temp->emailAddress; cout << "Twitter Handle: "; cin >> temp->twitterHandle; remove_(temp); cout << "Contact Added!!!" << endl; system("PAUSE"); } void removeContact(Contact *& head) {
  • 18. 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') { if (toDelete == head) head = toDelete->next; if (toDelete->next != nullptr) toDelete->next->prev = toDelete->prev; if (toDelete->prev != nullptr) toDelete->prev->next = toDelete->next;
  • 19. delete toDelete; cout << "Contacted Deleted!!!" << endl; } else { cout << "Nothing deleted. Returning to main menu" << endl; } } system("PAUSE"); } void swap(Contact* & head, Contact* & contact1, Contact* contact2) { //deal with head. if (contact1 == head) {
  • 20. head = contact2; } else if (contact2 == head) { head = contact1; } //take care of other things pointing at swappers, but only if they are not adjacent. . . if (contact1->next != nullptr && contact1->next != contact2) contact1->next->prev = contact2; if (contact2->next != nullptr && contact2->next != contact1) contact2->next->prev = contact1; if (contact1->prev != nullptr && contact1->prev != contact2) contact1->prev->next = contact2; if (contact2->prev != nullptr && contact2->prev != contact1) contact2->prev->next = contact1;
  • 21. //take care of swappers previous and next if (contact1->next == contact2) //adjacent, option 1 { contact1->next = contact2->next; contact2->next = contact1; contact2->prev = contact1->prev; contact1->prev = contact2; } else if (contact2->next == contact1) //adjacent, option 2 { contact2->next = contact1->next; contact1->next = contact2; contact1->prev = contact2->prev; contact2->prev = contact1; } else // not adjacent { Contact * temp = contact1->next;
  • 22. contact1->next = contact2->next; contact2->next = temp; temp = contact1->prev; contact1->prev = contact2->prev; contact2->prev = temp; } contact1 = contact2; } void sort(Contact *& head, sortBy sortKey) { Contact* sorted = head; Contact* currContact = nullptr; Contact* smallest = nullptr; while (sorted != nullptr)
  • 23. { currContact = sorted; smallest = sorted; //find smallest while (currContact != nullptr) { bool smallestContact = false; switch (sortKey) { case FIRST: if (currContact->firstName < smallest- >firstName) smallestContact = true; break; case LAST: if (currContact->lastName < smallest- >lastName) smallestContact = true; break;
  • 24. case STREET: { string fullAddress = to_string(currContact->address.streetNumber) + " " + currContact->address.street + " " + currContact- >address.streetType; string smallestFullAddress = to_string(smallest->address.streetNumber) + " " + smallest- >address.street + " " + smallest->address.streetType; if (fullAddress < smallestFullAddress) smallestContact = true; break; } case CITY: if (currContact->address.city < smallest- >address.city) smallestContact = true; break; case STATE: if (currContact->address.state < smallest- >address.state) smallestContact = true; break; case PHONE:
  • 25. if (currContact->phoneNumber < smallest- >phoneNumber) smallestContact = true; break; case EMAIL: if (currContact->emailAddress < smallest- >emailAddress) smallestContact = true; break; case TWITTER: if (currContact->twitterHandle < smallest- >twitterHandle) smallestContact = true; break; } if (smallestContact) { smallest = currContact; } currContact = currContact->next; } //swap swap(head, sorted, smallest);
  • 26. sorted = sorted->next; } } void sort(Contact* & head) { 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!!!
  • 27. cout << "Search by: " << endl; displayMenu(); int command = 0; cin >> command; if (command != 9) { //sort the list sort(head, (sortBy)command); cout << "Search text: "; string searchString; cin >> searchString; //search the list Contact* start = nullptr, *end = nullptr, *currContact = head; bool found; do
  • 28. { found = false; switch (command) { case 1: if (currContact->firstName == searchString) found = true; break; case 2: if (currContact->lastName == searchString) found = true; break; case 3: { string fullAddress = to_string(currContact->address.streetNumber) + " " + currContact->address.street + " " + currContact- >address.streetType; if (fullAddress == searchString) found = true; break;
  • 29. } case 4: if (currContact->address.city == searchString) found = true; break; case 5: if (currContact->address.state == searchString) found = true; break; case 6: if (currContact->phoneNumber == searchString) found = true; break; case 7: if (currContact->emailAddress == searchString) found = true; break; case 8: if (currContact->twitterHandle == searchString) found = true; break;
  • 30. } if (found) { if (start == nullptr) { start = currContact; end = currContact; //in case there is only one. . . } else { end = currContact; } } currContact = currContact->next; } while ((end == nullptr || found == true) && currContact != nullptr); if (start == nullptr && end == nullptr) {
  • 31. cout << searchString << " not found!!" << endl; return nullptr; } else { return(navigateRolodex(start, end)); } } }