Question: sample out put h file (please do not copy from other chegg and I have had some one do this and it was not correct)

 sample out put h file (please do not copy from other

chegg and I have had some one do this and it was

not correct) #include #include using namespace std; #ifndef SENTENCE_H #define SENTENCE_H class

sample out put

word { public: string term; word* next; }; class sentence { public:

sentence(); sentence(const string& s); // //a C-style string or a C++ string

h file (please do not copy from other chegg and I have had some one do this and it was not correct)

#include

#include

using namespace std;

#ifndef SENTENCE_H

#define SENTENCE_H

class word

{

public:

string term;

word* next;

};

class sentence

{

public:

sentence();

sentence(const string& s);

// //a C-style string or a C++ string representing the word to be created;

sentence(const sentence& org);

~sentence(); //"destructor called " inside the body of the destructor.

bool isEmpty() { return front == 0; } //inline implementation

int length();

void add_back(string& s);

friend ostream& operatorout, const sentence&); //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

void add_front(string& s); /

sentence& operator=(const sentence& w) { sentence 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+(sentence& 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;

bool isEqual(sentence& B); // Returns true if two word objects are equal; otherwise false; remember A is the current

void remove(const string& s); //Deletes the first occurrence of the string s from the list A;

private:

word* front, * back;

};

#endif

driver

#include

#include

#include "sentence.h"

using namespace std;

int main()

{

cout

sentence you;

cout

cout

cout

cout

sentence me("Today is a wonderful day! ");//sentence with 3 spaces at end

cout

cout

sentence me_to("");

cout

cout

sentence you_to(" ");

cout

cout

cout

cout

cout

sentence them = me;

cout

cout

cout

cout

cout

cout

sentence us;

us = "There are five racoons in the palm tree.";

cout

"\""

cout

cout

cout

cout

sentence her, him;

her = "I am very happy";

him = "They are very happy";

cout

//

her = "";

him = "";

cout

her = " ";

him = " ";

cout

her = "";

him = " ";

cout

her = " ";

him = " ";

cout

her = " ";

him = " ";

cout

cout

cout

cout

cout

sentence their("Everything ");

us = "will be okay.";

cout

cout

their + us;

cout

cout

cout

us + their;

cout

cout

cout

us = "123 456";

their = "123";

cout

cout

us + their;

cout

us = "123 456";

their = "";

cout

cout

their + us;

cout

cout

cout

them = "";

them.remove("123");

cout

them = "123";

them.remove("123");

cout

them = "123 abc 124 abc 123 4567";

them.remove("123");

cout

them = "123 abc 124 abc 123 4567";

them.remove("4567");

cout

them = "123 abc 124 abc 123 4567";

them.remove("124");

cout

them.remove(" ");

cout

them.remove(" ");

cout

them.remove(" ");

cout

them.remove(" ");

cout

them.remove(" ");

cout

cout

cout

cout

sentence h("123 456 780");

them = h;

cout

cout

cout

cout

return 0;

}

a little bit of my main cpp to help get you started

#include

#include

#include "sentence.h"

using namespace std;

sentence::sentence(){

front = NULL;

back = NULL;

}

sentence::sentence(const string& s){

cout

string s1 = s;

front = NULL;

back = NULL; //back pointer set to NULL

int length = static_castint>(s.length()); //length variable is length of string

if(length == 0){ //if string is empty, return, nothing can be done with it

return;

}

//allocate space for a new word

front = new word;

//creates a pointer to the current word and initialized it to the front

word* currentWord = front;

int i = length;

while(i != 0){

if(isspace(s1.front())){ //if the first character is space

currentWord->term = s1.front(); //make the term a space

s1 = s1.substr(1); //shorten the string to not include the space anymore

i--; //decrament the length by 1

}else{ //if the first term is NOT a space

int n = static_castint>(s1.find_first_of(" ")); //find the first space

if(n == -1) //if there are no more spacing, take the last index

n = static_castint>(s1.length());

currentWord->term = s1.substr(0,n); //make the term everything UP to the first space (aka a word)

i -= s1.substr(0,n).length(); //subtract the length of the last segment you substracted

s1 = s1.substr(n); //shorted the string not to include that word anymore

}

if(i

currentWord->next = NULL; //have the next pointer be null as there are no other positions

break;

}else{ //if we are not at the end yet and still have more values

Data Structure and Algorithm Analysis---COP3530 Module 6 Total Points: 25 NO LATE ASSIGNMENTS WILL BE ACCEPTED!! 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 . ADT---sentence Data: A set of terms Operations: 1. Default constructor: The default constructor will initialize your state variables. The front and back of the linked list is initially set to NULL or 0; this implies a non-header node implementation of the link list. 2. Explicit-value constructor: This constructor will have one argument; a C-style string or a CH string representing the sentence to be created; 3. Copy Constructor: Used during a call-by-value, return, or initialization/declaration of a sentence object; 4. Destructor: The destructor will de-allocate all memory allocated for the sentence. Put the message "destructor called inside the body of the destructor. 5. isEmpty: Check to see if the sentence A is empty, A is the current object; Note if either front = 0 or back = 0 then the list is empty. 6. length: Determines the length of the sentence A; remember A is the current object and space should be counted in the length of the sentence; 7. add_back: Add a word (node) to the back of the sentence (link list). Note that if the list contains only one node then front and back will point to the same node. 8. operator

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!