diff options
| author | Tyler Taormina <[email protected]> | 2021-11-14 21:40:25 -0800 |
|---|---|---|
| committer | Tyler Taormina <[email protected]> | 2021-11-14 21:40:25 -0800 |
| commit | 3591c2727206bbda1d2da190fe5807cce3e9c75f (patch) | |
| tree | 90bba17645693f4804b83fbe29339531404ce6d9 | |
| parent | Everything but removing array elements is working! (diff) | |
| download | cst116-lab7-till-t-3591c2727206bbda1d2da190fe5807cce3e9c75f.tar.xz cst116-lab7-till-t-3591c2727206bbda1d2da190fe5807cce3e9c75f.zip | |
Lab complete
| -rw-r--r-- | num2.cpp | 70 |
1 files changed, 53 insertions, 17 deletions
@@ -9,13 +9,13 @@ using namespace std; -void RmString(string arr[]); +void RmString(string arr[], int); void GatherStrings(int& limit, string arr[]); void ClearBuffer(); void DisplayMenu(int&); void ProcessMenuChoice(int, int, string arr[]); void PrintString(int, string arr[]); -bool FindString(string arr[], int); +void FindString(string arr[], int); #define max 100 @@ -67,9 +67,12 @@ void GatherStrings(int& limit, string arr[]) } -bool FindString(string arr[], int limit) +void FindString(string arr[], int limit) { // Check for a substring inside of one of the input strings. + // Prints whether or not the string was found. If found + // prints the index of the list where the string was found + // and what the string was that contained the substring. string sub; int i, j, k; @@ -82,7 +85,7 @@ bool FindString(string arr[], int limit) for (i = 0; i < limit; i++) { if (arr[i].size() < sub.size()) - return false; + i = limit; for (j = 0; j < arr[i].size(); j++) { int k = 0; if (arr[i][j] == sub[k]) { @@ -93,19 +96,20 @@ bool FindString(string arr[], int limit) } if (k == sub.size()){ - return true; + cout << "We found it at index: " << i+1 << endl; + cout << "The string was: " << arr[i] << endl; } else j = reset; } } } - return false; } void PrintString(int limit, string arr[]) { + //Displays all strings stored. int i = 0; cout << "==================================================================\n"; cout << "This is what we have in our database so far..." << endl; @@ -113,22 +117,59 @@ void PrintString(int limit, string arr[]) while (i < limit) { - cout << *(arr+i) << endl; + cout << i+1 << ") " << *(arr+i) << endl; i += 1; } } -void RmString(string arr[]) +void RmString(string arr[], int limit) { + // Finds string within array and removes the element. + // May need to use vector. + int i = 0, j = 0, k = 0; + int choice; + string copy[max]; + cout << "What data entry would you like to delete..." << endl; + PrintString(limit, arr); + cout << "Please enter the number for the string that you'd like to delte: " << endl; + cin >> choice; + choice -= 1; + cout << "Working...\n\n" << endl; + + for (j = 0 ; j < limit + 1; j++) + { + if (k == choice) { + cout << "Deleting...\n\n" << endl; + k++; + } + else { + copy[j] = arr[k]; + k++; + } + + + } + + + cout << "==================================================================\n"; + cout << "Here is our updated database..." << endl; + cout << "==================================================================\n"; + + while (i < limit) + { + cout << i+1 << ") " << copy[i] << endl; + i++; + } + } void DisplayMenu(int& menu_choice) { - //displays the menu of functions for the user to choose from + //Displays the menu of functions for the user to choose from. bool flag = 0; cout << "==================================================================\n"; cout << " MENU" << endl; @@ -149,22 +190,17 @@ void DisplayMenu(int& menu_choice) void ProcessMenuChoice (int menu_choice, int limit, string usr_data[]) { + //Takes in user input for menu choice and calls the appropriate function. int program_rerun = 0; bool check; switch(menu_choice) { case 1: - check = FindString(usr_data, limit); - if (check) { - cout << "WE FOUND IT!" << endl; - } - else - cout << "ME NO FIND" << endl; - + FindString(usr_data, limit); break; case 2: - RmString(usr_data); + RmString(usr_data, limit); break; case 3: |