Assignment InstructionsThe purpose of this assignment is to show that you can...« Compare two character arrays.« Analyze provided function(s).« Implement an insertion sort using student and...

1 answer below »
here is the photo of the question, language is matlab.


Assignment Instructions The purpose of this assignment is to show that you can... « Compare two character arrays. « Analyze provided function(s). « Implement an insertion sort using student and provided functions. We have used the insertion sort algorithm to sort an unsorted vector of numbers. This homework has you apply the same algorithm on words in a sentence. For example...Sort... "the quick brown fox" aS... "brown fox quick the" For this homework assignment you will... « Create a function "wordBeforeWord" which takes two arguments: a character array "word1", and another character array "word2 in that order. You can assume that "word1" and "word2" are lowercase and contain no spaces. "word1" or "word2" may be empty. Return a logical true if "word1" is alphabetically before "word2". Otherwise return false. = For example... >> wordBeforeWord ('goodbye', 'hello') ans = logical 1 >> wordBeforeWord('hello', 'goodbye') ans — logical 0 >> wordBeforeWord ('goodbye', 'goodbye') ans — logical 0 >> wordBeforeWord('good' , ‘goodbye ') ans — logical 1 >> wordBeforeWord ('goodbye', 'good') ans — logical 0 = Here's some other test cases wordBeforeWord('a’, wordBeforeWord ('b', wordBeforeWord('a’, wordBeforeWord ('aa’, wordBeforeWord ('ab', wordBeforeWord ('aa’, wordBeforeWord ('aaa’ wordBeforeWord ('aba’ wordBeforeWord ('aaa’ wordBeforeWord ('aab' wordBeforeWord ('abb' wordBeforeWord ('aab' wordBeforeWord ('aac' wordBeforeWord ('abc' wordBeforeWord ('aac' wordBeforeWord ('aaa’ wordBeforeWord ('aba’ wordBeforeWord ('aaa’ wordBeforeWord ('aab' wordBeforeWord ('abb' wordBeforeWord ('aab' wordBeforeWord('a’, wordBeforeWord ('ab', wordBeforeWord('a’, wordBeforeWord ('ab', 'b') % return 1 'a') % return 0 'a') % return 0 'ab') % return 1 'aa') % return 0 'aa') % return 0 , taba’) , 'aaa’) , 'aaa’) ’ rabb') , 'aab') , 'aab') , rabo') , rac’) , rac’) ’ rabb') , 'aab') , 'aab') , taba’) , 'aaa’) , 'aaa’) w ® ® ® ® ® ® ® ® ® ® ® ® ® ® return return return return return return return return return return return return return return return 'ab') % return 1 'a') % return 0 'ab') % return 1 'a') % return 0 wordBeforeWord('', 'a') % return 1 wordBeforeWord('a', '') % return 0 wordBeforeWord('', '') % return 0 wordBeforeWord('', 'ab') % return 1 wordBeforeWord ('ab', 1") % return 0 wordBeforeWord('', '') % return 0 CcomHOHOOMOOHKOOHR = DO THIS ONLY USING methods and practices demonstrated in class. These include... = Sequences or Vectors. = The functions "strcmp", "length"'strfind", etc... for", "whil = Arithmetic, relational and logical operations. = DO NOT USE other built-in matlab functions. = Such as.."regexp", "return", "string" or other similar functions. = If unsure, ask the instructor. = HINT: Suggest checking one character at a time iteratively. = HINT: "a" <'b'is true.="" "break",="" "continue"="" statements="" «="" use="" the="" provided="" function="" (see="" attached)="" called="" "insertwordinordertosentence"="" which="" takes="" two="" arguments:="" word="" character="" array,="" "newword",="" and="" an="" already="" word="" sorted="" sentence="" character="" array="" "ss"...in="" that="" order.="" assume="" "ss"="" has="" no="" beginning="" or="" trailing="" spaces="" and="" each="" word="" within="" it="" is="" single="" space="" separated.="" "ss"="" should="" already="" be="" an="" alphabetically="" word="" sorted="" sentence.="" "ss"="" may="" be="" empty.="" "newword"="" is="" the="" additional="" word="" that="" will="" be="" inserted="" into="" "ss"="" in="" a="" sorted="" manner.="" assume="" "newword"="" is="" all="" lower="" case="" and="" has="" no="" spaces.="" "newword"="" may="" be="" empty.="" return="" the="" sentence="" "ss"="" with="" "newword"="" inserted="" into="" it="" at="" the="" proper="" location.="" use="" your="" function="" "wordbeforeword()"="" to="" accomplish="" this.="For" example...="">> insertWordInOrderToSentence ('banana', 'avocado grape pear') ans — 'avocado banana grape pear’ >> insertWordInOrderToSentence ('watermelon', 'avocado grape pear’) ans — avocado grape pear watermelon’ >> insertWordInOrderToSentence ('apple', 'avocado grape pear') ans — 'apple avocado grape pear’ >> insertWordInOrderToSentence ('new', '') ans — "new! DO THIS ONLY USING methods and practices demonstrated in class. These include... = Sequences or Vectors. = The functions "strcmp", "length"'strfind", etc... "for", "while", "break", "continue" statements = Arithmetic, relational and logical operations. DO NOT USE other built-in matlab functions. = Such as.."split", "strrep”,'replaceBetween","'regexprep", "return", "string" or other similar functions. = If unsure, ask the instructor. HINT: Handle the empty cases separately from the non-empty cases. HINT: See examples from back in Lecture Slide 4 about finding first or last word in sentence...apply new knowledge of loops. HINT: While in the Lecture Slides there is an example of insertlnOrder() for numbers, it might NOT be productive to use that as a template for your code here. Instead, search the sentence for the first word which is not alphabetically before "newWord". Insert "newWord" within "ss" there. If all words in ss are alphabetically before "newWord", insert "newWord" at the end of "ss". « Create a function called "sentencelnsertionSort" which takes an argument: an unsorted sentence character array that order. Assume "s" has no beginning or trailing spaces and each word within it is single space separated. "s" may be empty. Using an insertion sort algorithm, return the character array sentence with the words in "s" alphabetically sorted. Use your function "insertWordInOrderToSentence()" to accomplish this. = For example... >> sentenceInsertionSort('the quick brown fox') ans — brown fox quick the’ >> sentenceInsertionSort ('the') ans = the! >> sentenceInsertionSort('') ans — 0x0 empty char array = DO THIS ONLY USING methods and practices demonstrated in class. These include... = Sequences or Vectors. = The functions "strcmp", "length"'strfind", etc... = "if", "for", "while", "break", "continue" statements = Arithmetic, relational and logical operations. = DO NOT USE other built-in matlab functions. = Such as.."strrep"'replaceBetween","regexprep"”, "return", "string" or other similar functions. » If unsure, ask the instructor. = HINT: See insertSortSimple() in Lecture Slide 14. 1. Start Matlab, you should see a bunch of windows all touching each other, with the biggest one labeled “Command Window”, as was demonstrated in lecture. Click in Matlab's Command Window. Hit the return key and you should see a prompt printed by the computer: >> After the prompt, type diary homework5.txt This will make everything that will be typed in the command window (by either you or Matlab) also be copied into the file homeworkS5.txt. This file will be on the computer where Matlab is really running, 2. In the command window, type clear This will remove any previously assigned variables from the current workspace 3. In the command window, type help wordBeforeWord You should see the help for your custom function. 4. In the command window, type help insertWordInOrderToSentence You should see the help for your custom function. 5. In the command window, type help sentenceInsertionSort You should see the help for your custom function. 6. In the command window, type wordBeforeWord ('down', 'up') You should see either true or false. 7. In the command window, type wordBeforeWord (' programming’ , 'program') You should see either true or false. 8. In the command window, type wordBeforeWord ('rain', 'rainfall') You should see either true or false.
Answered 2 days AfterNov 22, 2022

Answer To: Assignment InstructionsThe purpose of this assignment is to show that you can...« Compare two...

Baljit answered on Nov 25 2022
40 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here