Question: Solve this for C++ Write a program that reads some message loaded from a user specified text file (the file name is entered by the


Write a program that reads some message loaded from a user specified text file (the file name is entered by the user). The program then encodes the loaded message and outputs it to an "output t txt' file. The strategy for encoding is as follows. Given a user input integer " n ", the encoding will insert one digit character (i.e., 09 ) every " n " characters (including white spaces). The digit character is randomly generated every time a new digit needs to be inserted. Hint: You must set srand (2); in the main function. Then, call rand ( ) function in the encoder() function (see below) to produce a random number between 0 and 9 (inclusively). To use the rand() function, please include . The ASCll codes for ' 0 ' to ' 9 ' are 48 - 57. You can use char(48+digit) (digit is an integer with value between 0 and 9 ) to convert the ASCll code to a digit character. For example, char (48+2) will give you character ' 2 '. Ex: if the user enters and the "message1.txt" contains the following message the encoded message output to the "output.txt" file will be TOh9e85sle8c4r7e5t72m9e9e3t7i9n4g3710o2c2a9t5i7olno0i6s33a6t.2P1G6H27233727. The secret meeting location is at PGH 232. the encoded message output to the "output txt" file will be Tohge85sle8c4r7e5t72m9e9e3t7i9n4g371002ca9t51701n0016s33a6t22P1G6H27233727. It inserts a digit every 1 original character (including white spaces). (1) Define a function, named boot loadMessage () that takes the following in order as input - a file name - a string array to store the message, one element for one line (you can safely assume the number of lines is no more than 10) - the number of lines loadMessage ( ) function will try to open the file. If the file does not exist, the function will return false. Otherwise, the file will load the message line-by-line and update the number of lines variable accordingly. After reading all message, the function will return true. (2) Define a function, called void encoder () that takes the following in order as input. - a string storing the original message - an integer indicating how frequent to insert a digit - a string storing the encoded message learn.zybooks.com (3) In the main function, - receive the user input of a filename and an integer - call the LoadMessage () function. If the function returns false, output "File not found. " and exit. - otherwise, for the loaded message, call the encoder ( ) by passing one line of the message each time to produce a line of the encoded message; output this line of the encoded message to the "output.txt" and move on to the next line until all lines are encoded. Remember to close your files! If you do not explicitly close all files that the program opens, you will lose 10 points!!! Any attempt to hard code the results to the output.txt file will result in 0 for this exercise
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
