C++ Dynamic Arrays We are writing a program that will count the frequency of wor
ID: 664648 • Letter: C
Question
C++ Dynamic Arrays
We are writing a program that will count the frequency of words in a text file. As we come across new words, store them in a dynamic array. If word already exists, increment the frequency of that word.
First create a temporary pointer that will hold new array. Set that equal to a new array that is a larger size. Then copy over each element from he old array into the new array. Delete the old Array. Set the pointer of the old array back to the new array.
Structures
Create class called Word which conatins:
-private string to store the word
-private integer to store the frequency of occurences of the word
-public function increment() to increment the counter
-public functions getWord() and getCount() to return those data elements
-Public functions setWord() and setCount() to set the values of those data elements.
-ince its an array, we'll need a default constructor. This will just set the word and frequency to default values.
-constructor that takes in the word. This will build the Word object to store that word internally and set its initial count (0 or 1 depending on how you choose to write it)
-Place class declaration in Word.h
Assignment
main function should be located in Main.cpp. Here, we need a dynamic array of Word objects. The array should start at 10 and double each time we resize. Each time we have to copy the data inside each object from the old array into the new one we do this.
function called resizeArray() that takes two parameters: reference to the array pointer and the size of the array. Since the function knows the array size, we know how big to make the new array. This function can either modify the size directly(pass by reference) or return the new size (which main() will have to capture)
**File input will consist of a file called "input.txt" that has lots of words. File oyput will consist of a file called "output.txt". The first line should say "WORDS FOUND: " along with a space and number of words found. The second line should say "Array's Max size: " followed by a space and the largest size array got to. After a blank each word should be listed, followed by a space, a hyphen, and a space along with frequency the word appeared.
Explanation / Answer
word.h
word.cpp
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.