Question
Help With List.Cpp! With C++ THANKS! -Using C++, Write A List Class That Uses A Linked Sequence Of Dynamically Allocated Nodes To Store The Words
Help with list.cpp! with C++ THANKS!
-Using C++, write a List class that uses a linked sequence of dynamically allocated nodes to store the words in a phrase. -Each word is stored as a string in a list node. -The List class includes several member functions that will enable the client code to Append a word to the end of the current phrase. -Find a word within the current phrase, Replace a word in the phrase, determine the Length of the current phrase, Delete a word from the phrase, or insert a word at a particular position within the phrase. -These functions are described in more detail in list.h
LIST.H
#ifndef LIST_H #define LIST_H
#include using namespace std;
class ListEmpty { /*** Empty Error Class ***/ }; class ListFull { /*** Empty Error Class ***/ }; class ListNotFound { /*** Empty Error Class ***/ }; class ListBadPosition { /*** Empty Error Class ***/ };
struct Node { string word; // A word in a phrase Node* next; // Pointer to next node in sequence };
class List // List ADT used to store words in a phrase { private: Node* head; // Pointer to head of word list int num; // Number of words stored in list
public: /***** Constructor and Destructor *****/ List(); // Description of List() // Constructor sets state of list to empty
~List(); // Description of ~List() // Destructor must deallocate all list nodes
/***** Transformer Methods *****/ void Append(string newword); // Description of Append(...) // Appends newword to the end of the current phrase // Error Handling: If list is full, throw ListFull object.
void InsertAt(int pos, string newword); // Description of InsertAt(...) // Inserts newword at position pos. // Positions numbered starting with zero (0 =>=> // Hint: pos == num ==> append // Word previously at pos should now be at position pos+1 // Error Handling: If list is full, throws ListFull object // If pos out of range, throws ListBadPosition object
void Delete(string someword); // Description of Delete(...) // Deletes the first instance of someword if it is present. // Error Handling: If someword is not in list, throws ListNotFound object
void Replace(string oldword, string newword); // Description of Replace(...) // Replaces the first instance of oldword with newword. // Error Handling: If oldword not found, throws ListNotFound object
/***** Observer Methods *****/ int Length() const; // Description of Length() // Returns number of words in the list // Error Handling: none
bool Find(string someword) const; // Description of Find(...) // Returns true if someword is in list, false otherwise // Error Handling: none
void Print() const // Description of Print() // Prints the entire phrase to stdout { Node* temp = head; // Temp variable for scanning through list starting at head
cout while (temp != NULL) // While there are words that must be printed... { cout word; // ... print the next word temp = temp->next; // ... and advance to the next node. }
cout } };
#endif
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started