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

write a function with this prototype: string HighestCountWordlnFile(const char *

ID: 3535536 • Letter: W

Question

write a function with this prototype: string HighestCountWordlnFile(const char * filename); This function is meant to process a file containing lines that specify words and their "counts", and ending with the word "END" on a line by itself. For instance: cat 34 dog 8 apple 12 pizza 7 END The function should do the following, but throw an exception if anything goes wrong, including information about what the error was. Open the given file (note: the filename may or may not be valid) Read info from each line (assume the format is correct) Determine which word has the highest count, returning that word In main (), add code, using try / catch blocks, that asks the user for a filename, then calls the above function and reports its result. If an error occurs, instead of reporting the result, print an error message. Create a templatized class called Box. A Box is simply a container of items. It always starts empty, so it will only have a single default (no-arguments) constructor. Aside from the constructor, it needs to have these methods: Insert Inserts the given item (of type T) into the box. Size Returns the total number of items in the box. GetFirst Returns a copy of the first item inserted. GetLast Returns a copy of the most recent item inserted. GetMax Returns a copy of the maximum value item among the items in the box.

Explanation / Answer

#include #include int main() { map counts; //open file stream ... //LOOP (through file) { //read a word from the file counts[word]++; //increase that word's count } int maxWord; ... //LOOP (through the map "counts") { if( counts[word] > counts[maxWord] ) maxWord = word; } ... }