Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE use MATLAB Banned Function: if, while PLEASE read instruction carefully! Function Name: blender( ) Inputs: 1. (char) An incorrectly formatted list of ingredients 2.

PLEASE use MATLAB

Banned Function: if, while

PLEASE read instruction carefully!

Function Name: blender( )

Inputs: 1. (char) An incorrectly formatted list of ingredients

2. (char) The single ingredient you are looking for

Outputs: 1. (char) A sentence outputting how much of the specified ingredient you need

Topics: (char strings), (sprintf), (LHS/RHS indexing)

Function Description: Given a 1xN char vector with a jumbled list of ingredients and a 1xM char vector of a single ingredient, use the following instructions to determine how much of the ingredient you need:

1. You realize the list is written backwards, so first you must reverse the entire list such that the last letter becomes the first letter, the second-to-last letter becomes the second letter, and so on.

2. Next, you notice that there are random exclamation marks throughout the list. Delete every exclamation mark that appears.

3. Now, find the starting index of the desired ingredient (input 2) in the list. The starting index of the ingredient in the list represents the amount of that ingredient that you need.

4. Lastly, output a sentence summarizing what you need with the following format: 'I need to buy (s).' Be sure to print the specified ingredient exactly as it was given to you (all lowercase).

Example: list = '!!!IwIk!N!o!M!e!L!'

ingredient = 'kiwi'

[str] = blender(list, ingredient)

str 'I need to buy 6 kiwi(s).'

Notes: The incorrectly formatted list may contain both upper and lowercase letters. The list will not contain any spaces or special characters other than '!'.

The ingredient you are searching for (input 2) will always be one word. It will always be lowercase and will not contain any spaces or special characters.

The ingredient you are searching for may contain both upper and lowercase letters when it appears in the list.

The ingredient you are searching for is guaranteed to appear only once in the list.

When outputting the final sentence, print the ingredient exactly as it was given to you.

Hints: Consider ways you can account for case-sensitivity (i.e. mAtLaB is not the same as MATLAB)

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

Time Series Databases New Ways To Store And Access Data

Authors: Ted Dunning, Ellen Friedman

1st Edition

1491914726, 978-1491914724

More Books

Students also viewed these Databases questions