Project-1 Please modify our existing ClassDemo2 program and add characters( char ) and names ( strin

Project-1 Please modify our existing ClassDemo2 program and add characters( char ) and names ( strin | savvyessaywriters.org

Project-1 Please modify our existing ClassDemo2 program and add characters(
char) and names (
strings) to beadded to the linked list along with integers. The current demoprogram accepts only integer data, so you would ask the user toselect the data type to be added to the linked list. The usershould be given the following three choices:
(a) whole numbers
(b) single characters
(c) strings Once the user makes a selection from the question “Enter 1 forfor char, enter 2 for strings, or 3 for integer ending with a x”the list above then your program should be able to process the dataappropriately. This includes:
(a) insert
(b) print
(c) delete
(d) search
(e) copy You will use the existing code (class demo file) and modify itto process
char and
string datatype. Please upload .cpp file(s) along with screenshots of allsolutions/screens. You can take a screenshot of your solutions byhitting PrintScreen button on your keyboard and then by pastingthat image into a Word document. //This program tests various operation of a linked list//45 67 23 89 -999#include #include using namespace std;template struct nodeType{ Type info; nodeType *link;};template class circularLinkedList{public: //Overloads the assignment operator. const circularLinkedList& operator=(const circularLinkedList& otherList) { if (this != &otherList) //avoid self-copy { copyList(otherList); }//end else return *this; } //Initializes the list to an empty state. //Postcondition: first = NULL, last = NULL, // count = 0 void initializeList() { destroyList(); } //Function to determine whether the list is empty. //Postcondition: Returns true if the list is empty; otherwise, returns false. bool isEmptyList() { return (first == NULL); } void print() const { nodeType *current; //pointer to traverse the list current = first->link; while (current != first) //while more data to print { cout << current->info << ” “; current = current->link; } cout << first->info *temp; nodeType *current = NULL; if (first != NULL) { current = first->link; first->link = NULL; } while (current != NULL) { temp = current; current = current->link; delete temp; } first = NULL; //initialize last to NULL; first has already //been set to NULL by the while loop count = 0; } //Function to return the first element of the list. //Precondition: The list must exist and must not be empty. //Postcondition: If the list is empty, then the program terminates; otherwise, the first element of the list is returned. Type front() { assert(first != NULL); return first->link->info; //return the info of the first node } //Function to return the last element of the list. //Precondition: The list must exist and must not be empty. //Postcondition: If the list is empty, then the program terminates; otherwise, the last element of the list is returned. Type back() { assert(first != NULL); return first->info; //return the info of the first node } //Function to determine whether searchItem is in the list. //Postcondition: Returns true if searchItem is found in the list; otherwise, it returns false. bool search(const Type& searchItem) { nodeType *current; //pointer to traverse the list bool found = false; if (first != NULL) { current = first->link; while (current != first && !found) { if (current->info >= searchItem) found = true; else current = current->link; found = (current->info == searchItem); } } return found; } void insertNode(const Type& newitem) { nodeType *current; //pointer to traverse the list nodeType *trailCurrent; //pointer just before current nodeType *newNode; //pointer to create a node bool found; newNode = new nodeType; //create the node newNode->info = newitem; //store newitem in the node newNode->link = NULL; //set the link field of the node //to NULL if (first == NULL) //Case 1 e.g., 3 { first = newNode; first->link = newNode; count++; } else { if (newitem >= first->info)//e.g., 25 > 3 { newNode->link = first->link; first->link = newNode; first = newNode; } else { trailCurrent = first; //e.g., 1 < 3 current = first->link; found = false; while (current != first && !found) if (current->info >= newitem) found = true; else { trailCurrent = current; current = current->link; } trailCurrent->link = newNode; newNode->link = current; } count++; }//end else } //Function to delete deleteItem from the list. //Postcondition: If found, the node containing deleteItem is deleted from the list, first points to the first // node, and last points to the last node of the updated list. void deleteNode(const Type& deleteItem) { nodeType *current; //pointer to traverse the list nodeType *trailCurrent; //pointer just before current bool found; if (first == NULL) //Case 1; list is empty. cout << “Can not delete from an empty list.” << endl; else { found = false; trailCurrent = first; current = first->link; while (current != first && !found) if (current->info >= deleteItem) found = true; else { trailCurrent = current; current = current->link; } if (current == first) { if (first->info == deleteItem) { if (first == first->link) first = NULL; else { trailCurrent->link = current->link; first = trailCurrent; } delete current; count–; } else cout << “The item to be deleted is not in the list.” << endl; } else if (current->info == deleteItem) { trailCurrent->link = current->link; count–; delete current; } else cout & otherList) { first = NULL; copyList(otherList); } //Destructor //Deletes all the nodes from the list. //Postcondition: The list object is destroyed. ~circularLinkedList() { destroyList(); }protected: int count; //variable to store the number of elements in the list nodeType *first; //pointer to the first node of the list nodeType *last; //pointer to the last node of the list private: //Function to make a copy of otherList. //Postcondition: A copy of otherList is created and assigned to this list. void copyList(const circularLinkedList& otherList) { nodeType *newNode; nodeType *current; nodeType *tempFirst; if (first != NULL) destroyList(); if (otherList.first == NULL) { first = NULL; count = 0; } else { current = otherList.first->link; //current points to the //list to be copied count = otherList.count; //copy the first node tempFirst = new nodeType; //create the node tempFirst->info = current->info; //copy the info last = tempFirst; //make last point to the //first node current = current->link; //make current point to the //next node //copy the remaining list while (current != otherList.first) { newNode = new nodeType; //create a node newNode->info = current->info; last->link = newNode; last = newNode; current = current->link; }//end while if (tempFirst == last) { first = tempFirst; first->link = first; } else { newNode = new nodeType; //create a node newNode->info = current->info; last->link = newNode; first = newNode; first->link = tempFirst; } }//end else }};int main(){ circularLinkedList list1, list2; int num; cout << “”Enter 1 for for char, enter 2 for strings, or 3 for integer ending with a x”” << endl; cin >> num; while (num != -999) { list1.insertNode(num); cin >> num; } cout << endl; cout << “List 1: “; list1.print(); cout << endl; cout << “Length List 1: ” << list1.length() << endl; cout << “Enter the number to be searched: “; cin >> num; cout << endl; if (list1.search(num)) cout << num << ” found in the list” << endl; else cout << num << ” not in the list” << endl; cout << “Enter the number to be deleted: “; cin >> num; cout Attached

 

Do you need a similar assignment done for you from scratch? We have qualified writers to help you. We assure you an A+ quality paper that is free from plagiarism. Order now for an Amazing Discount!
Use Discount Code “Newclient” for a 15% Discount!

NB: We do not resell papers. Upon ordering, we do an original paper exclusively for you.


The post Project-1 Please modify our existing ClassDemo2 program and add characters( char ) and names ( strin appeared first on Affordable Nursing Writers.