Question: Write a C++program that reads from a file name specified in the command line as an argument. However, if no file name is provided, the

 Write a C++program that reads from a file name specified inthe command line as an argument. However, if no file name is

Write a C++program that reads from a file name specified in the command line as an argument. However, if no file name is provided, the program should print "No file is found", and exit. If the file cannot be opened, print "File could not be opened", followed by a space and the file name, and exit. The program should count the number of times each word is seen in the input file. Reading from the input file continues until the end of file. A word is defined as a number of non-whitespace characters separated by whitespace. After all input has been processed, - Print each word that was seen the largest number of times on a line by itself and the number of times it was seen in the file. Words should be printed in alphabetical order. - Print each word read from the file and the number of times it was seen. Words should be printed in alphabetical order. For example, with an input file of the following contents: 3456 george 10.25 1234 smith 4.5 4321 staci 10.25 278 staci 10.25 The output is as shown below: Words of Largest number of occurrences: 10.25:3 Iist of words seen in the file and their number of occurrences: 10.25:3 1234: 1 The output is as shown below: Words of Largest number of occurrences: 10.25:3 List of words seen in the file and their number of occurrences: 10.25:3 1234:1 278:1 3456:1 4.5:1 4321: 1 george: 1 smith: 1 staci: 2

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 Databases Questions!