C++ PLEASE!!       // FILE: simplestring.h // CLASS PROVIDED: string (a sequence of characters) // // CONSTRUCTOR for the string class: // string(const char str[ ] = "") -- default argument is the empty string. // Precondition: str is an ordinary null-terminated string. // Postcondition: The string contains the sequence of chars from str. // // CONSTANT MEMBER FUNCTIONS for the string class: // size_t length( ) const // Postcondition: The return value is the number of characters in the // string. // // char operator [ ](size_t position) const // Precondition: position < length( ). // Postcondition: The value returned is the character at the specified // position of the string. A string's positions start from 0 at the start // of the sequence and go up to length( )-1 at the right end. // // MODIFICATION MEMBER FUNCTIONS for the string class: // void operator +=(const string& addend) // Postcondition: addend has been catenated to the end of the string. // // void operator +=(const char addend[ ]) // Precondition: addend is an ordinary null-terminated string. // Postcondition: addend has been catenated to the end of the string. // // void operator +=(char addend) // Postcondition: The single character addend has been catenated to the // end of the string. // // NON-MEMBER FUNCTIONS for the string class: // string operator +(const string& s1, const string& s2) // Postcondition: The string returned is the catenation of s1 and s2. // // ostream& operator <<(ostream& outs, const string& source) // Postcondition: The sequence of characters in source has been written // to outs. The return value is the ostream outs. // // istream& getline(istream& ins, string& target) // Postcondition: A string has been read from the istream ins. The reading // operation reads all characters (including white space) until a newline // or end of file is encountered. The newline character is read and // discarded (but not added to the end of the string). // // VALUE SEMANTICS for the string class: // Assignments and the copy constructor may be used with string objects. // // DYNAMIC MEMORY usage by the string class: // If there is insufficient dynamic memory then the following functions call // new_handler: The constructors, operator +=, operator +, and the // assignment operator. #ifndef SIMPLESTRING_H #define SIMPLESTRING_H #include // Provides size_t #include // Provides ostream and istream class string_node { // define a node class here. }; class string { public: // CONSTRUCTORS and DESTRUCTOR string(const char str[] = ""); string(const string& source); ~string(); // MODIFICATION MEMBER FUNCTIONS void operator +=(const string& addend); void operator +=(const char addend[]); void operator +=(char addend); string& operator =(const string& source); int length() const; char operator [ ](int position) const; private: string_node* head_ptr; string_node* tail_ptr; int many_nodes; mutable string_node* cursor; mutable   size_type cursor_index; } // NON-MEMBER FUNCTIONS for the string class. string operator +(const string& s1, const string& s2); ostream& operator <<( ostream& outs, const string& source); void getline( istream& ins, string& target); } #endif

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

C++ PLEASE!!

 

 

 

// FILE: simplestring.h
// CLASS PROVIDED: string (a sequence of characters)
//
// CONSTRUCTOR for the string class:
// string(const char str[ ] = "") -- default argument is the empty string.
// Precondition: str is an ordinary null-terminated string.
// Postcondition: The string contains the sequence of chars from str.
//
// CONSTANT MEMBER FUNCTIONS for the string class:
// size_t length( ) const
// Postcondition: The return value is the number of characters in the
// string.
//
// char operator [ ](size_t position) const
// Precondition: position < length( ).
// Postcondition: The value returned is the character at the specified
// position of the string. A string's positions start from 0 at the start
// of the sequence and go up to length( )-1 at the right end.
//
// MODIFICATION MEMBER FUNCTIONS for the string class:
// void operator +=(const string& addend)
// Postcondition: addend has been catenated to the end of the string.
//
// void operator +=(const char addend[ ])
// Precondition: addend is an ordinary null-terminated string.
// Postcondition: addend has been catenated to the end of the string.
//
// void operator +=(char addend)
// Postcondition: The single character addend has been catenated to the
// end of the string.
//
// NON-MEMBER FUNCTIONS for the string class:
// string operator +(const string& s1, const string& s2)
// Postcondition: The string returned is the catenation of s1 and s2.
//
// ostream& operator <<(ostream& outs, const string& source)
// Postcondition: The sequence of characters in source has been written
// to outs. The return value is the ostream outs.
//
// istream& getline(istream& ins, string& target)
// Postcondition: A string has been read from the istream ins. The reading
// operation reads all characters (including white space) until a newline
// or end of file is encountered. The newline character is read and
// discarded (but not added to the end of the string).
//
// VALUE SEMANTICS for the string class:
// Assignments and the copy constructor may be used with string objects.
//
// DYNAMIC MEMORY usage by the string class:
// If there is insufficient dynamic memory then the following functions call
// new_handler: The constructors, operator +=, operator +, and the
// assignment operator.

#ifndef SIMPLESTRING_H
#define SIMPLESTRING_H
#include <cstdlib> // Provides size_t
#include <iostream> // Provides ostream and istream

class string_node
{
// define a node class here.

};

class string
{
public:
// CONSTRUCTORS and DESTRUCTOR
string(const char str[] = "");
string(const string& source);
~string();
// MODIFICATION MEMBER FUNCTIONS
void operator +=(const string& addend);
void operator +=(const char addend[]);
void operator +=(char addend);
string& operator =(const string& source);
int length() const;
char operator [ ](int position) const;
private:
string_node* head_ptr;
string_node* tail_ptr;
int many_nodes;
mutable string_node* cursor;
mutable   size_type cursor_index;
}

// NON-MEMBER FUNCTIONS for the string class.
string operator +(const string& s1, const string& s2);
ostream& operator <<( ostream& outs, const string& source);
void getline( istream& ins, string& target);
}

#endif

Write a new simple string class, where each object stores the characters in a linked list (with
one character per node). The pieces must be written from scratch using the header file
SimpleString.h as the starting point.
Make sure that you use a linked list to store its information.
Files that you must write:
• SimpleString.h: The header file for the string class that uses a linked list to store the
elements.
SimpleString.cpp: The implementation file for the new string class. You will write all of
this file, which will have the implementations of all the string's member functions.
stringTest.cpp: A simple interactive test program.
You may download the sample version of stringTest.cpp. Add more features if you need to.
Do Your Work in These Steps:
• Finish implementing the header file. Inchude at least three private member variables: a
head pointer, a tail pointer and a cursor (that is either NULL or points to the node that
was most recently used).
Implement the copy constructor, the other constructor, the destructor, and the length
function. Note: You may choose to store the current length in a private member
variable. This makes the length function simple, but it also means that all string functions
must correctly maintain the length member variable.
• Implement the rest of the member functions. Test your work again before proceeding.
Implement the nonmember functions.
Write a report file describing how the programs work and input/output screenshot.
• Remember to document your program and make good use of comments.
Transcribed Image Text:Write a new simple string class, where each object stores the characters in a linked list (with one character per node). The pieces must be written from scratch using the header file SimpleString.h as the starting point. Make sure that you use a linked list to store its information. Files that you must write: • SimpleString.h: The header file for the string class that uses a linked list to store the elements. SimpleString.cpp: The implementation file for the new string class. You will write all of this file, which will have the implementations of all the string's member functions. stringTest.cpp: A simple interactive test program. You may download the sample version of stringTest.cpp. Add more features if you need to. Do Your Work in These Steps: • Finish implementing the header file. Inchude at least three private member variables: a head pointer, a tail pointer and a cursor (that is either NULL or points to the node that was most recently used). Implement the copy constructor, the other constructor, the destructor, and the length function. Note: You may choose to store the current length in a private member variable. This makes the length function simple, but it also means that all string functions must correctly maintain the length member variable. • Implement the rest of the member functions. Test your work again before proceeding. Implement the nonmember functions. Write a report file describing how the programs work and input/output screenshot. • Remember to document your program and make good use of comments.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Declaring and Defining the Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education