In C++ yhou will create a new class named StringMod that will have several functions specific to string. Here is a UML diagram: StringMod - str : string + StringMod() + StringMod(string); + size() const : int + backwards() const : string + count(char) const : int + getString() const : string + uppercase() const : string + lowercase() const : string + erase() : void + setString(string) : void First of all, none of these functions should contain output statements! No cout, no cin, in any of these functions! As you can see, several of the methods of StringMod are const, meaning they won’t change the internal string. You’ll likely declare a local string which will be updated and then returned. The default constructor just sets str to an empty string, "". The constructor with parameters should just call setString() to set str to the value passed to the constructor. backwards() returns a new string that is the reverse of the string in str. uppercase() takes every letter in the string and capitalizes it, while lowercase() does the opposite. Again, since these are all const, they don’t change the value of str. The erase() function sets str back to an empty string. The size() function returns the number of characters in the string (you can use the built in size() function that is in the string class here if you’d like, and call it within StringMod’s size() function. The count() function accepts a character as an argument, then counts the number of times that character appears in the string. For example, if "Aardvark" was the string and you were looking for 'a', it would return 2 (since A is different from a).
In C++
yhou will create a new class named StringMod that will have several functions specific to
string. Here is a UML diagram:
StringMod
- str : string
+ StringMod()
+ StringMod(string);
+ size() const : int
+ backwards() const : string
+ count(char) const : int
+ getString() const : string
+ uppercase() const : string
+ lowercase() const : string
+ erase() : void
+ setString(string) : void
First of all, none of these functions should contain output statements! No cout, no cin, in any of these
functions!
As you can see, several of the methods of StringMod are const, meaning they won’t change the
internal string. You’ll likely declare a local string which will be updated and then returned.
The default constructor just sets str to an empty string, "". The constructor with parameters should just
call setString() to set str to the value passed to the constructor.
backwards() returns a new string that is the reverse of the string in str.
uppercase() takes every letter in the string and capitalizes it, while lowercase() does the
opposite. Again, since these are all const, they don’t change the value of str. The erase() function
sets str back to an empty string.
The size() function returns the number of characters in the string (you can use the built in size()
function that is in the string class here if you’d like, and call it within StringMod’s size() function.
The count() function accepts a character as an argument, then counts the number of times that
character appears in the string. For example, if "Aardvark" was the string and you were looking for
'a', it would return 2 (since A is different from a).
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images