// John Bent's CS 110 Hand-out 8 // Harder array of strings - sequential search // // This program search throughout an array of strings for the string which // contains the most e's. It works correctly, except it does not take into // consideration the fact that some strings may have the same number of e's. #include int getEs (char []); int main() { char month[12][10] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; cout << "\nHere are the 12 months:"; for (int i = 0; i < 12; i++) { cout << endl << month[i]; } cout << endl << endl; int temp = 0, mostEs = 0, whichMonth = 0; for (int i = 0; i < 12; i++) { temp = getEs(month[i]); if (temp > mostEs) { mostEs = temp; whichMonth = i; } } cout << month[whichMonth] << " has the most e's in it." << endl << endl; return 0; } int getEs (char localMonth[]) { int Es = 0; for (int j = 0; j < 10 && localMonth[j] != '\0'; j++) if (localMonth[j] == 'e') Es++; return Es; }