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
The file named world_series_winners.txt contains a chronological list of the World Series winning teams from 1903...
The file named world_series_winners.txt contains a chronological list of the World Series winning teams from 1903 through 2009. (The first line in the file is the name of the team that won in 1903, and the last line is the name of the team that won in 2009. Note that the World Series was not played in 1904 or 1994.) Write a program q3.py that lets the user enter the name of a team and then displays to the screen...
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...
Develop a C++ PROGRAM which will find a hidden sentence in a list of random words...
Develop a C++ PROGRAM which will find a hidden sentence in a list of random words using map function Open this text file named shuffled_words.txt in your program If it matters, you may presume there are an even number of words in the file Place the contents of the file into an appropriate data structure in the following manner: Grab a pair of strings from the file (unless end of file is reached) Each string is separated by a space...
Q1) Write a Python function partial_print, which takes one parameter, a string, and prints the first,...
Q1) Write a Python function partial_print, which takes one parameter, a string, and prints the first, third, fifth (and so on) characters of the strings, with each character both preceded and followed by the ^ symbol, and with a newline appearing after the last ^ symbol. The function returns no value; its goal is to print its output, but not to return it. Q2) Write a Python function called lines_of_code that takes a Path object as a parameter, which is...
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...
Write a 4-6 sentence summary explaining how you can use STL templates to create real world...
Write a 4-6 sentence summary explaining how you can use STL templates to create real world applications. In your summary, provide an example of a software project that you can create using STL templates and provide a brief explanation of the STL templates you will use to create this project. After that you will implement the software project you described . Your application must be a unique project and must incorporate the use of an STL container and/or iterator and...
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...
Finish the CustomerAccountTransactions program that reads customer accounts receivable data from a file and then applies...
Finish the CustomerAccountTransactions program that reads customer accounts receivable data from a file and then applies a series of transactions to the accounts. Its main() method uses the CustomerAccounts class to manage a collection of CustomerAccount objects: reading customer accounts data & transactions, and obtaining a String showing the customer accounts data after the operations are complete. You will need to complete the readCustomerAccounts () and applyTransactions() methods in the CustomerAccounts class. First, please fill in your name in the...
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...
**[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...