From 3591c2727206bbda1d2da190fe5807cce3e9c75f Mon Sep 17 00:00:00 2001 From: Tyler Taormina Date: Sun, 14 Nov 2021 21:40:25 -0800 Subject: Lab complete --- num2.cpp | 70 ++++++++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 53 insertions(+), 17 deletions(-) (limited to 'num2.cpp') diff --git a/num2.cpp b/num2.cpp index 0b028e9..9470670 100644 --- a/num2.cpp +++ b/num2.cpp @@ -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: -- cgit v1.2.3