Greetings, everyone I\'m having issues running my program in C++ language. I nee
ID: 3902265 • Letter: G
Question
Greetings, everyone
I'm having issues running my program in C++ language. I need of your help to fix my code. I will give a great rating to your answers.
These program is divided into three files: word.cpp, word.h and word_driver.cpp
Here is my first my file:
word.cpp
#include <iostream>
#include <string>
#include "word.h"
using namespace std;
//*************************************************************************************
//Name: Default Constructor
//Precondition: The state of the class WORD has not been initialized
//Postcondition: The state of the class WORD has been initialized;
//pointers to front and back are set to 0 using chaining;
//Description: The default constructor is used to initialize the state of your class.
//In this case, the state of your class are the pointers, front and back.
//*************************************************************************************
WORD::WORD()
{
cout << "Inside the default constructor ";
front = back = 0;
}
//*************************************************************************************
//Name: Explicit-value constructor
//Precondition: A string is passed to the function but has not been
//added to the linked list
//Postcondition: The string is created and added to the linked list
//Description: This constructor will have one argument;
//a C-style string or a C++ string representing the word to be created;
//this overload is used to combine two lists
//*************************************************************************************
WORD::WORD(const string & s) {
for (int i = 0; i < s.length(); i++)
{
Insert(s[i]);
}
}
//*************************************************************************************
//Name: Copy Constructor
//Precondition: A WORD is declared but has not been initialized.
//Postcondition: A WORD has been initialized.
//Description: Used during a call by value, return,
//or initialization/declaration of a word object;
//*************************************************************************************
WORD::WORD(const WORD & org) {
front = new character;
front->symbol = org.front->symbol;
front->next = org.front->next;
back = front;
}
//*************************************************************************************
//Name: Length
//Precondition: The function is called and the length of *this is unknown.
//Postcondition: The length of *this is returned in an int.
//Description: The function is used to determine the length of *this.
//*************************************************************************************
int WORD::Length()
{
if (front == 0)
{
return 0;
}
else
{
character *p = front;
int count = 0;
while (p != 0)
{
count++;
p = p->next;
}
return count;
}
}
//*************************************************************************************
//Name: Destructor
//Precondition: Memory is stored in the class.
//Postcondition: No memory is stored in the class.
//Description: The destructor will de-allocate all the memory allocated to your class.
//It is call automatically by the compiler when the current object goes
//out of scope.
//*************************************************************************************
WORD::~WORD()
{
cout << "Destructor has been called ";
while (front != 0)
{
character *p = front;
front = front->next;
delete p;
}
}
//*************************************************************************************
//Name: Opeartor +
//Precondition: Two WORDs (*this and the WORD passed to the function) are separate entities
//Postcondition: Two WORDs are combined into one, with the word being passed
//appended to the end of *this
//Description: This overloaded function is called to combine two lists
//
//*************************************************************************************
void WORD::operator+(const WORD & B)
{
character *p = B.front;
while (p != NULL)
{
Insert(p->symbol);
p = p->next;
}
}
//*************************************************************************************
//Name: IsEqual
//Precondition: It is unknown if two WORDs are the same
//Postcondition: If both WORDs are the same, returns true; else false;
//Description: This function compares two WORDs and returns true if they are
//the same WORD and falseotherwise
//
//*************************************************************************************
bool WORD::IsEqual(const WORD & B) {
character *visitor = B.front; // incoming node holder
character *current = front; // current node holder
//check if both characters are empty. if not, runs loop
while (current != 0 && visitor != 0)
{
// check if they match
if (current->symbol != visitor->symbol) { return false; }
// move forward 1 node
visitor = visitor->next;
current = current->next;
}
return true; // they must match or the loop would have returned.
}
//*************************************************************************************
//Name: Print
//Precondition: The WORDs have not been printed to output
//Postcondition: The WORDs are printed to output
//Description: The following function, Print, prints all the symbol stored in the
//linked list of the current object. In this case, printing starts at
//the front of the list.
//*************************************************************************************
void WORD::Print()//accessor
{
character *p = front;
cout << endl << endl;
while (p != 0)
{
cout << p->symbol << endl;
p = p->next;
}
cout << endl << endl;
}
//*************************************************************************************
//Name: Opeartor =
//Precondition: A WORD and a string are passed to the function
//Postcondition: The WORD has been assigned the value of the string; any previous
//string assigned to the WORD has been deleted
//Description: Overload the assignment operator as a member function to take a
//string (C++ string) as an argument and
//assigns its value to the current object;
//*************************************************************************************
void WORD::operator=(const string & s)
{
front = 0;
back = 0;
for (int i = 0; i < s.length(); i++)
{
Insert(s[i]);
}
}
//*************************************************************************************
//Name: Opeartor =
//Precondition: Two WORDs (*this and the element passed to the function)
//are separate.
//Postcondition: This* is assigned the value of the WORD passed to the function;
//any value previously stored in *this is removed
//Description: Overload the assignment operator as a member function with chaining to take a word
//object as an argument and assigns its value to the current object;
//*************************************************************************************
WORD & WORD::operator=(const WORD & w)
{
cout << "In the assignment operator WORD & WORD::operator=(const WORD & w)" << endl;
// test if replacing the same object
cout << "w is " << w << endl;
cout << "this is " << *this << endl;
if (this == &w) { return *this; }
// replace everything in (*This) with
character *current = front;
character *next;
// get rid of the original list
while (current != 0)
{
next = current->next;
delete current;
current = next;
}
// make a new list
(*this).front = 0;
(*this).back = 0;
current = w.front;
while (current != 0)
{
(*this).add(current->symbol);
current = current->next;
}
return (*this);
}
void WORD::add(char c)
{
// create new node
character *add = new character;
add->symbol = c;
add->next = 0;
// for the first node
if (front == 0)
{
front = add;
back = add;
return;
}
// point the back node to the new node
back->next = add;
// define the new back node
back = add;
}
//*************************************************************************************
//Name: Operator <<
//Precondition: A WORD has not been printed to output
//Postcondition: A WORD is printed to output
//Description: Prints to output a WORD without having to call the Print function
//
//*************************************************************************************
ostream & operator<<(ostream & out, const WORD & Org)
{
character *p;
for (p = Org.front; p != 0; p = p->next) {
out << p->symbol;
}
return out;
}
//*************************************************************************************
//Name: Insert
//Precondition: A List_Type is passed to the function and
//has not been added to the linked list
//Postcondition: The List_Type has been added to the linked list
//Description: The function, Insert, adds a new List_Type symbol item to the front
//of the linked list. If the list is null, memory is allocated for a
//new node, and key is stored in the symbol filed, and 0 is stored in the next field,
// and front and back are set to point to the node.
//
//If the list is not null, memory is allocated for a new node,
//and key is stored in the symbol filed, and front is stored in the next field,
//and front is set to point to the node.
//*************************************************************************************
void WORD::Insert(const List_Type & key)
{
if (front == 0)
{
front = new character;
front->symbol = key;
front->next = 0;
back = front;
}
else
{
character *p = new character;
p->next = 0;
p->symbol = key;
back->next = p;
back = p;
}
}
//*************************************************************************************
//Name: Remove
//Precondition: Org is passed to the function. *this remains unchanged.
//Postcondition: 1 instance of Org, if found, is removed from *this
//Description: The function, Remove, removes Org, if it is in the list,
//from any location anywhere (front, back, and between front and back).
//
//*************************************************************************************
void WORD::Remove(WORD & Org)
{
cout << "Remove Invoked" << endl;
character *obj = this->front;
character *key = Org.front;
character *pp = obj;
int len = Org.Length();
int count = 0, num = 0;
while (obj != NULL)
{
if (obj->symbol == key->symbol)
{
character *temp = obj;
character *temp2 = key;
for (int i = 0; i < len; i++)
{
if (obj->symbol == key->symbol)
{
key = key->next;
obj = obj->next;
count++;
}
else
{
count = 0;
key = temp2;
pp = pp->next;
num++;
break;
}
}
if (count == len)
{
if (num == 0)
{
pp = obj;
front = obj;
}
else {
pp->next = obj;
}
for (int i = 0; i < count; i++)
{
character *p = temp;
temp = temp->next;
delete p;
if (i == 0)
{
key = temp2;
}
}
count = 0;
break;
}
}
else
{
num++;
pp = obj;
obj = obj->next;
}
}
}
//*************************************************************************************
//Name: Is_Empty
//Precondition: Unknown if current object is empty
//Postcondition: Known if current object is empty
//Description: If the current object is empty, returns true
//
//*************************************************************************************
bool WORD::Is_Empty()
{
if (front == NULL) {
return true;
}
return false;
}
//*************************************************************************************
//Name: RemoveAll
//Precondition: Org is passed to the function. *this remains unchanged.
//Postcondition: Current object no longer has any instances of Org
//Description: All instances of Org, if found, are removed from *this.
//
//*************************************************************************************
void WORD::RemoveALL(WORD & Org)
{
cout << "RemoveALL Invoked" << endl;
character *obj = this->front;
character *key = Org.front;
character *pp = obj;
int len = Org.Length();
int count = 0, num = 0;
while (obj != NULL)
{
if (obj->symbol == key->symbol)
{
character *temp = obj;
character *temp2 = key;
for (int i = 0; i < len; i++)
{
if (obj->symbol == key->symbol)
{
key = key->next;
obj = obj->next;
count++;
}
else
{
count = 0;
key = temp2;
pp = pp->next;
num++;
break;
}
}
if (count == len)
{
if (num == 0)
{
pp = obj;
front = obj;
}
else {
pp->next = obj;
}
for (int i = 0; i < count; i++)
{
character *p = temp;
temp = temp->next;
delete p;
if (i == 0)
{
key = temp2;
}
}
count = 0;
}
}
else
{
num++;
pp = obj;
obj = obj->next;
}
}
}
(2)Next file code:
word.h
#include <iostream>
#include <string>
using namespace std;
#ifndef WORD_H
#define WORD_H
typedef char List_Type;
//declaration for a node in the list
class character
{
public:
List_Type symbol; //symbol element
character *next; //pointer element
};
//declaration of a list class
class WORD
{
public:
WORD();
WORD(const string & s);
WORD(const WORD & org);
bool Is_Empty();
int Length();
~WORD();
void operator+(const WORD & B);
bool IsEqual(const WORD & B);
void Print();
void operator=(const string & s);
WORD & operator=(const WORD & w);
friend ostream & operator<<(ostream & out, const WORD & Org);
void Insert(const List_Type &);
void Remove(WORD & Org);
void RemoveALL(WORD & Org);
private:
character * front, *back;
};
#endif
(3) LAST FILE:
word_driver.cpp
#include <iostream>
#include <string>
#include "word.h"
using namespace std;
int main()
{
WORD you;
cout << "************TEST#1******************************* ";
cout << "Testing the default constructor and printing empty word ";
you.Print();
cout << "The length of you is " << you.Length() << " = 0 ";
cout << "************************************************* ";
cout << endl << endl;
cout << "************TEST#2******************************* ";
WORD me("AAAA0000AAA0000AAA");
cout << "Testing the explicit-value constructor ";
cout << "me is " << me << " = AAAA0000AAA0000AAA ";
cout << "************************************************* ";
cout << endl << endl;
cout << "************TEST#3******************************* ";
WORD them = me;
cout << "Testing the copy constructor ";
cout << "them is " << them << " = AAAA0000AAA0000AAA ";
cout << "************************************************* ";
cout << endl << endl;
cout << "************TEST#4******************************* ";
cout << "Testing length ";
cout << "The length of me is " << me.Length() << " = 18 " << endl;
cout << "The length of them is " << them.Length() << " = 18 " << endl;
cout << "The length of you is " << you.Length() << " = 0 " << endl;
cout << "************************************************* ";
cout << endl << endl;
cout << "************TEST#5******************************* ";
WORD us;
us = "AA";
cout << "Testing operator= by assignment the value of "AA" to use ";
cout << "The word us is " << us << " = AA" << endl;
cout << "************************************************* ";
cout << endl << endl;
cout << "************TEST#6******************************* ";
WORD everyone;
everyone = "hello world ";
cout << "Testing operator= by assignment the value of "hello world" to use ";
cout << "The word everyone is " << everyone << " = hello world" << endl;
cout << "************************************************* ";
cout << endl << endl;
cout << "************TEST#7******************************* ";
WORD our, him;
our = "AAA000AAA000";
us = "XXXX";
cout << "*****TEST#7 part A (testing for non-equal strings)****** ";
cout << "Testing IsEqual by testing to see if 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 " << endl;
our = "XXXX";
cout << "****TEST#7 part B (testing for equal strings)***** ";
cout << "Testing IsEqual by testing to see if 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 equal ";
cout << "************************************************* ";
cout << endl << endl;
cout << "************TEST#8******************************* ";
cout << "Adding 2 words by adding us to the back of their. Their is the current object ";
WORD their("AAAA0000AAA0000AAA");
us = "XXXX";
their + us;
cout << "their followed by us is " << their << " = AAAA0000AAA0000AAAXXXX" << endl;
cout << "************************************************* ";
cout << endl << endl;
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 " << their2 << " = XXXX" << endl;
cout << "************************************************* ";
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 " << us << " = XXXX" << endl;
cout << "************************************************* ";
cout << endl << endl;
cout << endl << endl;
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 << endl << endl;
cout << endl << endl;
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;
cout << "them = abcabc567 after removing all occurrences of us are removed" << endl << endl;
cout << "************************************************* ";
cout << "************************************************* ";
cout << endl << endl;
cout << endl << endl;
cout << "************TEST#13******************************* ";
cout << "Testing the Assignment Operator" << endl << endl;
us = "XXXX";
them = "123abc123abc1234567";
cout << "Them is " << them << endl;
cout << "Us is " << us << endl;
them = us;
cout << "Them is " << them << endl;
cout << "Us is " << us << endl;
cout << "************************************************* ";
cout << "************************************************* ";
cout << endl << endl;
cout << endl << endl;
return 0;
}
Explanation / Answer
I have fixed your code below.Please do rate this answer positive, If i was able to help you. Let me know if you have any issues in comments
word.h
#include <iostream>
#include <string>
using namespace std;
#ifndef WORD_H
#define WORD_H
typedef char List_Type;
//declaration for a node in the list
class character
{
public:
List_Type symbol; //symbol element
character *next; //pointer element
};
//declaration of a list class
class WORD
{
public:
WORD();
WORD(const string & s);
WORD(const WORD & org);
bool Is_Empty();
int Length();
~WORD();
void operator+(const WORD & B);
bool IsEqual(const WORD & B);
void Print();
void operator=(const string & s);
WORD & operator=(const WORD & w);
friend ostream & operator<<(ostream & out, const WORD & Org);
void Insert(const List_Type &);
void Remove(WORD & Org);
void RemoveALL(WORD & Org);
void add(char c);
private:
character * front, *back;
};
#endif
word.cpp
#include <iostream>
#include <string>
#include "word.h"
using namespace std;
//*************************************************************************************
//Name: Default Constructor
//Precondition: The state of the class WORD has not been initialized
//Postcondition: The state of the class WORD has been initialized;
//pointers to front and back are set to 0 using chaining;
//Description: The default constructor is used to initialize the state of your class.
//In this case, the state of your class are the pointers, front and back.
//*************************************************************************************
WORD::WORD()
{
cout << "Inside the default constructor ";
front = back = 0;
}
//*************************************************************************************
//Name: Explicit-value constructor
//Precondition: A string is passed to the function but has not been
//added to the linked list
//Postcondition: The string is created and added to the linked list
//Description: This constructor will have one argument;
//a C-style string or a C++ string representing the word to be created;
//this overload is used to combine two lists
//*************************************************************************************
WORD::WORD(const string & s) {
front = back = 0;
for (int i = 0; i < s.length(); i++)
{
Insert(s[i]);
}
}
//*************************************************************************************
//Name: Copy Constructor
//Precondition: A WORD is declared but has not been initialized.
//Postcondition: A WORD has been initialized.
//Description: Used during a call by value, return,
//or initialization/declaration of a word object;
//*************************************************************************************
WORD::WORD(const WORD & org) {
front = new character;
front->symbol = org.front->symbol;
front->next = org.front->next;
back = front;
}
//*************************************************************************************
//Name: Length
//Precondition: The function is called and the length of *this is unknown.
//Postcondition: The length of *this is returned in an int.
//Description: The function is used to determine the length of *this.
//*************************************************************************************
int WORD::Length()
{
if (front == 0)
{
return 0;
}
else
{
character *p = front;
int count = 0;
while (p != 0)
{
count++;
p = p->next;
}
return count;
}
}
//*************************************************************************************
//Name: Destructor
//Precondition: Memory is stored in the class.
//Postcondition: No memory is stored in the class.
//Description: The destructor will de-allocate all the memory allocated to your class.
//It is call automatically by the compiler when the current object goes
//out of scope.
//*************************************************************************************
WORD::~WORD()
{
cout << "Destructor has been called ";
while (front != 0)
{
character *p = front;
front = front->next;
delete p;
}
}
//*************************************************************************************
//Name: Opeartor +
//Precondition: Two WORDs (*this and the WORD passed to the function) are separate entities
//Postcondition: Two WORDs are combined into one, with the word being passed
//appended to the end of *this
//Description: This overloaded function is called to combine two lists
//
//*************************************************************************************
void WORD::operator+(const WORD & B)
{
character *p = B.front;
while (p != NULL)
{
Insert(p->symbol);
p = p->next;
}
}
//*************************************************************************************
//Name: IsEqual
//Precondition: It is unknown if two WORDs are the same
//Postcondition: If both WORDs are the same, returns true; else false;
//Description: This function compares two WORDs and returns true if they are
//the same WORD and falseotherwise
//
//*************************************************************************************
bool WORD::IsEqual(const WORD & B) {
character *visitor = B.front; // incoming node holder
character *current = front; // current node holder
//check if both characters are empty. if not, runs loop
while (current != 0 && visitor != 0)
{
// check if they match
if (current->symbol != visitor->symbol) { return false; }
// move forward 1 node
visitor = visitor->next;
current = current->next;
}
return true; // they must match or the loop would have returned.
}
//*************************************************************************************
//Name: Print
//Precondition: The WORDs have not been printed to output
//Postcondition: The WORDs are printed to output
//Description: The following function, Print, prints all the symbol stored in the
//linked list of the current object. In this case, printing starts at
//the front of the list.
//*************************************************************************************
void WORD::Print()//accessor
{
character *p = front;
cout << endl << endl;
while (p != 0)
{
cout << p->symbol << endl;
p = p->next;
}
cout << endl << endl;
}
//*************************************************************************************
//Name: Opeartor =
//Precondition: A WORD and a string are passed to the function
//Postcondition: The WORD has been assigned the value of the string; any previous
//string assigned to the WORD has been deleted
//Description: Overload the assignment operator as a member function to take a
//string (C++ string) as an argument and
//assigns its value to the current object;
//*************************************************************************************
void WORD::operator=(const string & s)
{
front = 0;
back = 0;
for (int i = 0; i < s.length(); i++)
{
Insert(s[i]);
}
}
//*************************************************************************************
//Name: Opeartor =
//Precondition: Two WORDs (*this and the element passed to the function)
//are separate.
//Postcondition: This* is assigned the value of the WORD passed to the function;
//any value previously stored in *this is removed
//Description: Overload the assignment operator as a member function with chaining to take a word
//object as an argument and assigns its value to the current object;
//*************************************************************************************
WORD & WORD::operator=(const WORD & w)
{
cout << "In the assignment operator WORD & WORD::operator=(const WORD & w)" << endl;
// test if replacing the same object
cout << "w is " << w << endl;
cout << "this is " << *this << endl;
if (this == &w) { return *this; }
// replace everything in (*This) with
character *current = front;
character *next;
// get rid of the original list
while (current != 0)
{
next = current->next;
delete current;
current = next;
}
// make a new list
(*this).front = 0;
(*this).back = 0;
current = w.front;
while (current != 0)
{
(*this).add(current->symbol);
current = current->next;
}
return (*this);
}
void WORD::add(char c)
{
// create new node
character *add = new character;
add->symbol = c;
add->next = 0;
// for the first node
if (front == 0)
{
front = add;
back = add;
return;
}
// point the back node to the new node
back->next = add;
// define the new back node
back = add;
}
//*************************************************************************************
//Name: Operator <<
//Precondition: A WORD has not been printed to output
//Postcondition: A WORD is printed to output
//Description: Prints to output a WORD without having to call the Print function
//
//*************************************************************************************
ostream & operator<<(ostream & out, const WORD & Org)
{
character *p;
for (p = Org.front; p != 0; p = p->next) {
out << p->symbol;
}
return out;
}
//*************************************************************************************
//Name: Insert
//Precondition: A List_Type is passed to the function and
//has not been added to the linked list
//Postcondition: The List_Type has been added to the linked list
//Description: The function, Insert, adds a new List_Type symbol item to the front
//of the linked list. If the list is null, memory is allocated for a
//new node, and key is stored in the symbol filed, and 0 is stored in the next field,
// and front and back are set to point to the node.
//
//If the list is not null, memory is allocated for a new node,
//and key is stored in the symbol filed, and front is stored in the next field,
//and front is set to point to the node.
//*************************************************************************************
void WORD::Insert(const List_Type & key)
{
if (front == 0)
{
front = new character;
front->symbol = key;
front->next = 0;
back = front;
}
else
{
character *p = new character;
p->next = 0;
p->symbol = key;
back->next = p;
back = p;
}
}
//*************************************************************************************
//Name: Remove
//Precondition: Org is passed to the function. *this remains unchanged.
//Postcondition: 1 instance of Org, if found, is removed from *this
//Description: The function, Remove, removes Org, if it is in the list,
//from any location anywhere (front, back, and between front and back).
//
//*************************************************************************************
void WORD::Remove(WORD & Org)
{
cout << "Remove Invoked" << endl;
character *obj = this->front;
character *key = Org.front;
character *pp = obj;
int len = Org.Length();
int count = 0, num = 0;
while (obj != NULL)
{
if (obj->symbol == key->symbol)
{
character *temp = obj;
character *temp2 = key;
for (int i = 0; i < len; i++)
{
if (obj->symbol == key->symbol)
{
key = key->next;
obj = obj->next;
count++;
}
else
{
count = 0;
key = temp2;
pp = pp->next;
num++;
break;
}
}
if (count == len)
{
if (num == 0)
{
pp = obj;
front = obj;
}
else {
pp->next = obj;
}
for (int i = 0; i < count; i++)
{
character *p = temp;
temp = temp->next;
delete p;
if (i == 0)
{
key = temp2;
}
}
count = 0;
break;
}
}
else
{
num++;
pp = obj;
obj = obj->next;
}
}
}
//*************************************************************************************
//Name: Is_Empty
//Precondition: Unknown if current object is empty
//Postcondition: Known if current object is empty
//Description: If the current object is empty, returns true
//
//*************************************************************************************
bool WORD::Is_Empty()
{
if (front == NULL) {
return true;
}
return false;
}
//*************************************************************************************
//Name: RemoveAll
//Precondition: Org is passed to the function. *this remains unchanged.
//Postcondition: Current object no longer has any instances of Org
//Description: All instances of Org, if found, are removed from *this.
//
//*************************************************************************************
void WORD::RemoveALL(WORD & Org)
{
cout << "RemoveALL Invoked" << endl;
character *obj = this->front;
character *key = Org.front;
character *pp = obj;
int len = Org.Length();
int count = 0, num = 0;
while (obj != NULL)
{
if (obj->symbol == key->symbol)
{
character *temp = obj;
character *temp2 = key;
for (int i = 0; i < len; i++)
{
if (obj->symbol == key->symbol)
{
key = key->next;
obj = obj->next;
count++;
}
else
{
count = 0;
key = temp2;
pp = pp->next;
num++;
break;
}
}
if (count == len)
{
if (num == 0)
{
pp = obj;
front = obj;
}
else {
pp->next = obj;
}
for (int i = 0; i < count; i++)
{
character *p = temp;
temp = temp->next;
delete p;
if (i == 0)
{
key = temp2;
}
}
count = 0;
}
}
else
{
num++;
pp = obj;
obj = obj->next;
}
}
}
wordDriver.cpp
#include <iostream>
#include <string>
#include "word.h"
using namespace std;
int main()
{
WORD you;
cout << "************TEST#1******************************* ";
cout << "Testing the default constructor and printing empty word ";
you.Print();
cout << "The length of you is " << you.Length() << " = 0 ";
cout << "************************************************* ";
cout << endl << endl;
cout << "************TEST#2******************************* ";
WORD me("AAAA0000AAA0000AAA");
cout << "Testing the explicit-value constructor ";
cout << "me is " << me << " = AAAA0000AAA0000AAA ";
cout << "************************************************* ";
cout << endl << endl;
cout << "************TEST#3******************************* ";
WORD them = me;
cout << "Testing the copy constructor ";
cout << "them is " << them << " = AAAA0000AAA0000AAA ";
cout << "************************************************* ";
cout << endl << endl;
cout << "************TEST#4******************************* ";
cout << "Testing length ";
cout << "The length of me is " << me.Length() << " = 18 " << endl;
cout << "The length of them is " << them.Length() << " = 18 " << endl;
cout << "The length of you is " << you.Length() << " = 0 " << endl;
cout << "************************************************* ";
cout << endl << endl;
cout << "************TEST#5******************************* ";
WORD us;
us = "AA";
cout << "Testing operator= by assignment the value of "AA" to use ";
cout << "The word us is " << us << " = AA" << endl;
cout << "************************************************* ";
cout << endl << endl;
cout << "************TEST#6******************************* ";
WORD everyone;
everyone = "hello world ";
cout << "Testing operator= by assignment the value of "hello world" to use ";
cout << "The word everyone is " << everyone << " = hello world" << endl;
cout << "************************************************* ";
cout << endl << endl;
cout << "************TEST#7******************************* ";
WORD our, him;
our = "AAA000AAA000";
us = "XXXX";
cout << "*****TEST#7 part A (testing for non-equal strings)****** ";
cout << "Testing IsEqual by testing to see if 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 " << endl;
our = "XXXX";
cout << "****TEST#7 part B (testing for equal strings)***** ";
cout << "Testing IsEqual by testing to see if 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 equal ";
cout << "************************************************* ";
cout << endl << endl;
cout << "************TEST#8******************************* ";
cout << "Adding 2 words by adding us to the back of their. Their is the current object ";
WORD their("AAAA0000AAA0000AAA");
us = "XXXX";
their + us;
cout << "their followed by us is " << their << " = AAAA0000AAA0000AAAXXXX" << endl;
cout << "************************************************* ";
cout << endl << endl;
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 " << their2 << " = XXXX" << endl;
cout << "************************************************* ";
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 " << us << " = XXXX" << endl;
cout << "************************************************* ";
cout << endl << endl;
cout << endl << endl;
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 << endl << endl;
cout << endl << endl;
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;
cout << "them = abcabc567 after removing all occurrences of us are removed" << endl << endl;
cout << "************************************************* ";
cout << "************************************************* ";
cout << endl << endl;
cout << endl << endl;
cout << "************TEST#13******************************* ";
cout << "Testing the Assignment Operator" << endl << endl;
us = "XXXX";
them = "123abc123abc1234567";
cout << "Them is " << them << endl;
cout << "Us is " << us << endl;
them = us;
cout << "Them is " << them << endl;
cout << "Us is " << us << endl;
cout << "************************************************* ";
cout << "************************************************* ";
cout << endl << endl;
cout << endl << endl;
return 0;
}
Output
Inside the default constructor
************TEST#1*******************************
Testing the default constructor and printing empty word
The length of you is 0 = 0
*************************************************
************TEST#2*******************************
Testing the explicit-value constructor
me is
AAAA0000AAA0000AAA = AAAA0000AAA0000AAA
*************************************************
************TEST#3*******************************
Testing the copy constructor
them is
AAAA0000AAA0000AAA = AAAA0000AAA0000AAA
*************************************************
************TEST#4*******************************
Testing length
The length of me is 18 = 18
The length of them is 18 = 18
The length of you is 0 = 0
*************************************************
************TEST#5*******************************
Inside the default constructor
Testing operator= by assignment the value of "AA" to use
The word us is
AA = AA
*************************************************
************TEST#6*******************************
Inside the default constructor
Testing operator= by assignment the value of "hello world" to use
The word everyone is
hello world
= hello world
*************************************************
************TEST#7*******************************
Inside the default constructor
Inside the default constructor
*****TEST#7 part A (testing for non-equal strings)******
Testing IsEqual by testing to see if us is equal to our
The 2 words are not equal
TEST SHOULD REVEAL THAT our AND us are not equal
****TEST#7 part B (testing for equal strings)*****
Testing IsEqual by testing to see if us is equal to our
The 2 words are equal
TEST SHOULD REVEAL THAT our AND us ARE equal
*************************************************
************TEST#8*******************************
Adding 2 words by adding us to the back of their. Their is the current object
their followed by us is
AAAA0000AAA0000AAAXXXX = AAAA0000AAA0000AAAXXXX
*************************************************
************TEST#9*******************************
Adding 2 words, their2 is empty, by adding us to the back of their. Their is the
current object
their followed by us is
XXXX = XXXX
*************************************************
************TEST#10*******************************
Adding 2 words, their3 is empty, by adding us to the back of their. Their is the
current object
us followed by empty their3 is
XXXX = XXXX
*************************************************
************TEST#11*******************************
Remove Invoked
Testing Remove by removing the first occurrence of us from them
The word them is abc123abc1234567
*************************************************
************TEST#12*******************************
RemoveALL Invoked
Testing RemoveAll by removing all occurrences of us from them
The word them is abcabc4567
them = abcabc567 after removing all occurrences of us are removed
*************************************************
*************************************************
************TEST#13*******************************
Testing the Assignment Operator
Them is 123abc123abc1234567
Us is XXXX
In the assignment operator WORD & WORD::operator=(const WORD & w)
w is XXXX
this is 123abc123abc1234567
Them is XXXX
Us is XXXX
*************************************************
*************************************************
Destructor has been called
Destructor has been called
Destructor has been called
Destructor has been called
Destructor has been called
Destructor has been called
Destructor has been called
Destructor has been called
Destructor has been called
Destructor has been called
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.