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

*********word.cpp********

#include #include #include "word.h"

using namespace std;

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

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

//LINKED_LIST_CLASS::LINKED_LIST_CLASS() //{ // cout<<"Inside the default constructor "; // front = back = 0; // //} // // //LINKED_LIST_CLASS::~LINKED_LIST_CLASS() //{ // // // cout<<"Destructor has been called "; // while (front != 0) // { // LIST_NODE *p = front; // front = front->next; // delete p; // // } // //} // //void LINKED_LIST_CLASS::Print()//accessor //{ // // LIST_NODE *p = front; // // cout<data<next; // } // // cout<next =0; // p->data = key; // // if (front == 0) // { // front = p; // back = front; // } // else // { // // p->next = front; // front = p; // } // //} // //LIST_NODE * LINKED_LIST_CLASS::Search(const List_Type & key) //{ // // LIST_NODE *p = front; // // while(p!=0) // { // if (p->data == key) // { // return p; // } // p = p->next; // } // return p; // //} // // // // //void LINKED_LIST_CLASS::Remove(const List_Type & key) //{ // LIST_NODE *p = Search(key); // // if (p == 0) // { // cout<next; // delete p; // } // else // { // LIST_NODE *back_ptr = front; // // while(back_ptr!=0 && back_ptr->next!= p) // { // back_ptr = back_ptr->next; // } // if (p == back) // { // back = back_ptr; // } // back_ptr->next = p->next; // delete p; // } // } //} // //

*****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

private: character *front, *back; };

#endif

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

International Baccalaureate Computer Science HL And SL Option A Databases Part I Basic Concepts

Authors: H Sarah Shakibi PhD

1st Edition

1542457084, 978-1542457088

More Books

Students also viewed these Databases questions