Question
You will write a C++ program to search a particular word in a file and replace every occurrence of that word by another word. The
You will write a C++ program to search a particular word in a file and replace every occurrence of that word by another word. The search and replace should work in a casesensitive manner. Your program should have the following functions in addition to main. You may not change the prototypes of these functions. The length function should accept a filename (an array of characters) as an argument and return an integer that states how large the file is, in number of characters. This will be required for your program to know how much space needs to be allocated for the character array. One way of implementing this would be to open the file, and read all of the characters of the file, keeping a counter. The read function should accept the filename (an array of characters) and another array of characters for storing the file content. It should open the file and read the file content into the second array. The replace function should accept an array of characters for holding the original file content, another array of characters for holding the modified file content, the "search word", the "replace word", and the number of characters in the original file. This function should be responsible for finding each occurrence of the "search word" and replacing that with the "replace word". This function should return the number of characters in the modified file. The write function should accept an array of characters holding the file content and the number of characters in the file. It should print the file content to the console. The main function should be responsible for using the other functions to perform the overall task. The two arrays of characters should be created dynamically, inside main, based on the number of characters in the original file. You may declare the second array (storing the modified content) twice as big as the first one (storing the original content). Once you read the original content of the file by calling the read function, you will need to display the original content by calling the write function. Once the search and replace operation is complete, you will need to display the modified content in the console by calling the write function. Two sample execution traces for the program are shown at the end. You must deallocate your dynamic arrays at the end. You will not use the string class in your program as it would handle allocation for you, i.e., YOU WILL NOT include the header file.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started