Question
ENCMP 100 #5 Assignment Problem Specification Please read the entire document before starting this assignment. You are asked to write a program that generates a
ENCMP 100 #5 Assignment
Problem Specification
Please read the entire document before starting this assignment. You are asked to write a program that generates a tongue twister by substituting a particular string for every occurrence of a particular tag in a form that is read from a file named form.txt. The sample contents of this file are as follows: I [What?] a [what?]. But the [WHAT?] I [what?] wasn't the [what?] I [what?] I [what?].
You have also been given another file called sub.txt which contains a tag and a substitution string in a single line. The sample contents of this file are as follows: [What?] thought The first word (ending in white space) is a tag. It could consist of any characters that are not white space. Everything that follows (except for leading white space) is the string that should get substituted for that tag in the form. Tags are not case sensitive (upper or lower case does not matter). The substitution string might be empty or it might contain multiple words. Any leading white space is omitted. Finally once you have completed replacing all the occurrences of the tag with the substitution string and create a finished tongue twister, write the created tongue twister to a file called tongue_twister_
Here are the 4 functions: 1. read_form() - A function to read in the form from the data file. Open the file form.txt and test that the input file was correctly opened. Read in the data for the form using fgets . Using an empty string, concatenate each line read in into one string. Dont forget to close the file.
2. read_sub_tag() - A function to input the tag and substitution string. Open the file sub.txt and test that the input file was correctly opened. Read in the tag and substitution string. The function strtok will be helpful for this. Convert the tag to lowercase ( lower ) and trim the leading white space ( strtrim ) from the substitution string. Dont forget to close the file.
3. replace_tags()- A function to replace all occurrences of a specific tag with the substitution string. Tags are not case-sensitive. Before we can search for the tag (already lowercase) we wish to replace, we must ensure that the copy of the form we are searching in is all lowercase ( lower ). We can then use strfind to create an array of the occurrences of the tag in the lowercase form. Then for each occurrence of the tag, we can loop through and create a new string which is a concatenation of the original form up until the tag, the substitution string, and then the rest of the original form. Do not use strrep() in this assignment. If you do, you will receive a zero on Correct display of data in file. The purpose of this assignment is to get practice implementing string manipulations.
4. create_output()- A function that creates the required output text file for this assignment. Input parameters: your name as a string, and the string to be saved into the function. Code requirements: ? Your solution will contain 1 primary function and 4 functions, all contained in one file submission. ? Do not use the strrep() function. If you do, you will receive a zero on Correct display of data in file. ? There are no outputs needed or required to the command window of Matlab. Ensure that all outputs are suppressed.
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