Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

USE MATLAB TO SOLVE, NO HARD CODING Function Name: pillagePublix Inputs: 1. (cell) An MX3 cell array containing the Publix inventory 2. (char) A string

USE MATLAB TO SOLVE, NO HARD CODING

Function Name: pillagePublix

Inputs: 1. (cell) An MX3 cell array containing the Publix inventory 2. (char) A string containing your grocery list

Outputs: 1. (cell) An MX3 cell array containing the updated Publix inventory 2. (char) A string describing the total cost of your groceries

Topics: (cell array manipulation), (iteration)

Background: Shiver me timbers! You grew up hearing horror stories about pirate diets, but when you pledged your life to piracy, you didn't expect it to actually be this bad. It's almost pi day, and you're craving something that isn't rotten, stale, or covered in salt. You've finally convinced your fellow crewmates to stop by the grocery store for all the necessary ingredients - keeping things professional, of course. Time to pillage Publix.

Function Description: You are given a cell array containing the Publix inventory, where the first column holds the item name (type char), the second column contains the quantity of that item that Publix has in stock (type double), and the third column is the unit price of that item in dollars (type double). You are also given a string containing what you need to buy, formatted '-', with a comma separating each item. There will not be any spaces in the string, and the items may be written in a different case than they appear in the inventory. Also, the string can contain any number of items. Your first output will be the updated Publix inventory. The updated inventory should reflect the new quantity that Publix has in stock after you purchase the items. Your second output will be a string describing the total cost of your Publix run, formatted 'My total is $.' where the total cost always has two decimal places.

Example: inventory = {'Apple', 18, 0.52; 'Salt', 50, 1.37; 'Flour', 29, 3.20} list = 'flour-3,APPLE-15' [updatedInventory, sent] = pillagePublix(inventory, list) updatedInventory -> {Apple, 3, 0.52; Homework 08 - Cell Arrays Salt, 50, 1.37; Flour, 26, 3.20} sent -> 'My total is $17.40.'

Notes: You can have more than one item on your list Every item on your list will exist in the inventory. There will always be enough of each item to buy what you need. Case does not matter.

Hints: Think about how you can format a number with two decimal points in a string. Recall which string functions work on cell arrays!

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

Graph Database Modeling With Neo4j

Authors: Ajit Singh

2nd Edition

B0BDWT2XLR, 979-8351798783

More Books

Students also viewed these Databases questions