Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please do this in MATLAB ENCMP 100 MATLAB assignment 5 Please read the entire document before starting this assignment. You are asked to write a

Please do this in MATLAB

ENCMP 100 MATLAB assignment 5

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?].

ENCMP 100-Computer Programming for Engineers

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_.txt. After running your program, your tongue_twister_.txt file should contain the following:

I thought a thought. But the thought I thought wasn't the thought Ithought I thought.

After your program has run, open this file to verify its content. Your outputted file should be identical.

Additionally, your program should run correctly for any valid data found in these files.

Implementation Details

Your primary function will be fairly concise and will basically just call the 4 functions and pass the proper values and/or data to the other function(s).

Your solution will contain at a minimum the following 4 functions. In each function, write out the pseudocode for each function. Please remember to include it in your submission they will be marked. Work incrementally, testing your code as you go. 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 th

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.

Hints

1. For this assignment, declare string variables when you need them.

2. The data files that you read from will contain valid data in the format specified above. Your code does not need to do any validity checks on the data.

3. In order for the program to find your input files (form.txt and sub.txt), you must ensure that they are stored in the same directory or location as your *.m file.

4. Include your pseudocode for each function, there are marks for that.

5. Please remember to comment your code as well.

6. Some functions to be used : fopen fgets strtok fclose fprintf lower feof strfind strtrim sprintf

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Logics For Databases And Information Systems

Authors: Jan Chomicki ,Gunter Saake

1st Edition

1461375827, 978-1461375821

More Books

Students also viewed these Databases questions

Question

What is conservative approach ?

Answered: 1 week ago

Question

Identify the types of informal reports.

Answered: 1 week ago

Question

Write messages that are used for the various stages of collection.

Answered: 1 week ago