Question: PLEASE USE C++ AND PLEASE SEPERATE EACH FILE INTO .h and .cpp FILES. THANK YOU ___________________________________________________________________________ In this lab, you are going to design a

PLEASE USE C++ AND PLEASE SEPERATE EACH FILE INTO .h and .cpp FILES. THANK YOU

___________________________________________________________________________

In this lab, you are going to design a linked list to keep track of a telephone directory. You need to design two classes:

- Class Node has the following private data:

 string firstName; string lastName; string phoneNumber; 

- Class LL has the following private data: Node * head; // head pointer points to beginning of linked list

Class LL should be made friend of class Node so public functions of LL can access a nodes private attributes without having to write getters and setters for class Node.

You also need to implement the following public methods for class LL:

LL::LL()

 The default constructor sets the head to nullptr 

void LL::append(string fName, string lName, string phone)

This function creates a node, sets its data to the values sent as arguments, and inserts the new node at the end of the list (after the last node)

void LL::insertAtBegin(string fName, string lName, string phone)

This function creates a node, sets its data to the values sent as arguments, and inserts the new node at the beginning of the linked list (before the first node)

void LL::print() This function traverses the list printing the data in each node

void LL::searchByName(string fName, string lName) This function searches for a particular persons record, whose first name is fName and last name is lName, in the list and prints the persons corresponding phone number if it exists. If that person does not exist, the function prints an error message

LL::~LL() The destructor destroys (deletes) all nodes in the list and sets head back to nullptr. Have the destructor call another private function destroy that does the deleting (you need to implement that function too:

 void LL:destroy() 

LL::LL(const LL& source) The copy constructor performs a deep copy of the list source

Use the main program below to test your functions and add code where indicated:

int main() {

LL list1;

// add nodes to the list list1.insertAtBegin ("Nancy", "Garcia", "617-227-5454");

list1.append ("Adam", "James", "202-872-1010");

list1.append ("Jim", "Meyer", "337-465-2345");

list1.insertAtBegin ("Joe", "Didier", "352-654-1983");

list1.append ("Mayssaa", "Najjar", "878-635-1234");

 list1.print(); 
 // search for specific people in the list list1.searchByName ("Nancy", "Garcia"); list1.searchByName ("Mayssaa", "Najjar"); list1.searchByName ("Jamie", "Garcia"); 

// instantiate another list list2 using the copy constructor // so that list2 is a copy of list1 LL list2(list1);

// modify list1 by adding an entry at the beginning // then print list1 and list2

list1.insertAtBegin ("Michel", "Delgado", "327-165-2345");

list1.print();

list2.print();

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!