Write a program to accept a sentence which may be terminated by either '.', '?', or '!' only. Any other character may be ignored. The words ...

Write a program to accept a sentence which may be terminated by either '.', '?', or '!' only. Any other character may be ignored. The words may be separated by more than one blank space and are in UPPER CASE.

Perform the following tasks.

  1. Accept the sentence and reduce all the extra blank space between two words to a single blank space.
  2. Accept a word from the user which is part of the sentence along with its position number and delete the word and display the sentence.

Test your program with the sample data and some random data.

Example 1

INPUT: A     MORNING WALK IS A IS BLESSING FOR   THE  WHOLE DAY.
WORD TO BE DELETED: IS
WORD POSITION IN THE SENTENCE: 6

OUTPUT: A MORNING WALK IS A BLESSING FOR THE WHOLE DAY.

Example 2

INPUT:          AS YOU   SOW, SO     SO YOU REAP.
WORD TO BE DELETED:  SO
WORD POSITION IN THE SENTENCE:  4

OUTPUT: AS YOU SOW, SO YOU REAP.

Example 3

INPUT:     STUDY WELL  ##.
OUTPUT: INVALID OUTPUT.

Have something to say? Log in to comment on this post.

0 comments