Question: Phone book program with linked list in c++. Any Help would be highly appreciated. Phone Book with linked list in c++ 1.add an insert function(convert
Phone book program with linked list in c++. Any Help would be highly appreciated.
Phone Book with linked list in c++
1.add an insert function(convert all the strings to uppercase sort by last name)
2.modify function(search by last name and choose which part to modify)
3.delete function(last name)
4. Update your display
My code are as follows
#include
using namespace std;
class PhoneList{ private: struct ContactNode{ string firstname; string lastname; string phonenumber; ContactNode *next; }; ContactNode *head; public: PhoneList(); void appendNode(string Firstname, string Lastname, string Phonenumber); void display();
};
//Constructor PhoneList::PhoneList(){ head = NULL; }
// void PhoneList::appendNode(string Firstname, string Lastname, string Phonenumber){ ContactNode *newNode = new ContactNode(); newNode->firstname = Firstname; newNode->lastname = Lastname; newNode->phonenumber = Phonenumber; newNode->next = NULL; if(head == NULL){ head = newNode; } else{ ContactNode *temp = head; while(temp->next != NULL){ temp = temp->next; } temp->next = newNode; } } void PhoneList::display(){ cout << endl; if(head == NULL){ cout << "Email List is empty" << endl; } else{ cout << "Email List is" << endl; } ContactNode *temp = head; int count = 1; while(temp != NULL){ cout << count << "):" << endl; cout << "First Name: " << temp->firstname << endl; cout << "Last Name: " << temp->lastname << endl; cout << "Phone Number: " << temp->phonenumber << endl; cout << endl; temp = temp->next; count++; } }
int main(){ PhoneList PL; string str; string firstname, lastname, phonenumber; while(true){ cout << "Do you want to input an entry(y or n)?: "; cin >> str; if(str == "n" || str == "N"){ break; } else{ cout << "Enter First Name: "; cin >> firstname; cout << "Enter Last Name: "; cin >> lastname; cout << "Enter Phone Number: "; cin >> phonenumber; PL.appendNode(firstname, lastname, phonenumber); } } PL.display(); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
