Question: C++ PROGRAMMING. Finished all the code but its not quite running correctly. Will attach all instructions and code. All code to be edited is in

C++ PROGRAMMING. Finished all the code but its not quite running correctly. Will attach all instructions and code. All code to be edited is in Text.cpp copied below. Please do not edit anything except Text.cpp. These are all functions of the class Text which isn't included or needed to write these methods. Please make sure the code compiles when I put it in my program so I can give 5 stars. Thank you <3

Instructions:

- Implement the Text ADT (40 points)

- Text(), operator=() and ~Text(), getLength(), clear(), operator[]

- Write the functions toUpper() and toLower() to test (30 points)

- Programming Exercise 3 :Write the operators ==, <, > and test (30 points)

text.cpp:

#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 return 0; }

void Text::clear () { buffer[0] = '\0'; }

void Text::showStructure() const

// Outputs the characters in a string. This operation is intended for // testing/debugging purposes only.

{ int j; // Loop counter

for (j = 0; j < bufferSize; j++) cout << j << "\t"; cout << endl; for (j = 0; buffer[j] != '\0'; j++) cout << buffer[j] << "\t"; cout << "\\0" << endl; }

Text Text::toUpper( ) const { Text temp; for (int i = 0; i < bufferSize; i++) { if ((buffer[i] > 96 && (buffer[i] < 123))) { temp.buffer[i] = char(buffer[i] - 32); } } return temp; }

Text Text::toLower( ) const { Text temp; for (int i = 0; i < bufferSize; i++) { if ((buffer[i] > 64 && (buffer[i] < 91))) { temp.buffer[i] = char(buffer[i] + 32); } } return temp; }

bool Text::operator == ( const Text& other ) const { { if (bufferSize == other.getLength()) { if (bufferSize == 0) { return true; } else { for (int i = 0; i < bufferSize; i++) { if (buffer[i] != other.buffer[i]) { return false; } } return true; } } else { return false; } } }

bool Text::operator < ( const Text& other ) const { if (bufferSize < other.getLength()) { return true; } else { return false; } }

bool Text::operator > ( const Text& other ) const { if (bufferSize > other.getLength()) { return true; } else { return false; } }

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!