This project will help you show your mastery of (C)strings.
A readability index (or legibility index) gives an idea of how complicated a piece of writing is to read. Often the score from such an index will indicate a school level to which the non-confused reader must belong. (Comics require a 5th grade education, tax laws require a law degree, etc.)
One such index was designed by Rudolf Flesch. To calculate the Flesch index of a piece of text, count the number of words in the text, the number of syllables in the text, and the number of sentences in the text. Guidelines:
A word is any space-delimited sequence of characters (even if it doesn't form a REAL word).
Adjacent vowels count as a single syllable while separate vowels in a word count as separate syllables. Exception: an 'e' at the end of a word doesn't count as an extra syllable. (ReaL is one syllable whereas ReGaL is two.)
In addition, any word has at least one syllable — even if the previous rules give a count of zero.
If these simplistic syllable counting rules leave you wanting for realism, see the options below...
A sentence is any sequence of characters ending in a period, colon, semicolon, question mark, or exclamation mark. (You can't use ispunct here since it would include things like ", (), and '.)
Once you have your totals, calculate the index by:
syllables words index = 206.835 - 84.6 * ------------ - 1.015 * ------------- words sentences
Round this value to the nearest whole number.
You can read more about readability indices in general at this site. More on the Flesch index itself can be found at this site (and there are links about others in the left margin menu).
Hint: How can you determine their text is done? One option is to have them enter the end-of-file character at the end (and check with the eof() method of cin's class). Otherwise you'll have to designate that the last line either begins or ends with a special symbol/character sequence.
Hint 2: You can test with files without the option below by using copy/paste or terminal redirection. For more on redirection (and its fancy cousin pipelining), see your textbook (p. 136).
This assignment is (Level 4).
Add (Level ?) to improve the syllable-finding code. For each syllable pattern/improvement you can add (Level 0.5) up to a maximum of (Level 3).
Add (Level 2) to allow the user to choose one of the three indices described at the general site given above.
Add (Level 2) to allow the user
the option of ignoring HTML tags in the text. (An HTML tag
has the form <tag>
. Assume they will not give
you text without such tags when choosing this option...)
Add (Level 3.5) to add correctness
checking for the user's HTML tags when the above option is
chosen. (This assumes that you've coded the HTML option above.)
Correctness can be assumed if each tag is followed by its closing
tag. For instance, a <title>
tag must be
followed by a </title>
tag. Be careful, however,
because standard usage says that some tags don't need endings
(li, p, tr, th, td) and some tags actually
DON'T have endings at all (hr, img, br). When in doubt, ask me or refer to
various tutorials
available on the web.
Add (Level 3) to allow the user to specify a file that the text is stored in (instead of reading it from the keyboard). Allow the user to choose the file's name. Make sure there are no errors during the opening of the file.
Note: This lab is adapted from ones given in C++/Java textbooks by Cay Horstmann. (In fact, it is exercise P3.19 in our current book.)