Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program using C++ that will read in a file, recognize individual words i

ID: 3622345 • Letter: W

Question

Write a program using C++ that will read in a file, recognize individual words in the file, and count the number of times the word appears in the file. The comparison will be case sensitive (i.e., “the” and “The” will be considered as different words).



You will create a TopicH structure that will have three members:

· a pointer to string which is a word from the file;

· a count of the number of times that word was found in the file;

· the length of that word.



string refers to the C++ string class. C-strings cannot be used.



The program will:

1. Create a vector of TopicH structures. You do not know how many elements will be required.

2. Read a word from the input file, TopicHIn.txt.

3. Determine if the word read is already in the vector.

4. a. If the word is already in the vector, increase the count for that word by 1.
b. If the word is not already in the vector, add it in

5. Display the vector contents.



At a minimum, the following functions must be used:



· readInput – Reads the words in the file into the vector. This function calls the insertIntoVector function. The function return is a return code. The return code is an enumerated data type which consists of 3 possible values: success, the file cannot be found, or there was an error reading the file. main should produce a different message for each unsuccessful return code and then terminate the program. This function should also determine the length of the longest word and pass that value back to main.

· insertIntoVector – This function does steps 3 and 4 above. All accesses of individual vector elements will be done through the vector at function. Called from readInput.

· displayVector – This function does step 5. Notice the output formatting. The field width for the word (see Chapter 3 in the text) should be the length of the longest word (which was found in readInput) plus 5. All accesses of individual vector elements will be done using the [] operator. Called from main.

· deallocateDynamicMemory – This function deallocates the dynamic memory associated with the TopicH structure. Called from main.



Whenever necessary memory, such as the pointer to string in the TopicH structure, should be dynamically allocated, i.e., allocated using new. All the Topic G Readings discuss dynamic memory allocation and Section 9.8 of the text introduces the concept.



The program file should be named TopicH.cpp. You can run TopicH.exe to see what the program output is.

Explanation / Answer


Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote