Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please Help! I need to implement the following. I\'ve written the header file, I

ID: 3640698 • Letter: P

Question

Please Help! I need to implement the following. I've written the header file, I need help with the implementation file (word.cpp) . Below are the directions:

-Implement the WORD ADT (abstract data type) using a singly-linked list of characters. The WORD ADT is defined below. Call the class you implement "WORD". Define a class called "character" that has two fields, a char field called "symbol" and a pointer field called "next". Each node (character) in the list will contain one symbol of a word. The state of your class should contain a pointer to the front of the list of characters called "front". You may add more members to the state and more member functions to behavior of the class if your determine necessary. Store the definition of your class in a file called "word.cpp." and the declaration of your class in a file called "word.h ." You will implement all the code necessary to maintain a word. See the ADT below. Test the complete functionality of the class WORD. Use the file "driver.cpp" as a guide to help you understand and test the class. If you discover that you need more tests while implementing the functionality of WORD, then add more tests to your driver.

ADT---WORD

Data:

A set of characters

Operations:

IsEmpty: Check to see if the word A is empty; A is the current object;

Length: Determines the length of the word A; remember A is the current object;

Insert: Inserts a copy of word B (adds symbols that makeup B's linked list to A's linked list) into word A at position p; remember A is the current object;

Remove: Deletes the first occurrence of word B (removes the first set of symbols that makeup B's linked list from A's linked list) from word A if it is there; remember A is the current object;

RemoveAll: Removes all occurrences of word B (removes each set of symbols that makeup B's linked list from A's linked list) from word A if it is there; remember A is the current object;

operator<<: Overload the insertion operator as a friend function with chaining to print a word A;

operator= : Overload the assignment operator as a member function to take a string as an argument and assigns its value to A, the current object;

IsEqual: Returns true if two words are equal; otherwise false; remember A is the current object;

SetEqual: Assigns word B (creates a copy of B's linked list and assigns it to A's linked list) to word A; remember A is the current object;

AddWords: Adds word B (adds the set of symbols that makep B's linked list to the back of A's linked list) to the back of word A; remember A is the current object;

Default constructor: The default constructor will initialize your state variables. The front of the linked list is initially set to NULL or 0;

Explicit-value constructor: This constructor will have one argument; a C++ string representing the word to be created;

Copy Constructor: Used during a call by value, return, or initialization/declaration;

Destructor: The destructor will de-allocate all memory allocated for the word. Put the message "destructor called " inside the body of the destructor.

*****************************************************************************************************
word.h
*****************************************************************************************************
include <iostream> //i/o stream library
#include <string> //c++ string library
using namespace std; //standard workspace


class character
{
public:
char symbol;
character *next;
};



class WORD
{
public:
WORD();
WORD(const WORD &);
~WORD();
bool IsEmpty();
int Length();
void Insert(WORD &, int pos);
void Remove (WORD &);
void RemoveAll (WORD &);
friend ostream & operator<<(ostream &, const WORD &);
WORD & operator = (const string &);
bool IsEqual(WORD &);
void SetEqual(WORD &);
void AddWords(WORD &);
character *Search(WORD &);
void Insert_ch(const char &);

private:
character *front; //pointer to the front of the list.
int length;

};

****************************************************************************************************
driver.cpp
***************************************************************************************************
#include <iostream>
#include <string>
#include "word.h"

using namespace std;

int main()
{
WORD you;
cout<<"Testing the default constructor and printing empty word ";
cout<<you<<endl;

WORD me("123abc345abc129012");
cout<<"Testing the explicit-value constructor ";
cout<<me<<endl;

WORD them = me;
cout<<"Testing the copy constructor ";
cout<< them <<" = "<< me << endl;


cout<<"Testing length ";
cout<<"The length of me is "<<me.Length()<<endl;
cout<<"The length of them is "<<them.Length()<<endl;
cout<<"The length of you is "<<you.Length()<<endl;


cout<<"Testing Insert by inserting me into you at position 0 ";
you.Insert(me,0);
cout<<"The word you is "<<you<<endl;

WORD us;
us = "abc";
cout<<"Testing operator= by assignment the value of "abc" to use ";
cout<<us;

them.Remove(us);
cout<<"Testing Remove by removing us from them ";
cout<<"The word them is "<<them<<endl;

me.RemoveAll(us);
cout<<"Testing RemoveAll by removing all occurrences of us in me ";
cout<<"The word me is "<<me<<endl;

WORD our, him;

our = "XXXCCCYYY";
us = "XXXX";

cout<<"Testing IsEqual by testing to see inf us is equal to our ";
if (our.IsEqual(us))
cout<<"The 2 words are equal ";
else
cout<<"The 2 words are not equal ";

cout<<"Testing SetEqual and IsEqual by setting the value of us to the value stored in our ";
our.SetEqual(us);
if (our.IsEqual(us))
cout<<"The 2 words are equal ";
else
cout<<"The 2 words are not equal ";

WORD their("abcABCDEF");
WORD yo, child;

cout<<"Testing AddStrings by adding a string to the back of an empty string ";
cout<<"Adding to an empty word ";
yo.AddWords(their);
cout<<"The value of yo is "<<yo<<endl;

cout<<"Adding an empty word to another word by adding an empty string to a non empty string ";
yo.AddWords(child);
cout<<"The value of yo is "<<yo<<endl;

cout<<"Adding 2 words by adding us to the bac of their. Their is the current object ";
their.AddWords(us);
cout<<"their followed by us is "<<their<<endl;

return 0;
}


Explanation / Answer

I can help you with a few of the functions but not all of them, it's a lot to ask for.... Default Constructor WORD::WORD() { front = new character; //created an empty list front->next = 0; } Copy Constructor WORD::WORD(const WORD & Original) { front=0; *this=Original; } Insertion operator WORD & WORD::operator=(const WORD & Original) //overload = { character *y = Original.front; count=0; character *s; if(front!=0) { s=front; front = front->next; delete s; } while(p!=0) { AddWords(y->symbol); y = y->next; } return *this; } Length int WORD::Length() { character *r; r=front; int i=0; while(!r->next=='') { i++; r=r->next; } count=i; return i; } Hope this can get you started