Question: Write a C++ program that reads lines from a file until the end of file. The program should prompt the user for the file name

 Write a C++ program that reads lines from a file until

Write a C++ program 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, print the message "File could not be opened", followed by a space and the filename, and exit. The program should keep track of the number of lines, the number of non-blank lines, the number of words, and the number of integers read from the file. An integer is defined as a one or more digits, with an optional sign preceding the number, with no spaces separating the sign and the number. For example, 17234, -354, and +639 are integers, but 17.234, -+23 are not. A word is defined as a sequence of one or more non-whitespace characters separated by whitespace. At the end of file, the program should print out the total number of lines, the number of non-blank lines, the number of words, and the number of integers. Note that a line having only whitespace characters is a non-blank line as well. For example, given the following file, Write a C++ program 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, print the message "File could not be opened", followed by a space and the filename, and exit. The program should keep track of the number of lines, the number of non-blank lines, the number of words, and the number of integers read from the file. An integer is defined as a one or more digits, with an optional sign preceding the number, with no spaces separating the sign and the number. For example, 17234, -354, and +639 are integers, but 17.234, -+23 are not. A word is defined as a sequence of one or more non-whitespace characters separated by whitespace. At the end of file, the program should print out the total number of lines, the number of non-blank lines, the number of words, and the number of integers. Note that a line having only whitespace characters is a non-blank line as well. For example, given the following file

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!