Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am having problem getting the right output, I have provided the output needed for the program, and the output I am having. Please don't

I am having problem getting the right output, I have provided the output needed for the program, and the output I am having. Please don't make changes to text.h file, only text.cpp

Sample output image text in transcribed

My output

image text in transcribed

text.h

//-------------------------------------------------------------------- // // Laboratory 1 Text.h // **Instructor's Solution** // Class declaration for the array implementation of the Text ADT // //--------------------------------------------------------------------

#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

// 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;

private:

// 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

};

#endif

text.cpp

#include "pch.h" #include #include #include #include #include "Text.h" Text::Text(const char *charSeq) { bufferSize = strlen(charSeq) + 1; buffer = new char[bufferSize]; strcpy(buffer, charSeq); } Text::Text(const Text &other) { bufferSize = other.bufferSize; buffer = new char[bufferSize]; strcpy(buffer, other.buffer); } void Text::operator = (const Text &other) { int len = other.bufferSize; if (len > bufferSize) { delete[] buffer; bufferSize = other.bufferSize; buffer = new char[bufferSize]; } strcpy(buffer, other.buffer); } Text::~Text() { delete[] buffer; } int Text::getLength() const { return bufferSize - 1; } char Text::operator [] (int n) const { // check if n is out of range first if (n >= 0 && n Tests: 1 Tests the constructors 2 Tests the length operation 3 Tests the subscript operation 4 Tests the assignment and clear operations 5 Tests the copy constructor and operator- operations 6 Tests the toUpper and toLover operations Inactive : In-lah Exerc ise 2 7 Tests the relational operations Select the test to run 1 CInactive In-lab Exercise 3 Structure of various text objects: text object: alpha alpha text object: epsilon epsilon text object:a a. empty text object ests 1 Tests the constructors 2 Tests the length operation 3 Tests the subscript operation 4 Tests the assignment and clear operations 5 Tests the copy constructor and operator-operations 6 Tests the toUpper and toLower operations (Inactive In-lab Exercise 2) 7 Tests the relational operations (Inactive In-lab Exercise 3) Select the test to run 1 Structure of various text objects: text object: alpha text object: epsilon 6 0 text object: a empty text object Press any key to continue

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

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions

Question

1. Where will you recommend that she hold the focus group?

Answered: 1 week ago

Question

3. What might you have done differently

Answered: 1 week ago