Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this assignment you will implement the WORD ADT (abstract data type) using a singly-linked list of characters. The WORD ADT is defined below. Call

In this assignment you will 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". Remember, a singly-linked list is composed of nodes. You will also implement a class called "character" that has two fields: a char field called "symbol"; and a pointer field called "next". Essentially, each character is really a node in the list. Each node (character) in the list (word) will contain one alpha/numeric character of a word. Consider the following declaration of a character. A WORD is composed of characters: class character { public: char symbol; character *next; }; The state (private data members) of your WORD class should contain a pointer to the front of the list of characters called "front" and a pointer to the back of the list called "back". You may add more members to the state and more member functions to the behavior of the class if you 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 "word_driver.cpp" as a guide to help you understand and test all the functionality of 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: 1. IsEmpty: Check to see if the word A is empty; A is the current object; 2. Length: Determines the length of the word A; remember A is the current object; 3. operator<<: Overload the insertion operator as a friend function with chaining to print a word A; 4. operator= : Overload the assignment operator as a member function to take a string (C-style or C++ string, just be consistent in your implementation) as an argument and assigns its value to A, the current object; 5. operator= : Overload the assignment operator as a member function with chaining to take a word object as an argument and assigns its value to A, the current object; 6. operator+: Overload the + operator as a member function without chaining to add 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; 7. Default constructor: The default constructor will initialize your state variables. The front of the linked list is initially set to NULL or 0; this implies a non-header node implementation of the link list. 8. Explicit-value constructor: This constructor will have one argument; a C-style string or a C++ string representing the word to be created; 9. Copy Constructor: Used during a call by value, return, or initialization/declaration of a word object; 10.Destructor: The destructor will de-allocate all memory allocated for the word. Put the message "destructor called " inside the body of the destructor. 11. IsEqual: Returns true if two word objects are equal; otherwise false; remember A is the current. 12. Remove: Deletes the first occurrence of word B (removes the first set of characters that makeup B's linked list from A's linked list) from word A if it is there; remember A is the current object. 13. RemoveALL: Removes all occurrences of word B (removes each set of characters that makup Bs linked list from As linked list) form word A if it is there; remember A is the current object

//word.h

#include #include

using namespace std;

#ifndef WORD_H #define WORD_H

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

class WORD { public: bool IsEmpty(){ return front ==0;} int Length(); //Length: Determines the length of the word A; remember A is the current object; friend ostream & operator<<(ostream & out, const WORD &){return out;} //Overload the insertion operator as a friend function with chaining to print a word A; void operator=(const string & s){}// Overload the assignment operator as a member function to take a //string (C-style or C++ string, just be consistent in your implementation) as an argument and //assigns its value to A, the current object; WORD & operator=(const WORD & w){WORD k; return k;} // Overload the assignment operator as a member function with chaining to take a word //object as an argument and assigns its value to A, the current object; void operator+(const WORD & B){} //Overload the + operator as a member function without chaining to add 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; WORD(){front = back =0; } //The default constructor will initialize your state variables. //The front of the linked list is initially set to NULL or 0; this implies a non-header node //implementation of the link list. WORD(const string & s){ } //Explicit-value constructor: This constructor will have one argument; //a C-style string or a C++ string representing the word to be created; WORD(const WORD & org){} // Copy Constructor: Used during a call by value, return, or initialization/declaration of a word object; ~WORD(){} //Destructor: The destructor will de-allocate all memory allocated for the word. Put the message //"destructor called " inside the body of the destructor. bool IsEqual(const WORD & B){return true;} // Returns true if two word objects are equal; otherwise false; remember A is the current void WORD::Remove(WORD & Org) {};//Deletes the first occurrence of word B (removes the first set of characters that makeup B's linked //list from A's linked list) from word A if it is there; remember A is the current object; void WORD::RemoveALL(WORD & Org) {};//Removes all occurrences of word B (removes each set of characters that makeup B's linked //list from A's linked list) from word A if it is there; remember A is the current object;

private: character *front, *back; };

#endif

//word.cpp

#include #include #include "word.h"

using namespace std;

int WORD::Length() { string s; //in>>s;

if (front == 0) { return 0; } else { character *p = front; int count = 0;

while(p!=0) { count++; p=p->next; } return count; } }

//driver.cpp

#include #include #include "word.h"

using namespace std;

int main() { //WORD you; //cout<<"************TEST#1******************************* "; //cout<<"Testing the default constructor and printing empty word "; //cout<

//cout<<"************TEST#2******************************* "; //WORD me("AAAA0000AAA0000AAA"); //cout<<"Testing the explicit-value constructor "; //cout<

//cout<<"************TEST#3******************************* "; //WORD them = me; //cout<<"Testing the copy constructor "; //cout<<"them is "<

//cout<<"************TEST#4******************************* "; //cout<<"Testing length "; //cout<<"The length of me is "<

//cout<<"************TEST#5******************************* "; //WORD us; //us = "AA"; //cout<<"Testing operator= by assignment the value of \"AA\" to use "; //cout<<"The word us is "<

//cout<<"************TEST#6******************************* "; //WORD everyone = "hello world "; //cout<<"Testing operator= by assignment the value of \"hello world\" to use "; //cout<<"The word everyone is "<

//cout<<"************TEST#7******************************* "; //WORD our, him;

//our = "AAA000AAA000"; //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<<"TEST SHOULD REVEAL THAT our AND us are not equal ";

//cout<<"************************************************* "; //cout<

//cout<<"************TEST#8******************************* "; //cout<<"Adding 2 words by adding us to the back of their. Their is the current object "; //WORD their("AAAA0000AAA0000AAA"); //their + us; //cout<<"their followed by us is "<

//cout<<"************TEST#9******************************* "; //cout<<"Adding 2 words, their2 is empty, by adding us to the back of their. Their is the current object "; //WORD their2(""); //their2 + us; //cout<<"their followed by us is "<

//cout<<"************TEST#10******************************* "; //cout<<"Adding 2 words, their3 is empty, by adding us to the back of their. Their is the current object "; //WORD their3(""); //us + their3; //cout<<"us followed by empty their3 is "<

//cout<<"************TEST#11******************************* "; //them = "123abc123abc1234567"; //us = "123"; //them.Remove(us); //cout << "Testing Remove by removing the first occurrence of us // <<" from them "; //cout << "The word them is " << them << endl; //them = abc123abc123567 after removing first occurrence of us //cout<<"************************************************* "; //cout<

//cout<<"************TEST#12******************************* "; //them = "123abc123abc1234567"; //us = "123"; //them.RemoveAll(us); //cout << "Testing RemoveAll by removing all occurrences of us from them "; //cout << "The word them is " << them << endl; //them = abcabc567 after removing all occurrences of us are removed //cout<<"************************************************* "; //cout<<"************************************************* "; //cout<

return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learning PostgreSQL

Authors: Salahaldin Juba, Achim Vannahme, Andrey Volkov

1st Edition

178398919X, 9781783989195

More Books

Students also viewed these Databases questions