解析C/C++、C/C++语言辅导留学生、辅导C/C++程序、C/C++编程讲解留学生、辅导C/C++ MyString程序
辅导Database|讲解R语
CSI 1440
Project 1.5
“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 proj1-5-MyString.h and proj1-5-
MyString.cpp respectively. Even though MyString.h will be provided on the upload site, you should create your
own version for testing your code locally. Make sure to properly test your code on your own by creating a test
driver that fully tests every function created in the MyString class.
Deliverables:
proj1-5-MyString.h
proj1-5-MyString.cpp
proj1-5-testMain.cpp
Memory Requirements:
Your MyString should start with 10 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 patten of 10, 20, 40, 80, … bytes of memory
depending of the number of characters stored.
Attributes:
int size – the number of characters currently stored in the string object. Do NOT count the NULL
character.
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 terminated with the NULL character.
Member Functions:
MyString( )
Constructor
MyString(const char *)
Constructor with an initialization character string
~MyString( )
Destructor
MyString(const MyString &)
Copy constructor
MyString& operator = (const MyString&)
Overloaded assignment operator, make a copy of MyString object
bool operator == (const MyString&) const
overloaded equivalence relational operator
char& operator [ ] (int)
overloaded [ ] should return a char by reference
void operator += (const MyString&)
overloaded += operator, use to concatenate two MyStrings
MyString operator + (const MyString&) const
Create a new MyString object that is the concatenation of two MyString
objects
void getline(istream&, char delimit = ‘\n’);
reads an entire line from a istream. Lines are terminated with delimit
which is newline ‘\n’ by default
int length( ) const;
return the length of the string
friend ostream& operator<< (ostream&, MyString&);
overloaded insertion operator
- QQ:99515681
- 邮箱:99515681@qq.com
- 工作时间:8:00-21:00
- 微信:codinghelp
联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!