Question: ( 1 ) Write the function containsWord ( 5 pt ) ( a ) Place a prototype above main ( ) under the comment /

(1) Write the function containsWord (5 pt)
(a) Place a prototype above main() under the comment
// Add the remaining three function prototypes here
int containsWord(vector words, string word);
(b) Write a definition for this function below main() under the appropriate comment
(c) This function should return the index of where word is located in the vector words.
If word is not in the vector words, the function should return -1.
(d) Test 1 will test the function. You can submit after writing the function to see if it works correctly. You do not need to finish main first.
(2) Write the function processInputFile (5 pt)
(a) Place a prototype above main() under the comment
// Add the remaining three function prototypes here
void processInputFile(vector& words, vector& wordCount, ifstream& file);
(b) Write a definition for this function below main() under the appropriate comment
(c) This function should read through the already opened file one word at a time.
i) Each word read in should be pre-processed. For each word remove the punctuation from the word and make all the alphabetic characters lower case. You have been provided with two functions to help you with this: string removePunctuation(string word) and string wordToLowerCase(string word). See the comment headers for these functions to determine how to use them.
ii) For each word read in, the function should check if it is in the words vector
iii) If it is, the element at the same index in the wordCount vector should be incremented by 1
iv) If the word is not in the words vector, it should be pushed onto the words vector and 1 should be pushed on to the wordCount vector
(d) Hint: Make sure you user your containsWordremovePunctuation and wordToLowerCase
(e) Test 2 will test the function. You can submit after writing the function to see if it works correctly. You do not need to finish main first.
(3) Write the function writeOutputFile
(a) Place a prototype above main() under the comment
// Add the remaining three function prototypes here
void writeOutputFile(vector words, vector wordCount, ofstream& file);
(b) Write a definition for this function below main() under the appropriate comment
(c) This function should write word in the words vector along with the corresponding value from the wordCount vector separated by a space to the already opened file. Each word with it's count should be written on a separate line. The last line of the file should be the total number of words in the words vector.
Example output to the file:
the 102
three 3
little 43
pigs 5...
happily 1
ever 1
Total words: 260
(d) This function will be tested with step 4
(4) Finish writing the function main()(10 pt)
The main() function has several lines of code for you todo. Write the code to complete each TODO in main()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!