Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this assignment, you will provide one possible implementation of the string class. You will use a dynamic array of characters to represent the string.

In this assignment, you will provide one possible implementation of the string class. You
will use a dynamic array of characters to represent the string. In order to avoid conflicts, we
will call the class myString and use the file names myString.h and myString.cc.(There
are better ways to avoid conflicts, and we will discuss this later in the course.)
Functionalities
Your class should provide the following methods. Here, current string refers to the string
that the method is called with. I.e. in s.length(), s is the current string.
default constructor: initializes to the empty string.
a constructor with a char * parameter (i.e. conversion). The supplied pointer should
be treated as a character array. The string should be initialized to the content of
the character array until the character \0 is seen. This is called a null-terminated
string or a C-string. Note that a string literal in C++(e.g. "hello") is treated as
a character array.
a constructor with a char parameter (i.e. conversion). A string with a single character
is constructed.
a copy constructor and an assignment operator.
a destructor.
int length(): returns the length of the string.
char& at(int i): returns a reference to the ith character. Also provide a version
which returns a reference to a constant.
myString substr(int k, int n): returns a substring of the current string starting
at index k and of length n. E.g. If s == "abcdefg", then s.substr(2,4)== "cdef".
1
myString& erase(int k, int n): erase n characters starting at index k from the
current string. Returns a reference to the modified string. E.g. If s == "abcdefg",
then after s.erase(2,4), s == "abg".
myString& insert(int k, const myString& s): inserts the string s into the current
string at position k. Returns a reference to the modified string. E.g. If s ==
"abcdefg", then after s.insert(2,"xyz"), s == "abxyzcdefg". Here, k can be the
length of the string, meaning that the string s is appended to the current string.
int find(const myString& s): returns the index to the first occurrence of the string
s inside the current string. If s does not occur in the current string, the function returns
myString::npos (see notes below).
Also, provide the following friend functions:
istream& getline(istream& is, myString& s): reads a line of text into a string.
Notes
1. This is a large class. You may want to implement a few functionalities at a time and
test them. START EARLY!
2. Your assignment will be marked on program correctness and readability (including
comments). For all classes, use const member functions when appropriate. When
appropriate, use assert to ensure that the supplied indices are correct. You may wish
to write private helper functions for certain tasks, such as resizing the array, copying
the array, etc.
3. Also write a Makefile which can be used to compile all programs in this assignment.
4. The constant myString::npos should be a static constant member set to 1. It is
guaranteed to be an invalid index into the string.
5. A driver program (stringTest.cc) will be provided to you to test your string class.
6. Be sure that there are no memory errors: all arrays are large enough to hold the results,
and there are no memory leaks.
7. The standard way of using dynamic arrays (allocating an array just large enough to
hold the result and remembering its size) can be inefficient because of the frequent
need to allocate and deallocate arrays. In this assignment, we are not concerned about
efficiency.
2

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

Professional Visual Basic 6 Databases

Authors: Charles Williams

1st Edition

1861002025, 978-1861002020

More Books

Students also viewed these Databases questions

Question

l Discuss three aspects of international training and development.

Answered: 1 week ago

Question

Explain budgetary Control

Answered: 1 week ago

Question

Solve the integral:

Answered: 1 week ago

Question

What is meant by Non-programmed decision?

Answered: 1 week ago

Question

What are the different techniques used in decision making?

Answered: 1 week ago

Question

What are Measures in OLAP Cubes?

Answered: 1 week ago

Question

How do OLAP Databases provide for Drilling Down into data?

Answered: 1 week ago

Question

How are OLAP Cubes different from Production Relational Databases?

Answered: 1 week ago