Question

Instructions​: You will find a file named findingNemo.m and another named nemo.txt. The first contains code...

Instructions​:

  1. You will find a file named findingNemo.m and another named nemo.txt. The first contains code which will read in strings from nemo.txt, then call Lab08(string) on each line of nemo.txt. Your job is to write Lab08.m.
  2. The Lab08 function will take in a string as input and will return an integer n as output.
  3. The value of n will be the nth word in the input string, where n is the location of the substring 'Nemo'.
    1. Please note that you will need to match whole words only, so 'aNemone' and 'Leonard Nemoy' should not be counted
    2. All strings will end with punctuation, so you do not need to work out the edge case of a string like 'I found Nemo', which could cause significant problems
  4. Once the value of n has been determined (hint: count the number of spaces before the index at which you found Nemo), use the statement fprintf('I found Nemo at word%d!\n',n); to print the results.
  5. If Nemo is not in the string, instead use the statement fprintf('I couldn''t find Nemo,sorry.\n'); and set n equal to negative one.
  6. If Nemo is in the string multiple times, return the location of its first appearance.
  7. Please be aware that if your file and function names are not the same as those expected in findingNemo(), or if all three files are not in the same folder, your code will not work correctly
  8. There are multiple ways to approach this problem, but the regular expressions may be useful here.

findingNemo.m:

function [] = findingNemo()
    fileID = fopen('nemo.txt','r');
    while true
        line = fgets(fileID);
        if line == -1
            break;
        end
        n = Lab08(line);
        fprintf('n = %d\n',n);
    end
end

Nemo.txt:

The author of this assignment swears she has never seen the movie Finding Nemo.
No, for real, this is totally a joke about Captain Nemo from 20,000 Leagues Under the Sea.
Okay, fine, I've never read 20,000 Leagues. But I did see Nadia: The Secret of Blue Water, which has a character named Captain Nemo.
Or maybe it's NEMO: Never Eat More Oreos.
I'll ask Leonard Nemoy. Or is it Nimoy?
Wait, those don't match Nemo.
At this point, Nemo doesn't even sound like a word anymore.
I guess it's not, Nemo is a name.
Buffalo buffalo buffalo buffalo. Nemo Nemo Nemo?
Is it spelled Nemotode or Nemotoad? Oh well, let's study anemone instead.
I'm thinking about making a cryptocurrency for Nebraska. What do you think of the name NEMoney?
Nemo is also a town in South Dakota, evidently.
Apparently NVIDIA has a toolkit for creating AI called NeMo, so that's weird.
I'm running out of jokes about the name Nemo, to be honest.
Let's just go watch Finding Nemo.

Homework Answers

Answer #1

SOLUTION :

Lab08 function is given below.

Note: line starting with '//' are comment lines. To explain in detail, comment lines were included.

function [] = Lab08(line)

n = 0

// get the string length

len = strlen(line);

// each word is seperated by space

oneSpace = ' '

while true

// n1 - temperory variable

n1 = n;

while n1 < len

// get single character at index n

ch = getch(line, n1)

// Check whether the character is space, if it is space, return the index

if ch == ' '

break;

// increment the index

n1 = n1 +1

end

// index not found

if n1 >= len

n1 = -1

if n1 == -1

break;

// extract the word between two spaces

word = substr(line, n, (n1-n))

// trim function is used to trim the punctuation and space in the beginning and end of the word

word = trim(word)

// if the word is not Nemo set the n to -1.

if word != "Nemo"

n = -1

// if the word is not Nemo, print the message

if n < 0

fprintf('I couldn''t find Nemo,sorry.\n');

// if the word is Nemo, print the message

if n >= 0

fprintf('I found Nemo at word%d!\n',n);

// Set the next index

n = n1

end

end

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Description The word bank system maintains all words in a text file named words.txt. Each line...
Description The word bank system maintains all words in a text file named words.txt. Each line in the text file stores a word while all words are kept in an ascending order. You may assume that the word length is less than 20. The system should support the following three functions: Word lookup: to check whether a given word exists in the word bank. Word insertion: to insert a new word into the word bank. No insertion should be made...
Strings The example program below, with a few notes following, shows how strings work in C++....
Strings The example program below, with a few notes following, shows how strings work in C++. Example 1: #include <iostream> using namespace std; int main() { string s="eggplant"; string t="okra"; cout<<s[2]<<endl; cout<< s.length()<<endl; ​//prints 8 cout<<s.substr(1,4)<<endl; ​//prints ggpl...kind of like a slice, but the second num is the length of the piece cout<<s+t<<endl; //concatenates: prints eggplantokra cout<<s+"a"<<endl; cout<<s.append("a")<<endl; ​//prints eggplanta: see Note 1 below //cout<<s.append(t[1])<<endl; ​//an error; see Note 1 cout<<s.append(t.substr(1,1))<<endl; ​//prints eggplantak; see Note 1 cout<<s.find("gg")<<endl; if (s.find("gg")!=-1) cout<<"found...
Please create a python module named homework.py and implement the functions outlined below. Below you will...
Please create a python module named homework.py and implement the functions outlined below. Below you will find an explanation for each function you need to implement. When you are done please upload the file homework.py to Grader Than. Please get started as soon as possible on this assignment. This assignment has many problems, it may take you longer than normal to complete this assignment. This assignment is supposed to test you on your understanding of reading and writing to a...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code to initialize the CustomerAccountsDB database table and add a set of customer accounts is provided. Finish the code in these 3 methods in CustomerAccountDB.java to update or query the database: -purchase(double amountOfPurchase) -payment(double amountOfPayment) -getCustomerName() Hint: For getCustomerName(), look at the getAccountBalance() method to see an example of querying data from the database. For the purchase() and payment() methods, look at the addCustomerAccount() method...
Arrays, loops, functions: Lotto Element Repeated Function Write a function that that takes as parameters an...
Arrays, loops, functions: Lotto Element Repeated Function Write a function that that takes as parameters an array of ints, an int value named element, and an int value named end. Return a bool based on whether the element appears in the array starting from index 0 and up to but not including the end index. Generate Random Array Write a function that takes as parameters an array of integers and another integer for the size of the array. Create a...
**[70 pts]** You will be writing a (rather primitive) online store simulator. It will have these...
**[70 pts]** You will be writing a (rather primitive) online store simulator. It will have these classes: Product, Customer, and Store. All data members of each class should be marked as **private** (a leading underscore in the name). Since they're private, if you need to access them from outside the class, you should do so via get or set methods. Any get or set methods should be named per the usual convention ("get_" or "set_" followed by the name of...
PYTHON : Create a Email Address Parser (* Please do make comments*) Often times, you may...
PYTHON : Create a Email Address Parser (* Please do make comments*) Often times, you may be given a list of raw email addresses and be asked to generate meaningful information from such a list. This project involves parsing such a list and generating names and summary information from that list. The script, eparser.py, should: Open the file specified as the first argument to the script (see below) Read the file one line at a time (i.e., for line in...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the codes below. Requirement: Goals for This Project:  Using class to model Abstract Data Type  OOP-Data Encapsulation You are asked to write an app to keep track of a relatively small music library. The app should load song information from a data file once the app is started. It should allow user to view, add, remove, and search for songs. The app should...
Description: In this assignment, you need to implement a recursive descent parser in C++ for the...
Description: In this assignment, you need to implement a recursive descent parser in C++ for the following CFG: 1. exps --> exp | exp NEWLINE exps 2. exp --> term {addop term} 3. addop --> + | - 4. term --> factor {mulop factor} 5. mulop --> * | / 6. factor --> ( exp ) | INT The 1st production defines exps as an individual expression, or a sequence expressions separated by NEWLINE token. The 2nd production describes an...
IntList Lab Specifications You are required to come up with a single header file (IntList.h) that...
IntList Lab Specifications You are required to come up with a single header file (IntList.h) that declares and implements the IntNode class (just copy it exactly as it is below) as well as declares the IntList Class interface only. You are also required to come up with a separate implementation file (IntList.cpp) that implements the member functions of the IntList class. While developing your IntList class you must write your own test harness (within a file named main.cpp). Never implement...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT