Question
HW #8A.- (20 pts) C++ program to read a text file containing a list of vocabulary words in alphabetical order. Your instructor will supply the
HW #8A.- (20 pts) C++ program to read a text file containing a list of vocabulary words in alphabetical order. Your instructor will supply the word (text) file. The program should access the word list file and compute and display the following statistics: Hint: do not use functions in the solution. Calculate and display the following statistics... a) total number of words are in the file (over 100,000 ) b) # words begin with the letter 't' c) # of words that have no vowels (a, e, i, o, u, y) Note: include 'y' d) average length of the words (use length() command) e) minimum length of the words (shortest word length; display length and the shortest word) f) maximum length of the words (longest word length; display length and the longest word) h) # of words with all vowels (only use vowels; a,e,i,o,u). May contain one or more of same vowels. i) # of words that begin with "sh" Pseudocode Solution (you must convert this into valid C++ code and test) //declare and initialize all counters while (not end of file) //loop once for each word in file; stop loop when all words have been read { Read a word from file and store in string variable word //part (a) total number of words numWords++; // part (b) # words begin with the letter 't' if word[0] is equal to letter 't' then numWordsT++; // part (c) words with no vowels // first count number of vowels in each word (include y) numVowels = 0; for (int k = 0; k < word.length(); k++) { if (word[k] == 'a' or word[k] == 'e' or word[k] == 'i' or word[k] == 'o' or word[k] == 'u' or word[k] == 'y') { numvowels++; } if (numVowels == 0) then numWordsNoVowels++; // part (d) average length of words sum = sum + word.length();
// part (e) minimum word length and min word // initialize min to be an integer and set to 100 (before while loop) // declare minWord to be a string if ( word.length() < min) { min = word.length(); minWord = word; } // part (f) maximum word length and max word // initialize max to be an integer and set to 0 (before while loop) // declare maxWord to be a string if ( word.length() > max) { max = word.length(); maxWord = word; } // part (h) # of words with all vowels (only vowels; a,e,i,o,u). May contain one or more vowels. // first count number of vowels in the word (do not include letter 'y' numVowels = 0; for (int k = 0; k < word.length(); k++) { if (word[k] == 'a' or word[k] == 'e' or word[k] == 'i' or word[k] == 'o' or word[k] == 'u') { numvowels++; } if (numVowels == word.length()) then numWordsAllVowels++; // part (i) # of words that begin with "sh" // there are 2 ways to do... if (word[0] == 's' and word[1] == 'h') then numwordsSh++; //or if (word.substring(first 2 characters) == "sh") then numWordsSh++; } // end of while loop double average = (double)sum/numWords; //calculate average length of words outside while loop //Display all counters and statistics (see problem definition for list)
Give me your email to send word file
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started