// Program file: twodim.cpp // Demonstrates two dimemsional arrays #include #include using namespace std; typedef char word_array[4][11]; typedef char vowel_array[5]; struct info_type { vowel_array vowels; int count; word_array words; }; info_type get_words(); int count_vowels(info_type &i); void print_count(info_type i); int main() { info_type info_obj; system("cls"); info_obj = get_words(); info_obj.count = count_vowels(info_obj); print_count(info_obj); system("pause"); return 0; } info_type get_words() { info_type i; cout << "Enter four words" << endl; for (int j = 0; j < 4; ++j) { cout << "Type word number " << j+1 << ": "; cin >> i.words[j]; } i.vowels[0] = 'a'; i.vowels[1] = 'e'; i.vowels[2] = 'i'; i.vowels[3] = 'o'; i.vowels[4] = 'u'; return i; } void print_count(info_type i) { cout << "The four words are: " << endl; for (int j = 0; j < 4; ++j) cout << " " << i.words[j] << endl; cout << "The number of vowels is: " << i.count << endl; } int count_vowels(info_type &i) { int c = 0; for (int j = 0; j < 4; ++j) { for (int k = 0; k < 11 && i.words[j][k] != '\0'; ++k) { for ( int m = 0; m < 5; ++m) { if (i.words[j][k] == i.vowels[m]) ++c; } } } return c; }