Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 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+639areintegers,but 17.234, -+23 are not. A word is defined as a sequence of one or more non-whitespace characters separated by whites pace. 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 white space characters is a non-blank line as well.

For example, given the following file, Note: There are 9 lines in this input file. the generated output results after reading the file contents are as follows:Note: The screen pointer is at a new line after displaying the results.You have to apply the same format in order to have exact match.Total Number of Lines: 9Number of non-blank lines: 5Number of Words: 10Number of Integers: 0staci jamesGeorge -+-+123smith beth 12.56-4.75

image text in transcribed

All meger is demed as a one or more ugnis, win an optional sign preceomg me number, Win To 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, staci james George -+123 12.56 smith beth -4.75 Note: There are 9 lines in this input file. the generated output results after reading the file contents are as follows: Total Number of Lines: 9 Number of non-blank lines: 5 Number of Words: 10 Number of Integers: 0 Note: The screen pointer is at a new line after displaying the results. You have to apply the same format in order to have exact match. All meger is demed as a one or more ugnis, win an optional sign preceomg me number, Win To 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, staci james George -+123 12.56 smith beth -4.75 Note: There are 9 lines in this input file. the generated output results after reading the file contents are as follows: Total Number of Lines: 9 Number of non-blank lines: 5 Number of Words: 10 Number of Integers: 0 Note: The screen pointer is at a new line after displaying the results. You have to apply the same format in order to have exact match

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft SQL Server 2012 Unleashed

Authors: Ray Rankins, Paul Bertucci

1st Edition

0133408507, 9780133408508

More Books

Students also viewed these Databases questions