diff options
| author | James Lawrance <[email protected]> | 2021-11-13 09:21:21 -0800 |
|---|---|---|
| committer | James Lawrance <[email protected]> | 2021-11-13 09:21:21 -0800 |
| commit | a28abddbdf0b81baed199b7fe11f6d9e254e2c63 (patch) | |
| tree | 89ef75e5c8052b5250007928213f069b169affa0 | |
| parent | 11b complete (diff) | |
| download | cst116-lab7-jemersonlawrance-a28abddbdf0b81baed199b7fe11f6d9e254e2c63.tar.xz cst116-lab7-jemersonlawrance-a28abddbdf0b81baed199b7fe11f6d9e254e2c63.zip | |
lab 7 completed 11/13/2021
| -rw-r--r-- | CST116F2021-Lab7/CST116F2021-Lab7.cpp | 47 | ||||
| -rw-r--r-- | CST116F2021-Lab7/Functions.cpp | 56 | ||||
| -rw-r--r-- | CST116F2021-Lab7/Header.h | 4 |
3 files changed, 92 insertions, 15 deletions
diff --git a/CST116F2021-Lab7/CST116F2021-Lab7.cpp b/CST116F2021-Lab7/CST116F2021-Lab7.cpp index c03ef4e..b7aa60f 100644 --- a/CST116F2021-Lab7/CST116F2021-Lab7.cpp +++ b/CST116F2021-Lab7/CST116F2021-Lab7.cpp @@ -21,23 +21,50 @@ //} //12b -int main() -{ +//int main() +//{ + //initializations +// string strData[100]; + + //title and start prompt +// cout << setw(65) << "--String Reader--\n" +// << endl; + +// cout << "You can enter up to one hundred strings. When finished entering, please type \"done,\" and your strings will display.\n"; + + //get string data +// getStringData(strData); + + //display +// displayStrings(strData); + + //find string +// findString(strData); +//} + +//12c +//int main() +//{ //initializations - string strData[100]; +// string strData[100]; //title and start prompt - cout << setw(65) << "--String Reader--\n" - << endl; +// cout << setw(65) << "--String Reader--\n" +// << endl; - cout << "You can enter up to one hundred strings. When finished entering, please type \"done,\" and your strings will display.\n"; +// cout << "You can enter up to one hundred strings. When finished entering, please type \"done,\" and your strings will display.\n"; //get string data - getStringData(strData); +// getStringData(strData); //display - displayStrings(strData); +// displayStrings(strData); //find string - findString(strData); -}
\ No newline at end of file +// findString(strData); + + //remove string +// removeString(strData); + +// return 0; +//}
\ No newline at end of file diff --git a/CST116F2021-Lab7/Functions.cpp b/CST116F2021-Lab7/Functions.cpp index de7de7f..cefd0ea 100644 --- a/CST116F2021-Lab7/Functions.cpp +++ b/CST116F2021-Lab7/Functions.cpp @@ -48,9 +48,8 @@ int displayStrings(string data[]) } -//prints out "match found" each time a letter of the user string is found. -//once a match for the first letter is found, then it moves onto the next, printing "match found" for each match -void findString(string data[]) +//findString definition +int findString(string data[]) { //initializations int cntData = 0; @@ -96,7 +95,7 @@ void findString(string data[]) { cout << "\n\"" << user << "\" has been found in the display" << endl; - exit(0); + return 1; } } cntDataChar++; @@ -106,4 +105,53 @@ void findString(string data[]) } cout << "\n\"" << user << "\" has not been found in the display"; +} + +//removeString definition +int removeString(string data[]) +{ + //initializations + int a = 0; + int b = 0; + int c = 0; + + string userDelete; + + //prompt + cout << "\nEnter a string to delete from your display: "; + cin >> userDelete; + + cout << endl; + + //find + while (data[a] != "\0") + { + if (data[a] == userDelete) + { + cout << "\"" << data[a] << "\"" << " has been deleted.\n"; + break; + } + else + { + a++; + } + } + const int removePos = a; + + //remove + while (data[b+1] != "\0") + { + b++; + } + while (c <= (b - removePos)) + { + + data[a] = data[a + 1]; + a++; c++; + } + + //redisplay results + displayStrings(data); + + return 1; }
\ No newline at end of file diff --git a/CST116F2021-Lab7/Header.h b/CST116F2021-Lab7/Header.h index a29e4fd..204d6bd 100644 --- a/CST116F2021-Lab7/Header.h +++ b/CST116F2021-Lab7/Header.h @@ -11,4 +11,6 @@ int getStringData(string data[]); //displayStrings prototype int displayStrings(string data[]); //findString prototype -void findString(string data[]);
\ No newline at end of file +int findString(string data[]); +//removeString prototype +int removeString(string data[]);
\ No newline at end of file |