Question

In: Computer Science

Lab 08: Finding Nemo Youshouldturnin:1.A file named Lab08.m, and a screenshot of you running findingNemo() from...

Lab 08: Finding Nemo

Youshouldturnin:1.A file named Lab08.m, and a screenshot of you running findingNemo() from thecommand line.

Instructions​:1.On Canvas you will find a file named findingNemo.m and another named nemo.txt. Thefirst contains code which will read in strings from nemo.txt, then call Lab08(string) oneach 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 thesubstring 'Nemo'.a.Please note that you will need to match whole words only, so 'aNemone' and'Leonard Nemoy' should not be countedb.All strings will end with punctuation, so you do not need to work out the edgecase 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 theindex 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 expectedin findingNemo(), or if all three files are not in the same folder, your code will not workcorrectly.

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

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.

Solutions

Expert 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


Related Solutions

Directly copy the source code and paste into the Word file. Screenshot of running result must...
Directly copy the source code and paste into the Word file. Screenshot of running result must be presented. 1. (20 points) Write the “Hello, world!” program. 2. (30 points) Write a program to calculate the sum from -5 to10. Use the for loop to do the calculation. 3. (20 points) Write a complete C++ program that asks the user to enter the necessary information about the cylinder, calculate the volume in a function (named as calculate_vol, using reference to pass...
In this lab, you open a file and read input from that file in a prewritten...
In this lab, you open a file and read input from that file in a prewritten C++ program. The program should read and print the names of flowers and whether they are grown in shade or sun. The data is stored in the input file named flowers.dat. Instructions Ensure the source code file named Flowers.cpp is open in the code editor. Declare the variables you will need. Write the C++ statements that will open the input file flowers.dat for reading....
Suppose you are running the bowling alley and are interested in finding the distribution of shoe...
Suppose you are running the bowling alley and are interested in finding the distribution of shoe sizes for women in order to buy a good fitting distribution of shoes. You took a random sample of 36 women and the mean size was an 8 with a standard deviation of 2. Create and interpret an approximate 95% confidence interval, with the appropriate critical T or Z value, for the mean shoe size of all women.
using C thank you Must submit as MS Word file with a screenshot of the 3...
using C thank you Must submit as MS Word file with a screenshot of the 3 outputs. Run your program 3 times. the output must be in a screenshot not typed for the each time you run the program. thank you Modify the code below to implement the program that will sum up 1000 numbers using 5 threads. 1st thread will sum up numbers from 1-200 2nd thread will sum up numbers from 201 - 400 ... 5th thread will...
Write a program named FinalExamProgram2 that reads numbers from a file (which you will create using...
Write a program named FinalExamProgram2 that reads numbers from a file (which you will create using Notepad) into a one-dimensional array and then analyzes the numbers as described below. Your program must use loops to read the numbers into the array and to analyze the contents of the array. The program’s main function should do the following:  Read eight floating-point numbers from the file named numbers.txt into a onedimensional array, displaying each number on the screen.  Pass the...
Lab to be performed in Java. Lab: 1.) Write a class named TestScores. The class constructor...
Lab to be performed in Java. Lab: 1.) Write a class named TestScores. The class constructor should accept an array of test scores as its argument. The class should have a method that returns the average of the test scores. If any test score in the array is negative or greater than 100, the class should throw an IllegalArgumentException. Write a driver class to test that demonstrates that an exception happens for these scenarios 2.) Write a class named InvalidTestScore...
In this lab, you will read and write to a file, as well as sorting the...
In this lab, you will read and write to a file, as well as sorting the information. Copy and paste the following into a file named "inputs.txt": 7 199922007 C.J. Cregg Political_Science 200822013 Olivia Dunham Criminal_Justice 199822007 Josh Lyman Law 199922006 Toby Ziegler Communications 200922015 Leslie Knope Public_and_Environmental_Affairs 199922004 Sam Seaborn Law 200722013 Walter Bishop General_Sciences The input file provides details for a student database in the following format: Number_of_students ID_Number Student_First_Name Student_Last_Name Major …… ID_Number Student_First_Name Student_Last_Name Major Your...
Consider a text file that you will create named “employees.txt”. The file contains data organized according...
Consider a text file that you will create named “employees.txt”. The file contains data organized according to the following format:John Smith 10 15Sarah Johnson 40 12Mary Taylor 27 13Jim Stewart 25 8For instance, “John” is the first name, “Smith” is the last name, “10” is the number of hours per week, and “15” is the hourly rate.Write a program that computes the weekly salary of each employee. The program prints the first name, last name, and weekly salary of each...
You are running a screening lab in a hospital and are trying to decide which test...
You are running a screening lab in a hospital and are trying to decide which test you should bulk order, API 20E, or EnteroPluri. Choose one and write a justification of why you prefer that one over the other.  
(LANGUAGE: C++) 1)     For this lab, you will fill in what’s missing to make the attached file...
(LANGUAGE: C++) 1)     For this lab, you will fill in what’s missing to make the attached file cust_leads.cpp work 2)     The Lead class is for a very limited amount of information about a potential customer ·       Include string fields for name and email ·       A constructor that takes values for these two fields ·       Include a getter for the email field ·       Overload the == operator ·       2 Lead’s are equal if the names are the same (the emails don’t need to match) ·       the first few lines...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT