Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Objectives: This assignment will access your CH+ language skills and understanding of linked lists. After completing this assignment you will be able to do the

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Objectives: This assignment will access your CH+ language skills and understanding of linked lists. After completing this assignment you will be able to do the following: (1) Manage a singly-linked list with pointers to the front and back of the singly-linked list, (2) allocate memory dynamically (3) implement a default, explicit-value and copy constructors, (4) a destructor, (5) add a node to a singly-linked list, and (6) delete a node anywhere in a singly-linked list. In this assignment you will implement the SENTENCE ADT (abstract data type) using a singly- linked list of strings. The SENTENCE ADT is defined below. Call the class you implement "sentence". Remember, a singly-linked list is composed of nodes. You will also implement a class called "word" that has two fields: a string field called "term"; and a pointer field called "next". Essentially, each word is really a node in the linked list. And sentence is the singly-linked list. Each node (word) in the linked list (sentence) will contain one string of a sentence. Note that a space is considered a string. Consider the following declaration of a word. A sentence is composed of words: class word { public: string term; word *next; }; The state (private data members) of your sentence class should contain a pointer to the front of the list of words 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 "sentence.cpp." and the declaration of your class in a file called "sentence.h." You will implement all the code necessary to maintain a sentence. See the ADT below. Test the complete functionality of the class sentence. You must use the file "sentence_driver.cpp" to help you understand and test all the required functionality of the class. If you discover that you need more tests while implementing the functionality of the sentence class, then add more tests to your driver, but your final code must be submitted with the given driver . #include #include using namespace std; #ifndef SENTENCE H #define SENTENCE_H class word { public: string term; word* next; }; class sentence { public: //sentence(); [/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. l/sentence(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; l/sentence(const sentence& org); // Copy Constructor: Used during a call by value, return, or initialization/declaration of a word object; //-sentence(); //Destructor: The destructor will de-allocate all memory allocated for the word. Put the message // //"destructor called " inside the body of the destructor. //bool isEmpty() { return front == 0; } //inline implementation l/int length(); //Length: Determines the length of the word A; remember A is the current object; //void add_back(string& s); l/friend ostream& operator #include #include "sentence.h" using namespace std; int main() { 1/cout #include using namespace std; #ifndef SENTENCE H #define SENTENCE_H class word { public: string term; word* next; }; class sentence { public: //sentence(); [/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. l/sentence(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; l/sentence(const sentence& org); // Copy Constructor: Used during a call by value, return, or initialization/declaration of a word object; //-sentence(); //Destructor: The destructor will de-allocate all memory allocated for the word. Put the message // //"destructor called " inside the body of the destructor. //bool isEmpty() { return front == 0; } //inline implementation l/int length(); //Length: Determines the length of the word A; remember A is the current object; //void add_back(string& s); l/friend ostream& operator #include #include "sentence.h" using namespace std; int main() { 1/cout

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

Sql++ For Sql Users A Tutorial

Authors: Don Chamberlin

1st Edition

0692184503, 978-0692184509

More Books

Students also viewed these Databases questions

Question

low proportion of Muslims

Answered: 1 week ago