UPDATE: New due date - ALL commits (1 and 2) are due 10/12 at midnight)
In this project, you will be creating your own string class (called SuperString). At this point we have used the std::string
object (https://www.cplusplus.com/reference/string/string/) in C++ quite a bit. You should now have an idea of how to use some of the functions it contains (like the find and replace). In this project, you will create an object that mimicks some of this functionality and also builds on it!
Your SuperString object is already defined for you in the SuperString.h
file in your GitHub repo. Below I will describe more details about all of the variables and functions. Make sure that you read this all the way through before starting! There is important information at the end about how to run the code! (https://github.com/coleca24/csce240_f21_p2/blob/main/ProjectDescription.md#compiling-and-running-your-code)
char *data
: a dynamic pointer array that holds each character of the string within that SuperString objectint size
: the size of thedata
array (how many characters it holds)
SuperString()
: The default constructor. Should:- set
size
to 0 - allocate the
data
array to a new char array of sizesize
- set
explicit SuperString(std::string)
: Alt. Constructor #1. Should:- set
size
to the length of the string passed in - allocate the
data
array to a new char array of sizesize
- fill the contents of the
data
array with the contents of the string passed in
- set
SuperString(int, char)
: Alt. Constructor #2. Should:- set
size
to the value of the int passed in - allocate the
data
array to a new char array of sizesize
- fill all contents of the
data
array with the character passed in
- set
SuperString(const SuperString&)
: Copy Constructor. Should:- set
size
to the size of the object passed in - allocate the
data
array to a new char array of sizesize
- fill all contents of the
data
array with the same contents as the passed object's data
- set
~SuperString()
: Should deallocate the data array
void print()
: prints the contents of your array - Already implemented DO NOT MODIFYchar get(int)
: Extracts an element from yourdata
array. - Already implemented DO NOT MODIFYint length()
: returns thesize
. - Already implemented DO NOT MODIFYint find(char, int start = 0)
- Should not modify the calling object
- returns the index of the first instance of the character passed in the
data
array starting at indexstart
- returns -1 if the character does not exist.
- Ex. obj.data = "Hello" then obj.find('l', 0) == 2
- Ex. obj.data = "Hello" then obj.find('l', 3) == 3
int find(std::string, int start = 0)
- Should not modify the calling object
- returns the index of the first instance of the string passed in the
data
array starting at indexstart
- returns -1 if the character does not exist.
- Ex. obj.data = "that cat is a cool cat" then obj.find("cat", 0) == 5
- Ex. obj.data = "that cat is a cool cat" then obj.find("cat", 6) == 19
SuperString substr(int start, int numChar)
- Should not modify the calling object
- returns a
SuperString
object that contains the substring of the calling object's data starting at indexstart
and spanning the number of characters held innumChar
- Contents of the returned object should be size 0 if no substring is able to be extracted. This would happen if a user gave an index that was out of bounds.
- Ex. obj.data = "Hello" then obj.substr(0,2) == ret.data =="He"
- Ex. obj.data = "Hello" then obj.substr(4,2) == ret.data == empty // Note that this will attempt to get a substring that walks out of bounds (the last index would be 4 + 2 = 6 which is out of bounds)
SuperString reverse()
- Should not modify the calling object
- Returns a
SuperString
object thats data array contains the calling calling object's data in reverse order. - Ex. obj.data = "Hello" then obj.reverse() == ret.data == "olleH"
SuperString replace(int index, int numChar, std::string sub)
- Should not modify the calling object
- Returns a
SuperString
object thats data array has the contents of the data after the replacement is performed. - Returns a
SuperString
object with size = 0 if invalid index is passed. - How the replacement is performed:
- Starting at
index
, the elements of thedata
array are removed up untilindex
+numChar
and replaced with the contents of the passed stringsub
- Starting at
- Ex. obj.data = "Hello" then obj.replace(0, 2, "Jal") == ret.data == "Jalllo"
void push_back(char)
- Modifies the calling object
- Adds a new character (the one passed in) to the
data
array of the calling object. - Ex. obj.data = "hello" then obj.push_back('w') -> obj.data == "hellow"
void append(std::string)
- Modifies the calling object
- Appends the content of the passed string to the end of the
data
array of the calling object - Ex. obj.data = "hello" then obj.append(" world") -> obj.data == "hello world"
void append(const SuperString&)
- Modifies the calling object
- Appends the content of the passed
SuperString
to the end of thedata
array of the calling object - Ex. obj.data = "hello" and obj2.data = " world" then obj.append(obj2) -> obj.data == "hello world"
void replace(char find, char rep)
- Modifies the calling object
- Replaces all instances of the character
find
in the calling object'sdata
array with therep
character. - Ex. obj.data = "catcat" then obj.replace('c', 't') -> obj.data = "tattat"
Extra Credit Functions:
void removeAll(char)
- Modifies the calling object
- Removes all of the instances of the character that is passed in is in the
data
array - Ex. obj.data = "hello" then obj.removeAll('l') -> obj.data == "heo"
void replace(std::string find, std::string sub)
- Modifies the calling object
- Replaces all instance of a string
find
with the stringsub
- Ex. obj.data = "this cat is a cool cat" then obj.replace("cat", "dog") -> obj.data = "this dog is a cool dog"
bool isUpper()
- Should not modify the calling object
- Returns true if the
data
array contains all uppercase characters - Returns false if the
data
array contains anything other than uppercase characters
bool isLower()
- Should not modify the calling object
- Returns true if the
data
array contains all lowercase characters - Returns false if the
data
array contains anything other than lowercase characters
bool isTitleCase()
- Should not modify the calling object
- Returns true if the
data
array contains a sentence that is in proper "Title" case. - Returns false if the
data
array contains contains a sentence that is not in proper "Title" case. - For this function we are going to simplify the definition of "Title" case to be every new word in a sentence is capitalized.
- For example: "This Is Our Modified Title Case" and "This Does Not Count as Title Case" (because of the "as")
NEW DUE DATE: ALL COMMITS (1 AND 2) DUE 10/12 AT MIDNIGHT
Functions to complete:
SuperString();
explicit SuperString(std::string);
SuperString(int, char);
SuperString(const SuperString&);
~SuperString();
int find(char, int start = 0);
int find(std::string, int start = 0);
SuperString substr(int, int);
Functions to complete:
SuperString reverse(const SuperString&);
SuperString replace(int, int, std::string);
void push_back(char);
void append(std::string);
void append(const SuperString&);
SuperString replace(char, char);
void removeAll(char);
SuperString replace(std::string, std::string);
bool isUpper();
bool isLower();
bool isTitleCase();
To compile and run your code with Google Tests:
Windows WSL and Linux:
g++ main-gtest.cpp SuperString.cpp -lgtest -lpthread -o proj2
./proj2
Mac:
g++ -std=c++2a main-gtest.cpp SuperString.cpp -lgtest -lpthread -o proj2
./proj2
To compile and run your code without Google Tests:
Windows WSL and Linux:
g++ main.cpp SuperString.cpp -o proj2
./proj2
Mac:
g++ -std=c++2a main.cpp SuperString.cpp -o proj2
./proj2
To compile and run your Extra Credit code with Google Tests:
Windows WSL and Linux:
g++ main-bonus-gtest.cpp SuperString.cpp -lgtest -lpthread -o proj2
./proj2
Mac:
g++ -std=c++2a main-bonus-gtest.cpp SuperString.cpp -lgtest -lpthread -o proj2
./proj2
To compile and run your Extra Credit code without Google Tests:
Windows WSL and Linux:
g++ main-bonus.cpp SuperString.cpp -o proj2
./proj2
Mac:
g++ -std=c++2a main-bonus.cpp SuperString.cpp -o proj2
./proj2
For more information about the Google test cases and the non-gtest mains, see: https://github.com/coleca24/csce240_f21_p2/blob/main/Testing.md
This time, you may modify the header (.h) or the SuperString.cpp or even one of the non-gtest related mains! That means that you may have multiple files to push. Make sure you push them all up if needed.
Example for pushing the .h and the SuperString.cpp together
git pull
git add SuperString.h SuperString.cpp
git commit -m "Added changes to .h and SuperString.cpp"
git push
Remember, you can use the command git status
to see what files you have modified since your last pull!
See the Testing.md file (https://github.com/coleca24/csce240_f21_p2/blob/main/Testing.md) for breakdown per Google Test.
SuperString();
- 1 pointexplicit SuperString(std::string);
- 1 pointSuperString(int, char);
- 1 pointSuperString(const SuperString&);
- 2 points~SuperString();
- 2 pointsint find(char, int start = 0);
- 2 pointint find(std::string, int start = 0);
- 3 pointsSuperString substr(int, int);
- 3 points
SuperString reverse(const SuperString&);
- 3 pointsSuperString replace(int, int, std::string);
- 5 pointsvoid push_back(char);
- 4 pointsvoid append(std::string);
- 5 pointsvoid append(const SuperString&);
- 5 pointsSuperString replace(char, char);
- 2 points
1 point for cpplint
void removeAll(char);
+ 2 pointSuperString replace(std::string, std::string);
+ 2 pointsbool isUpper();
+ 1 pointbool isLower();
+ 1 pointbool isTitleCase();
+ 2 point