Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C++ please rhymes.cpp Write a program that finds rhyming words in a poem! Specifically, the program reads an input file, line by line, and

In C++ please

image text in transcribedimage text in transcribedimage text in transcribed

rhymes.cpp Write a program that finds rhyming words in a poem! Specifically, the program reads an input file, line by line, and extracts the last word in each line. It then compares this last word with the last word from the line after it. If it finds that the 2 words rhyme" (which is simply defined as the 2 words that are being compared share the same 2 last letters), then it prints out these two words to standard output (i.e. the display). It also displays the number of lines in the poem along with a metric called the rhyme-line density which is the number of rhymes found divided by the number of lines in the poem. But first, the words must be cleaned up of any non-alphabetical characters (usually this means punctuation, since many poems have their last lines often end with a comma, a semicolon, a question-mark, etc.) So, if the last word on a line has punctuation marks on it, e.g. "hello?!, it becomes "hello. Or if the last word is "don't, it becomes "dont. Finally, the program has to state how many rhyming pairs it found, or if it did not find any at all. Requirements 1. Your program should take file name as an input from the user-it does need to check if the input file name is valid. a. If it does not exist, the program must output (via cerr) an error message: Input file opening failed. and then exit with return code 1. 2. Your program should define at least 3 functions that only do last-word extraction, word-end comparisons, and word clean-up. a. You can have additional functions, if you like. b. If your program does not have these 3 functions, you will not get credit for this part of the assignment, even if your program passes the Gradescope autograder. 3. When displaying the rhyme-line metric, only show 2 places after the decimal point. a. If there are no rhymes found, you do not need to show the metric (see examples below). 4. Be sure to utilize only techniques we've covered in lecture. Do not use "special" arrays or pointers, do not use vectors, do not use built-in sorting functions, etc. You will get zero points if you do. As an example, assume there is a text file called My Poem. txt, which contains this: "I cannot go to school today," Said little Peggy Ann Mckay. "I cannot go to school and play! I have the measles and the mumps, A gash, a rash and purple bumps. My mouth is wet, my throat is dry, I'm going blind in my right eye. My tonsils are as big as rocks, I've counted sixteen chicken pox" The program would run as follows. Enter file name: My Poem. txt today and Mckay McKay and play mumps and bumps There are 3 pairs of rhyming words. There are 9 lines in this poem, so the rhyme-line density is: 0.33 Note that, in this poem, "dry" and "eye were not shown, nor were rocks and pox. This is because they do not meet the program's criteria of a rhyme. Also note the last line of the output says how many pairs of rhyming words there are. Please make the word pair" singular if only 1 pair of rhyming words is found and use the plural pairs if you found more than 1 rhyming pairs. So, for example, with a file called Simple.txt: I do not like green eggs and ham, I do not like them Sam I am. The program would run as follows: Enter file name: Simple.txt ham and am There is 1 pair of rhyming words. There are 2 lines in this poem, so the rhyme-line density is: 0.50 Finally, consider this example file called No.txt: No means no, it always means no If I say it once it means A thousand times no! The program would run as follows: Enter file name: No.txt No rhymes found. There are 3 lines in this poem. Note that no rhymes were found because the program only looks at adjacent lines. Also, note that the case of no rhymes found will not display the rhyme-line metric. You can safely assume that: 1. Text files may be empty (have no line), and may contain blank lines, but lines that are not blank will have at least 2 words per line. 2. The last words on a line contain at least 2 characters. 3. The rhyme comparison is case-sensitive. You will only be submitting the C++ file, rhymes.cpp (there is no skeleton or starter file). We will test it with several different rhyme files

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2018 Dublin Ireland September 10 14 2018 Proceedings Part 1 Lnai 11051

Authors: Michele Berlingerio ,Francesco Bonchi ,Thomas Gartner ,Neil Hurley ,Georgiana Ifrim

1st Edition

3030109240, 978-3030109240

More Books

Students also viewed these Databases questions

Question

=+How might these stem from country and regional cultures?

Answered: 1 week ago