a file of text, output the number of Vowels, Consonants, Digits and Special characters

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
icon
Related questions
Question
Given a file of text, output the number of Vowels, Consonants, Digits and Special characters in each line of the file.
Definitions:
A consonant is any alphabetic character that's not a vowel
A special character is any character that is neither alphabetic nor a digit.
Ex: If the input file is:
●
data2.txt
the output is:
Character analysis of each line from file data2.txt
Line
Why did the duck cross the road?
To prove he wasn't chicken!
Why did the cow cross the road?
●
Character Count.
V: 7
V: 7
V: 7
V: 8
/**
C: 18
D: 0
C: 14 D: 0
To get to the udder side!
Note: All input files on which your program will be tested can be downloaded below.
Step 0: Work on this project using Clion.
@param
@param
@param
C: 17 D: 0
Step 2: Create a function following the specification:
C: 11
S: 7
D: 0
S: 6
• The first step is to create a new project (we will call it lab04). Follow these instructions.
O Click New Project on the Welcome screen or select File | New Project from the main menu.
O
In the New Project window that opens, select C++ Executable in the left-hand pane. Set the project name (lab04)
and the language standard (C++ 14 or C++17).
S: 7
• You are now ready to write your code on main.cpp
Copy your code for this problem from lab03 and ensure you can compile and run it!
Ask the instructor if you are having trouble getting your lab03 code from running correctly in Clion.
S: 6
• Important: If you didn't get your lab 03 code working for this problem, do not hesitate to take help from peers or
instructor and ensure you have a working lab 03 code.
Step 1: Modify the function printReport so that it takes an additional argument (string for the line that is being analyzed)
and prints the character counts in the following format: line (left-justified to 35 characters) followed by the abbreviation for
each kind of character count. Each abbreviation is followed by a space (example: "V: ") followed by the count, which is
left-justified to 4 characters.
• Modify the call to printReport in the main () function according to the new definition of printReport.
Run your code to make sure it works and gives the correct output for a test string.
*Sets the counts for different kinds of characters in a string
userText the input line that is being analyzed
vowelCount the number of vowels in userText
consoCount the number of consonants in userText
* @param digitCount the number of digits in userText
@param specialCount the number of special characters in userText
@pre
vowelCount, consoCount, digitCount and specialCount are zero
@post vowelCount, consoCount, digitCount and specialCount are populated with the
respective counts.
**/
void getCount (string userText, int& vowelCount, int& consoCount, int& digitCount, int &
special Count)
Refactor your main () so that it only calls get Count and printReport by passing it appropriate arguments. At this
stage, your main() shouldn't be more than 4-5 lines of code! Run your code to make sure it works and gives the correct
output for a test string.
Transcribed Image Text:Given a file of text, output the number of Vowels, Consonants, Digits and Special characters in each line of the file. Definitions: A consonant is any alphabetic character that's not a vowel A special character is any character that is neither alphabetic nor a digit. Ex: If the input file is: ● data2.txt the output is: Character analysis of each line from file data2.txt Line Why did the duck cross the road? To prove he wasn't chicken! Why did the cow cross the road? ● Character Count. V: 7 V: 7 V: 7 V: 8 /** C: 18 D: 0 C: 14 D: 0 To get to the udder side! Note: All input files on which your program will be tested can be downloaded below. Step 0: Work on this project using Clion. @param @param @param C: 17 D: 0 Step 2: Create a function following the specification: C: 11 S: 7 D: 0 S: 6 • The first step is to create a new project (we will call it lab04). Follow these instructions. O Click New Project on the Welcome screen or select File | New Project from the main menu. O In the New Project window that opens, select C++ Executable in the left-hand pane. Set the project name (lab04) and the language standard (C++ 14 or C++17). S: 7 • You are now ready to write your code on main.cpp Copy your code for this problem from lab03 and ensure you can compile and run it! Ask the instructor if you are having trouble getting your lab03 code from running correctly in Clion. S: 6 • Important: If you didn't get your lab 03 code working for this problem, do not hesitate to take help from peers or instructor and ensure you have a working lab 03 code. Step 1: Modify the function printReport so that it takes an additional argument (string for the line that is being analyzed) and prints the character counts in the following format: line (left-justified to 35 characters) followed by the abbreviation for each kind of character count. Each abbreviation is followed by a space (example: "V: ") followed by the count, which is left-justified to 4 characters. • Modify the call to printReport in the main () function according to the new definition of printReport. Run your code to make sure it works and gives the correct output for a test string. *Sets the counts for different kinds of characters in a string userText the input line that is being analyzed vowelCount the number of vowels in userText consoCount the number of consonants in userText * @param digitCount the number of digits in userText @param specialCount the number of special characters in userText @pre vowelCount, consoCount, digitCount and specialCount are zero @post vowelCount, consoCount, digitCount and specialCount are populated with the respective counts. **/ void getCount (string userText, int& vowelCount, int& consoCount, int& digitCount, int & special Count) Refactor your main () so that it only calls get Count and printReport by passing it appropriate arguments. At this stage, your main() shouldn't be more than 4-5 lines of code! Run your code to make sure it works and gives the correct output for a test string.
Step 3: Reading from an input file
Your program will now take its input from this file instead of from the user. Here's what you want to do:
• Remove the call to getUserInput. You can also remove its definition and prototype if you like.
Within main, prompt the user for a file and open that file to read lines. If the file doesn't exist, display a warning
message and exit the program.
Display a summary statement in the following format such that the string "Line" is left-justified to 35 characters and
the string "Character Count" is left-justified to 20 characters.
·
Character analysis of each line from file datal.txt
Line
·
Character Count
Process each line in the file to get and print their character count. You should be able to now see the benefit of writing
functions get Count and printReport!
• To test your code on CLion, place the input files in the directory cmake-build-debug under the project directory lab04.
All the input files can be downloaded from below.
Step 4: Writing onto a file
• So far your program uses cout to write onto the standard output. Now you will write another function writeReport
that has the same parameters as printReport with an additional parameter that is a reference to ofstream (it is a
pass-by-reference parameter). Both functions have the exact functionality except that while printReport uses cout,
writeReport will use the parameter corresponding to the ofstream.
• In main (), open an output file stream to write to file data analysis.txt. Then just after the call to printReport, call
the writeReport function by passing in the parameters corresponding to character counts and the parameter
corresponding to the output file stream.
• Don't forget to close the output file stream at the end of the function.
• Ensure that by running the code, not only do you get output on the console but also in a file data analysis.txt, which is
generated in the cmake-build-debug under the project directory lab04. Note that the output file only contains
information related to character counts and not the summary statements provided in Step 3.
Transcribed Image Text:Step 3: Reading from an input file Your program will now take its input from this file instead of from the user. Here's what you want to do: • Remove the call to getUserInput. You can also remove its definition and prototype if you like. Within main, prompt the user for a file and open that file to read lines. If the file doesn't exist, display a warning message and exit the program. Display a summary statement in the following format such that the string "Line" is left-justified to 35 characters and the string "Character Count" is left-justified to 20 characters. · Character analysis of each line from file datal.txt Line · Character Count Process each line in the file to get and print their character count. You should be able to now see the benefit of writing functions get Count and printReport! • To test your code on CLion, place the input files in the directory cmake-build-debug under the project directory lab04. All the input files can be downloaded from below. Step 4: Writing onto a file • So far your program uses cout to write onto the standard output. Now you will write another function writeReport that has the same parameters as printReport with an additional parameter that is a reference to ofstream (it is a pass-by-reference parameter). Both functions have the exact functionality except that while printReport uses cout, writeReport will use the parameter corresponding to the ofstream. • In main (), open an output file stream to write to file data analysis.txt. Then just after the call to printReport, call the writeReport function by passing in the parameters corresponding to character counts and the parameter corresponding to the output file stream. • Don't forget to close the output file stream at the end of the function. • Ensure that by running the code, not only do you get output on the console but also in a file data analysis.txt, which is generated in the cmake-build-debug under the project directory lab04. Note that the output file only contains information related to character counts and not the summary statements provided in Step 3.
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Fundamentals of Computer System
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
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