Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

HW10: File Analysis In this assignment you're to write a program that analyzes the contents of an external file calleddracula.txt. (It is an eBook titled

HW10: File Analysis

In this assignment you're to write a program that analyzes the contents of an external file calleddracula.txt. (It is an eBook titled Dracula by Bram Stoker.) The program you write will opendracula.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 isReadFileand here's what a sample function call looks like:

totalChars = ReadFile(inFile, totalUpper, totalLower, totalDigits, totalPunct, totalSpace, totalLines, totalPeriods, totalQuestion);

Trying creating a structure chart like we did in class to understand how the program will work.

TheReadFilefunction is going to examine every single character in the file, including whitespace characters (which means you'll have to usecharacter I/O, which means you'll want to use the.get(),.put()and.eof()functions, which means you might want to look atp.340andp.355in 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, likeisdigit,isupper,islower,isspace, etc. Look onp.1042in your textbook, these functions are extremely easy to use (don't forget to #include the header filecctype). It would be worth your while to write some quick code to experiment with these functions so you know what's available and how 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 aHW10subdirectory for you and put starter kit in there calledFileAnalysis.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 calledfile_analysis.cppin theHW10subdirectory, 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: 189703 Lines: 15973 Total Periods: 8505 Total Question Marks: 492 Total characters read: 883160

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

Step: 3

blur-text-image

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

More Books

Students also viewed these Databases questions

Question

Explain how the different reinforcement schedules affect behavior.

Answered: 1 week ago

Question

2. What are the different types of networks?

Answered: 1 week ago