#include using namespace std; // This assignment is worth 4 points int main() { string str0, search_term; cout << "Enter first string: "; getline(cin, str0); cout << "Enter search term: "; getline(cin, search_term); int k = 0, search_found = 0; // Avoid probing beyond the array boundaries for(int i = 0; i < str0.length() - search_term.length()+1; i++) { k = 0; while(k < search_term.length() && str0[i+k] == search_term[k]) k++; // k counts the number of character matches in a row if(k == search_term.length()) { search_found++; i += search_term.length() - 1; // Skips over the rest of the pattern } } cout << "The first string has " << search_found << " instances of \"" << search_term << "\".\n"; return 0; }