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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education