Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a class that implements your own string class, called MyString. Description of the class attributes: str: stores the memory address for a dynamically allocated

Write a class that implements your own string class, called MyString.

Description of the class attributes:

str: stores the memory address for a dynamically allocated array of characters. This stores a C-string. size: stores the number of characters in the c-string (not including the null terminator).

Constructor: accepts a C-String as it's only argument. Dynamically allocates an array long enough to store the argument and a null terminator. Sets size to the appropriate value. Copies the argument C-string into the new array.

Destructor: frees up the memory used by the dynamically allocated array.

size() - returns the number of characters in the string stored by MyString (excluding the null terminator).

set() - accepts a C-string as it's only argument. Replaces the current C-string held by the MyString object, resizing the array as needed.

at() - accepts an integer as it's only argument. Returns a reference to the element indicated by the argument. That is, if at is passed 1, then the second element is returned by reference. The method should throw the C-String exception "OUT OF BOUNDS!" if the argument passed would be an invalid subscript.

Place your complete class in it's own header file named MyString.h. Be sure to include preprocessor guards and mark accessors const.

UML diagram below:

image text in transcribed

MyString -str: char -size: int +MyString(s: char*) t-MyString0) +size(): int +set(s: char*): void +at(i: int): char&

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

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

9th Edition

0135188148, 978-0135188149, 9781642087611

More Books

Students also viewed these Databases questions

Question

=+Understand the fi eld of comparative IHRM.

Answered: 1 week ago

Question

=+j Understand different types of regions in the world.

Answered: 1 week ago