Write a C++ program that acts like a simple counting tool for collecting information from textual files of documents prepared for a simple scripting language interpreter. An input file for the simple scripting interpreter includes two types of data, commented lines and command lines. A commented line is recognized by the ‘%’ at the beginning of the line, and would be skipped by the script interpreter. A valid command line is a one which starts with one of the four possible commands. Only one valid command per line is considered, followed by possibly one or more arguments. The simple scripting language includes the commands “run” for executing file(s), “print” for printing one or more files, and “copy” for copying a file to another file, and “delete” to delete one or more files. The simple counting tool should collect data about the total number of lines read from the file, the number of commented lines, the number of valid command lines, the number of invalid command lines, and the number of “run”, “print”, “copy” and “delete” commands. Note, a line should be skipped if it is empty or consists of white space characters only. In that case, the line is not counted as either valid or invalid command line.
Write a C++ program for the simple counting tool that reads lines from a file until the end of file. The program should prompt the user for the file name to read from. The program should open the file for reading, and if the file cannot be opened, it should print the message "File cannot be opened ", followed by the filename, and exit. The program should consider the first word of a non-commented line as a command. If no word is found, or a word is not recognized as one of the four commands, an error message should be printed out for an invalid command line, followed by the its line number. See the example in the slides for more details.
After reading the contents of the input file, the program should print out the total number of lines, the number of commented lines, the number of command lines, the number of invalid command lines, and the number of “run”, “print”, “copy” and “delete” commands.