Question: Write a C++ program that reads from a file name specified in the command line as an argument, and ignoresany extra command line arguments that
Write a C++ program that reads from a file name specified in the command line as an argument, and ignoresany extra command line arguments that are provided after the file name.However, if no file name is provided, the program should use the standard input instead of a file.If the file cannot be opened, print on a new line "File cannotbe opened: ",followed the filename, and exit.The program should read from the file character by character until the end of file.If the input file is empty, print out themessage "File is empty."on anewline and then exit.The program should count the number of lines, number of words, number of characters, number of digit characters(0-9), and the number of alphabetic charactersseen in the file.
For example, with an input file of the following contents:
3456 Georgre 10.25
1234 smith 4.5
4321 staci 12.75
278 sandra 25.35
The displayed output is as shown below:
LINES: 4
WORDS: 12
CHARS: 75
DIGITS: 29
LETTERS: 21
Hints:
1. .Use functionssuch as: isdigit(), isalpha(),and isspace().
2.You can use get() method for reading from the input.
There are 4test cases. Case 2 is for an empty file, myfile2. Note that case 3 is for checking you against no file is provided in the command line and your program switches to read from the stdin. The input for case 3 is from myfile3 on vocareum.Case4reads from a provided file name in the command line, myfile4.
myfile 1 is an incorrect file which should give output of file cannot be opened
myfile 2 is an empty file
myfile 3 is an example given above
and myfile 4 contains: An International Standard Book Number (ISBN) is a code of 10 characters, referred to as ISBN-10, separated by dashes such as 0-7637-0798-8. An ISBN-10 consists of four parts: a group code, a publisher code, a code that uniquely identifies the book among those published by a particular publisher, and a check character. The check character is used to validate an ISBN. For the ISBN 0-7637-0798-8, the group code is 0, which identifies the book as one from an English-speaking country. The publisher code 7637 is for "Jones and Bartlett Publishers".
myfile 4 should give a output of
LINES: 5 WORDS: 90 CHARS: 553 DIGITS: 31 LETTERS: 402
(The input files are in bold myfile 1 myfile 2 myfile 3 mufile 4)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
