Loops – String – Problem #2
IIT Kharagpur CS10001 / CS11001 Programming and Data Structures Lab Question Archive
Problem Statement
In this problem, you will scan a poem (along with its name and its poet) and do some computations as follows. Take a poem as input through the keyboard and store it in a string variable. Assume that the poem has at most 1000 characters in total. Use scanf("%[^#]s", P) for scanning the whole text at once in the character array P. The poem has the following form. ● Line 1 contains the name of the poem. ● Line 2 is blank (= a single newline character). ● Line 3 contains the poet’s name. ● Line 4 is blank. ● The poem starts from Line 5. ● There are no two consecutive blank lines anywhere. ● Stanzas are separated by exactly one blank line. ● After the last line of the poem, the character ‘#’ appears in a new line to mark the end. ● There is exactly one space or a punctuation mark or a newline after each word. ● There is no unnecessary space anywhere. ● A punctuation mark is immediately preceded by a word, and immediately followed by either a space or a newline. ● A hyphenated word is counted as a single word (ex: fast-paced, I-). A hyphen is not counted as a punctuation mark. ● Following are to be counted as punctuation marks: ‘.’, ‘,’, ‘:’, ‘;’, ‘!’, ‘?’. ● A word with apostrophe is counted as a single word (ex: we’ve, there’s). Print the name of the poem and its poet [2 marks], and the number of lines [2 marks], words [2 marks], stanzas [2 marks], and punctuation marks [2 marks] in the main body of poem.