Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please solve the following problem using C++ language. Please include comments so that I am able to understand the code and please follow the instructions

Please solve the following problem using C++ language. Please include comments so that I am able to understand the code and please follow the instructions shown. Thanks in advance.Please make sure that the function toReverse is implemented recursively as directed.

image text in transcribed

// text.h

#ifndef TEXT_H #define TEXT_H #include  #include  using namespace std; class Text { public: // Constructors and operator= Text ( const char *charSeq = "" ); // Initialize using char* Text ( const Text &other ); // Copy constructor void operator = ( const Text &other ); // Assignment Text operator += (const Text &input2); //lab 2 // Destructor ~Text (); // Text operations int getLength () const; // # characters char operator [] ( int n ) const; // Subscript void clear (); // Clear string // Output the string structure -- used in testing/debugging void showStructure () const; //-------------------------------------------------------------------- // In-lab operations // toUpper/toLower operations (Programming Exercise 2) Text toUpper( ) const; // Create upper-case copy Text toLower( ) const; // Create lower-case copy // Relational operations (Programming Exercise 3) bool operator == ( const Text& other ) const; bool operator  ( const Text& other ) const; char toReverse(Text obj, int position) const; //lab 2 private: int count = 0; // Data members int bufferSize; // Size of the string buffer char *buffer; // Text buffer containing a null-terminated sequence of characters // Friends // Text input/output operations (In-lab Exercise 1) friend istream & operator >> ( istream& input, Text& inputText ); friend ostream & operator  

// test1.cpp

#include  #include "Text.h" #include "config.h" //-------------------------------------------------------------------- // // Function prototype void copyTester ( Text copyText ); // copyText is passed by value void print_help ( ); //-------------------------------------------------------------------- int main() { Text a("a"), // Predefined test text objects alp("alp"), alpha("alpha"), epsilon("epsilon"), empty, assignText, // Destination for assignment inputText, // Input text object inputText2; int n; // Input subscript char ch, // Character specified by subscript selection; // Input test selection // Get user test selection. print_help(); // Execute the selected test. cin >> selection; cout > n; ch = alpha[n]; cout > inputText; cout  " epsilon) alpha) alpha) alpha) alp) alpha) a) alpha) empty) empty) > inputText; inputText.toReverse(inputText, 0); //inputText.showStructure(); break; #endif // LAB2_TEST1 #if LAB2_TEST2 case '9': cout > inputText; cout > inputText2; inputText += inputText2; inputText.toReverse(inputText, 0); break; #endif // LAB2_TEST2 default : cout   30 pts) On the foundation of the previous Text ADT homework, add the following methods to the Text class: 1Implement the function to rse to reverse recursively the order of letters of the given Text object. Test your implementation by activating LAB2_TEST1 (15 pts) Function prototype: Text toReverse(Text obi, int position) const 2. Implement the operators+-. Test it by activating LAB2-TEST2. (15 pts) Function prototype: Text operator += (const Text & input2); Notel: Make Source code with the test cases are provided (text,h and test2.cpp). Make sure you create corresponding methods in text.cpp as well. There were added the following two lines into the configuration file: ingrvale corespondnd n #define LAB2 TEST! #define LAB2 TEST2 0 // Programming recursion // Programming operation and recursion Plus, there are included test cases to test your implementation

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions