Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Create a class called Words. In Words, 1 . Create two private int variables length, word _ count. 2 . Create a private string pointer
Create a class called Words.
In Words,
Create two private int variables length, wordcount. Create a private string pointer called list. This variable will be used to hold a dynamic string array.
Create an overloaded constructor to set the value of length
In the overloaded constructor, call countmatches and assign its return value to wordcount. Create a dynamic string array, of size wordcount this string array will be assigned to the list pointer. Lastly, call the load function.
Create a private function, int countmatches This function will open the file enabletxt and count how many words from this file are of length. The return value of this function is the number of words found that match this length.
Create a private function, void load This function will open the file enabletxt This time, while reading each word, identify which words are of length, and fill up the list string array with each matching word.
Create a public function int reloadint len This function will:
Check if list is not NULL. If so delete the list array pointer
Write the same code here as you have in your overloaded constructor.
This function will return wordcount.
Since a constructor is only called once when an object is created, it is good for doing initialization things. However, in certains situations such as this, we want the ability to reinitialize things in the class at some point after initialization, but we can't recall the constructor. The reload function allows us to reinitialize the class.
Create a public function string pickrandom This function will check that wordcount contains a number greater than zero. If so return a string out of the list array. Otherwise, return an empty string. HINT: rand will generate a random number between and rand will generate a random number between and Think about how you can use this phrase to randomly select an item out of the list array.
Create a public function bool isvalidstring word This function will return true if word is found in the list array. Otherwise, it returns false. This function will be used to validate that text passed in the parameter is a valid word or not.
Create a global, nonclass function int wordCistancestring word string word This function will compare two words, word and word If the lengths of word and word are different, return
Otherwise, the function will return how many letters are different between the two words for each letter in equivalent positions. For example, cat and cot should return one letter is
example, cat and cot should return one letter is different because and are the the same, but A and are different. cat and dog should return letters are different because all letters are different. HINT. Remember that variable.length will return the number of characters in variable where variable is any string variable.
For this milestone, use main to instantiate an instance of Words. The sample main instantiates a Words object with a value of This means only letter words will be selected from the file and added to your Words object.
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