Write a C++ program that reads a file named words.txt and counts and prints the total number of words, the total number of VISIBLE characters (with white spaces), the total number of VISIBLE characters (without white spaces), the number of white spaces, and the number of lines in the file.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter8: I/o Streams And Data Files
Section: Chapter Questions
Problem 9PP: (Inventory) Create an ASCII file with the following data, or use the shipped.dat file available on...
icon
Related questions
Question
100%

C++

Assignment 2-B: Text
Analysis
Collapse context
Write a C++ program that reads a file named
words.txt and counts and prints the total number of
words, the total number of VISIBLE characters (with
white spaces), the total number of VISIBLE characters
(without white spaces), the number of white spaces,
and the number of lines in the file.
1/0
Program Input:
One text file called "words.txt"
Program Output:
Multiple lines showing the total number of
words, the total number of characters (with
white spaces), the total number of characters
(without white spaces), the number of white
spaces, and the number of lines in the file, THIS
PART HAS BEEN ALREADY WRITTEN FOR YOU.
Sample Testcase 0: (To try on your computer, it
won't be graded, there is another secret text).
Input:
Suppose words.txt has the following passage:
Arithmetic operators in C++ have the same
precedence as they do in
mathematics.
Multiplication and division have left associativity
(meaning that they
will be evaluated from left to right) and they
have higher precedence
than addition and subtraction, which also have
left associativity.
We can also force the precedence of expression
using parentheses. Just
the same way as you would do that in normal
mathematics.
Output:
Number of characters without spaces:
351
Number of characters with spaces:
409
Number of words:
65
Number of lines:
7
Spaces count:
58
Transcribed Image Text:Assignment 2-B: Text Analysis Collapse context Write a C++ program that reads a file named words.txt and counts and prints the total number of words, the total number of VISIBLE characters (with white spaces), the total number of VISIBLE characters (without white spaces), the number of white spaces, and the number of lines in the file. 1/0 Program Input: One text file called "words.txt" Program Output: Multiple lines showing the total number of words, the total number of characters (with white spaces), the total number of characters (without white spaces), the number of white spaces, and the number of lines in the file, THIS PART HAS BEEN ALREADY WRITTEN FOR YOU. Sample Testcase 0: (To try on your computer, it won't be graded, there is another secret text). Input: Suppose words.txt has the following passage: Arithmetic operators in C++ have the same precedence as they do in mathematics. Multiplication and division have left associativity (meaning that they will be evaluated from left to right) and they have higher precedence than addition and subtraction, which also have left associativity. We can also force the precedence of expression using parentheses. Just the same way as you would do that in normal mathematics. Output: Number of characters without spaces: 351 Number of characters with spaces: 409 Number of words: 65 Number of lines: 7 Spaces count: 58
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Function Arguments
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr