Question: Write a C++ program that reads words in input file and checks if a substitute word exists in another file. If a substitute word exists,

Write a C++ program that reads words in input file and checks if a substitute word exists in another file. If a substitute word exists, the substitute word is printed. The program also counts how many times substitution occurred. If a word has multiple substitutes only the last substitute is considered.

The program takes two command line arguments: The first is the name of the file containing substitutions, and the second is the name of the file containing words. The program should process the substitution file and then should read the file containing words, apply any replacements indicated and print the result.

How to decide if an input word matches a word in substitution? Here are the rules:

Any leading and trailing punctuation is ignored. Any case difference is ignored.

If the first letter of the word is capital then even substituted word should be capitalized.

Also, all whitespaces should be printed as is.

If two filenames are not provided, print TWO FILENAMES REQUIRED and stop. If file cannot be read print BAD FILENAME and stop

Example,

Words in substitution:

Hi bye

coming going

home school

Input file we process

Hi!!! I'm !!!cOmInG to meet you at Home now.

The output willl be :-

Bye!!! I'm !!!going to meet you at School now.

Number of changes: 3

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!