CS112: Lab 8 :: Structures and GUIs

Task 1. Practice with Structures

Set up

In the assign6_problems folder, open the file named shopping.m. This file creates two different vectors of structures called sohiesCart and ellensCart. Run the script and then examine sohiesCart and ellensCart in your workspace. How many structures are in each vector (cart)? How many fields does each structure have?

Print cart contents and total

Your task is to write a function called viewAndTotalCart(theCart) that prints the contents of the provided cart vector and totals the prices of the items in the cart. For example, your output should look something like this:
>>
>> viewAndTotalCart(sohiesCart)
orange
apple
milk
cheerios
carrot
doritos
lucky charms
--------
Your total is $18.52
>>
>> viewAndTotalCart(ellensCart)
yogurt
cheese
apple
cashews
--------
Your total is $28.67


Table of contents