Answered step by step
Verified Expert Solution
Link Copied!

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,
1. Create two private int variables length, word_count. 2. Create a private string pointer called list. This variable will be used to hold a dynamic string array.
3. Create an overloaded constructor to set the value of length
4. In the overloaded constructor, call count_matches() and assign its return value to word_count. Create a dynamic string array, of size word_count - this string array will be assigned to the list pointer. Lastly, call the load() function.
5. Create a private function, int count_matches(). This function will open the file enable1.txt, 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.
6. Create a private function, void load(). This function will open the file enable1.txt. This time, while reading each word, identify which words are of length, and fill up the list string array with each matching word.
7. Create a public function int reload(int len). This function will:
1. Check if list is not NULL. If so, delete the list array pointer
2. Write the same code here as you have in your overloaded constructor.
3. This function will return word_count.
4. 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 re-initialize things in the class at some point after initialization, but we can't re-call the constructor. The reload() function allows us to re-initialize the class.
8. Create a public function string pick_random(). This function will check that word_count contains a number greater than zero. If so, return a string out of the list array. Otherwise, return an empty string. HINT: rand()%10 will generate a random number between 0 and 9,rand()%100 will generate a random number between 0 and 99. Think about how you can use this phrase to randomly select an item out of the list array.
9. Create a public function bool is_valid(string 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.
3. Create a global, non-class function int word_Cistance(string word1, string word2). This function will compare two words, word1 and word2. If the lengths of word 1 and word 2 are different, return
-1. 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 1(one letter is
example, cat and cot should return 1(one letter is different) because C and T are the the same, but A and O are different. cat and dog should return 3(3 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.
4. For this milestone, use main to instantiate an instance of Words. The sample main instantiates a Words object with a value of 5. This means only 5- 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning ASP.NET 4.5 Databases

Authors: Sandeep Chanda, Damien Foggon

3rd Edition

1430243805, 978-1430243809

More Books

Students also viewed these Databases questions