Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Project 2.5 MyString 2.5 Remember to try to find as many solutions as you can using pointer arithmetic like we modeled today in class with

image text in transcribed

image text in transcribed

Project 2.5 "MyString 2.5 Remember to try to find as many solutions as you can using pointer arithmetic like we modeled today in class with strlen, strcat, and strcpy as you can on this version of MyString Class description: A MyString class should behave much like the c++ string class. Your class should use a dynamically allocated char array to hold a character string. If the amount of memory allocated to the array is too small to complete some necessary task (e.g., assigning a new character string to the object) your object should automatically double its capacity until it is large enough to complete the task. If you discover that your object is using less than 25% of its capacity your object should shrink to half its capacity until it is using more that 25% of its capacity. Problem Statement: Implement the MyString class using a header and implementation file named MyString.h and MyString.cpp respectively. Make sure to properly test your code on your own by creating a test driver that tests every function created in the MyString class. Some members and functions have been changed a bit Deliverables proj2.5-MyString.h proj2.5-MyString.cpp proj2.5-testMain.cpp Memory Requirements: Your MyString should start with 3 bytes of allocated memory and should grow in size by doubling. So, we should be able to predict the capacity of your MyString as acquiring a pattern of 3, 6, 12, 24,.. bytes of memory depending of the number of characters stored. Attributes: int capacity the number of bytes currently allocated. This should always be at least size + 1. The extra byte is needed to store the NULL character. char "data character pointer that points to an array of characters. Member Functions: MyString() o Constructor .MyString() o Destructor MyString(const MyString &) MyString(const char ") o Copy constructor MyString& operator (const MyString&) MyString& operator (const char ') o Overloaded assignment operator, make a copy of Cstring bool operator (const MyString&) const bool operator(const char ") const overloaded equivalence relational operator against Cstring char& operator [ 1 (int) ooverloaded [1 should return a char by reference Be sure to check array bounds (safe' version) void operator+(const MyString&) void operator + (const char ) ooverloaded +- operator, use to concatenate two MyStrings MyString operator + (const MyString&) const Create a new MyString object that is the concatenation of two MyString o objects void getline(istream&, char delimit n): o reads an entire line from a istream. Lines are terminated with delimit owhich is newline in by default int strlen() const; o calculate the length of the string o Do not consider lo int length( ) const MyString strcat(const char "other) MyString strcpy(const char other) o calculate the length of the string oDo not consider 10 concatenate other to end of current MyString make function 'array bounds safe o o o copy other to current MyString o make function 'array bounds safe int strcmp(const char "other) o return less than zero if MyString comes first in alphabet oreturn 0 if MyString and other are equal o return greater than zero otherwise int myStringTolnt() convert current MyString to int. static char reverseCString(char const str) utility function to reverse a cstring and return it reversed MyString reverseMeo o send back a copy of current MyString (this) reversed WITHOUT changing current Mystring state o .friend ostream& operatorss (ostream&. Mystring&) ooverloaded insertion operator string toString) toString function to print out class in more of a testing way Prints all members ot the class. Indent members o

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

Visual Basic Net Database Programming

Authors: Rod Stephens

1st Edition

0789726815, 978-0789726810

More Books

Students also viewed these Databases questions

Question

Technology. Refer to Case

Answered: 1 week ago