Answered step by step
Verified Expert Solution
Question
1 Approved Answer
in c++ please HW10: File Analysis In this assignment you're to write a program that analyzes the contents of an external file called dracula.txt. (It
in c++ please
HW10: File Analysis In this assignment you're to write a program that analyzes the contents of an external file called dracula.txt. (It is an eBook titled Dracula by Bram Stoker.) The program you write will open dracula.txt, look at its contents and determine the number of uppercase, lowercase, digit, punctuation, whitespace, lines, periods and question mark characters contained in the file so that the caller can report the results to stdout. Additionally, the function will return the total number of characters read to the caller. An example of the run is listed towards the end. I have already created for you the directory In order to derive all these statistics, you'll have to write a function to do the work. The name of the function is ReadFile and here's what a sample function call looks like: totalChars = ReadFile(inFile, totalUpper, totalloner, totalDigits, totalPunct, totalSpace, totalLines, totalPeriods, totalQuestion); Trying creating a structure chart like we did in class to understand how the program will work. The ReadFile function is going to examine every single character in the file, including whitespace characters (which means you'll have to use character I/O, which means you'll want to use the .get() .put) and .eof() functions, which means you might want to look at p.340 and p.355 in your textbook). As characters are read from the input stream, you'll need to recognize whether they're uppercase, lowercase, digits, punctuation characters, whitespace characters (e.g., blank, tab, newline, etc.), newlines, periods, or question marks. You could certainly write the code to do this yourself (it's easy to do), but the good news is that you don't have to! Recall that the standard libraries already have some character testing functions for you to use, like isdigit, isupper, islower, isspace, etc. Look on p.1042 in your textbook, these functions are extremely easy to use (don't forget to t#include the header file cctype). It would be worth your while to to use it. Now the key thing is how will you figure out if the character is a newline, period, or a question mark? I suggest you look closely at the character testing functions in the standard library and see how you can use them to your advantage. To help you get started, I went ahead and created a HW10 subdirectory for you and put starter kit in there called FileAnalysis.tar.gz. This is a compressed archive file, much like a zip file, it contains files that need to be extracted. To extract the file(s), use this command: tar xvzf FileAnalysis.tar.gz This will extract the file(s) contained within the archive into the present working directory. You should then find a text file called dracula to use in your analysis. NOTE: You only need to extract the files once! If you extract the text file, write something in it, and then extract again at a later point in time, the original text file in the archive will be extracted and overwrite any changes that you've already written! You can leave your code in a file called file_analysis.cpp in the Hw10 subdirectory, and we'll review the program together at our next class session. Sample Run of FileAnalysis.exe File "dracula.txt" contains the following: Uppercase letters: 20592 Lowercase letters: 638144 Digits: 729 Punctuation characters: 33901 Whitespace characters: 189783 Lines: 15973 Total Periods: 8505 Total Question Marks: Total characters read: 883168 492Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started