Question: Function Name: Processor( ) Inputs: 1. ( char ) An incorrectly formatted list of ingredients 2. ( char ) The single ingredient you are looking

Function Name: Processor( )

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 )

Background:

You're cleaning out your kitchen and you come across an old recipe book. Unfortunately, the ingredient lists for each recipe are filled with typos, and you can not tell how

much of each ingredient you need. But, it seems like someone before you has left tips

telling you how to translate the recipes, so you turn to MATLAB to figure it out.

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.

2. Next, Delete every exclamation mark that appears.

3. Now, find the starting index of the desired ingredient (input 2) 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] = Processor(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 case-sensitivity (i.e. mAtLaB is not the same as

MATLAB)

Please solve without using Conditional Statements and Iterations!!!!!!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!