// Lab7Ansari.cpp : This file contains the 'main' function. Program execution begins and ends there. // #include #include #include #include #include using namespace std; void createStringArray(string strArray[100], int& arrayLen); void findStringInArray(string u, string strArray[100], int arrayLen); int main() { string strArray[100]; int arrayLen; string findInString; createStringArray(strArray, arrayLen); cout << "\n Enter the string you would like to find: "; cin >> findInString; findStringInArray(findInString, strArray, arrayLen); } void findStringInArray(string u, string strArray[100], int arrayLen) { bool found = false; int ulen = u.length(); for (int i = 0; i < arrayLen; i++) { for (int x = 0; x < strArray[i].length(); x++) { //cout << strArray[i].substr(x, x + ulen) << "\n"; if (strArray[i].substr(x, ulen) == u.substr(0, ulen)) { found = true; } } } if (found == true) { cout << '\n' << "Substring Found! " << endl; } else { cout << '\n' << "Substring Not Found! " << endl; } } void createStringArray(string strArray[100], int& arrayLen) { int option; int loop = 0; do { cout << "Please enter 0 to add a value, 1 to print the strings, 2 to remove a string, or any othe rnumber to exit: "; cin >> option; cout << endl; if (option == 0) { string addString; cout << "Enter string you would like to enter: "; cin >> addString; cout << endl; strArray[loop] = addString; loop++; } else if (option == 2) { int rpos; cout << '\n' << "What number string would you like to remove? : "; cin >> rpos; cout << endl; for (int y = 0; y < loop; y++) { if (y == rpos - 1) { for (int z = rpos - 1; z < loop; z++) { strArray[z] = strArray[z + 1]; } loop--; } } } else if (option == 1) { for (int i = 0; i < loop; i++) { cout << "String " << i + 1 << ": " << strArray[i]; cout << endl; } } } while (option == 0 || option == 1 || option == 2); arrayLen = loop; } // Run program: Ctrl + F5 or Debug > Start Without Debugging menu // Debug program: F5 or Debug > Start Debugging menu // Tips for Getting Started: // 1. Use the Solution Explorer window to add/manage files // 2. Use the Team Explorer window to connect to source control // 3. Use the Output window to see build output and other messages // 4. Use the Error List window to view errors // 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project // 6. In the future, to open this project again, go to File > Open > Project and select the .sln file