Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Data Management Databases And Organizations

Authors: Richard T. Watson

6th Edition

1943153035, 978-1943153039

More Books

Students also viewed these Databases questions

Question

Did the team members feel that their work mattered

Answered: 1 week ago

Question

3. What may be the goal of the team?

Answered: 1 week ago