Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

My attempt to solve this problem is as follows: function deAdamize(pun,replacement) % opening the pun file and the replacement file with intent to read them.

image text in transcribedimage text in transcribed

My attempt to solve this problem is as follows:

function deAdamize(pun,replacement)

% opening the pun file and the replacement file with intent to read them. openPun = fopen(pun,'r'); openRep = fopen(replacement,'r'); % initializing empty vectors that will hold the portion of each line of the % replacement text which corresponds to the replacer and the pun to be % replaced. replacer = {}; findPun = {}; % looping through every line in the replacement file to isolate the % replacer and the pun intended to be replaced. for r = replacement %retrieving each line of the replacement file. lineR = fgetl(openRep); % using the ':' character as an indicator of the pun and the % replacement word in each line and concatenating each word into % its respective array. replacer = {replacer extractAfter(string(lineR),':')}; findPun = {findPun extractBefore(string(lineR),':')}; % looping through every line of the pun file to find lines that contain % puns which would need to be replaced. for p = pun % retrieveing each line of the pun file. lineP = fgetl(openPun); % performing a string replacement of the pun with its indicated % replacement on any line that contains the specified pun. if contains(lineP,findPun) == true lineP = strrep(lineP,findPun,replacer); end end % creating a variable in the workspace which will read each line of the % pun file with any replacements made. lineP = sprintf('%s ',lineP); end

% finding the name of the input pun text file. [path name ext] = fileparts(pun); % appending '_edited' to its corresponding output text file. txtFile = [name '_edited']; % opening the edited pun text file with intent to write to it. txtFile = fopen(txtFile,'w'); % making sure each line of text will print to the output text file. fprintf(txtFile,'%s',lineP); % printing to the desired text file. fprintf(txtFile,' '); % closing the output file. fclose(txtFile); end

The Test Case I have tried which returned the error above are as follows:

'tacos.txt'

Okay now it's time for a short one. What did the nachos say to Bonnie Raitt? Lets give them something to taco 'bout. Now thats punny.

'replace.txt'

appeeling:attractive taco:talk punny:funny a salted:assaulted ribbiting:riveting
Homework 5 Low Level File VO Function Name: deAdamize Inputs: 1. (char) the name of a text file containing puns 2. (char) the name of a text file with pun replacements Outputs: none File Outputs: 1. A text file of the edited version of the original text Function Description: As you will come to find out throughout this semester, some TAs lack the ability to make quality jokes, one ex-TA in particular has been honored in the name of this function. You have decided to take it upon yourself to remove the lowest form of joke, the pun, from various text files This ex-TA only has a set amount of jokes he knows so the pun keywords you will always be looking for are 'punny', 'a salted', 'appeeling, 'ribbiting', and 'taco" However, after you find these puns you must go in and replace them with an appropriate substitute defined in the text file You are given a text file of appropriate replacements for each pun word. Each line of the text file will be formatted as khorrible punx:replacement> Swap all pun words in the original file with their replacement and write the result to a new file. The new filename should have'_edited' appended to the original file name. For example if the original filename was 'speech.txt' the output file would be 'speech edited.txt The puns will only be the ones listed above, but the replacements for these words could change Notes: . Neither the pun nor the replacement will contain a colon () There could be multiple puns on one line The strrep() function will be very useful Homework 5 Low Level File VO Function Name: deAdamize Inputs: 1. (char) the name of a text file containing puns 2. (char) the name of a text file with pun replacements Outputs: none File Outputs: 1. A text file of the edited version of the original text Function Description: As you will come to find out throughout this semester, some TAs lack the ability to make quality jokes, one ex-TA in particular has been honored in the name of this function. You have decided to take it upon yourself to remove the lowest form of joke, the pun, from various text files This ex-TA only has a set amount of jokes he knows so the pun keywords you will always be looking for are 'punny', 'a salted', 'appeeling, 'ribbiting', and 'taco" However, after you find these puns you must go in and replace them with an appropriate substitute defined in the text file You are given a text file of appropriate replacements for each pun word. Each line of the text file will be formatted as khorrible punx:replacement> Swap all pun words in the original file with their replacement and write the result to a new file. The new filename should have'_edited' appended to the original file name. For example if the original filename was 'speech.txt' the output file would be 'speech edited.txt The puns will only be the ones listed above, but the replacements for these words could change Notes: . Neither the pun nor the replacement will contain a colon () There could be multiple puns on one line The strrep() function will be very useful

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

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions