Grocery Problem Exercise #1 – Grocery Problem (25pts) Scenario Consider the foll
ID: 3774424 • Letter: G
Question
Grocery Problem
Exercise #1 – Grocery Problem (25pts)
Scenario
Consider the following situation. Your local grocery store ran a contest where the contest winner was
allowed to fill his/her car with however many groceries the winner could take home, at no cost to the
contest winner. And as a result, you were the lucky winner of that contest.
Requirements
The included file groceries.txt (found in the Canvas repository) contains a list of groceries available
for you to take home in your car. The format of the file is the following broken across every three
lines:
• Item Name (string)
• Item Weight in pounds (double)
• Item Cost in USD (double)
You are to write a program which loads the data into your program. There are a number of conditions
to be aware of though:
Weight Restrictions
Unfortunately your car is rather small and you are unable to drive off with every item in the store. You
are only able to fit 100 pounds of groceries in your car.
Cost Optimization
Since you are restricted with being only able to drive off with 100 pounds of groceries, you being the
savvy shopper decided that you want to make the trip as worthwhile as possible and drive off with the
most valuable items in the store. You have devised the following algorithm (pseudocode) to help you
obtain this goal:
while weight limit is not hit
select most valuable item from grocery store
if weight of item is less than weight remaining in car
add it to your car
end if
end while
The weight of all items in your car cannot exceed 100 pounds when the algorithm completes. Also
you can only accept one of each item in the store (found in the groceries.txt file.) One last restriction,
you can not take “partials” of items (either the whole item can be taken or it cannot fit in your car.)
Instructions
For this assignment, you are to write a C++ program implements the above algorithm. Your code is to
read in the groceries.txt file and after processing you are to output the following:
• The name and cost of each item
• The total cost of all items in your car
• The total weight of all items in your car
groceries.txt
Bananas1.310.99Rib Eye Steak2.5514.96Chicken Breast Value Pack7.8521.97Dry Dog Food20.0014.99Apples2.503.49Yogurt (Plain)5.009.99Bread (White)2.001.59Eggs (18 count)2.002.99Milk (Whole/Gallon)1.004.29Hamburger (Value Pack/90% Lean)10.0031.99Deli Ham (Virginia)3.0021.49Shrimp (Peel and Serve)4.0029.99Canned Tomatoes (12 pack)7.007.99Cheese (American / 50 slices)5.006.99Bread (Hamburger Rolls / 24 count)2.002.99Tuna Fish (Canned albacore with Oil / 12 count)6.009.99Olive Oil (Extra Virgin)5.0019.99Kidney Beans (Canned with Juice)3.003.49Orange Juice (100% with pulp)3.005.99Cranberry Juice2.004.99Energy Drink (24 count)1.7519.99Batteries (AA / 100 count)
7.5029.99Pork Shoulder4.5012.99Sausage (Brown and Serve)2.004.99Salmon (Fresh Caught / Sushi Grade)3.5064.99Bread (Hot Dog Buns / 24 count)2.002.49Cottage Cheese1.353.99Bacon (Center Cut)2.0014.99Cream Cheese (4 pack)4.008.99T-shirt of your local city1.0012.99Dog Biscuits2.003.99Lobster (Fresh)4.0059.99Oranges (10 count)5.007.99Canadian Bacon2.009.99Frozen Pizza (Pepperoni style / 3 pack)3.0012.99Lettuce (Romaine)3.006.99Onions (Yellow)3.004.49Garlic (Fresh / 12 cloves)1.453.99Mushrooms (Portabella)3.006.99Dried Oregano0.451.99Cheese Curls0.753.99Soda (24 pack / Canned)6.005.99Sheet Cake (from in store bakery)3.00
19.99Frozen Pizza (Cheese style / 3 pack)3.0012.99Green Peppers (Bell style)3.006.99Macaroni and Cheese (hot bar)2.0011.49Frozen Turkey (Young)19.4928.76Rice (White / Value Bag)20.0011.99Green Curry (Jar)0.454.29London Broil4.9326.44Butter (Salted)2.004.29Pound Cake (Frozen)2.007.99Bagels (Fresh / 12 count)4.006.99Pain Reliever (Generic brand / 100 count)0.753.99Hot Dogs (100% Beef)4.509.99Potato Chips2.004.99Ice (20 pound bag)20.002.99Gum (Peppermint / 5 pack)0.752.49Potatoes (Red Skin)10.004.99Shampoo2.006.99
Explanation / Answer
Salmon (Fresh Caught / Sushi Grade) 64.99
Lobster (Fresh) 59.99
Hamburger (Value Pack/90% Lean) 31.99
Shrimp (Peel and Serve) 29.99
Batteries (AA / 100 count) 29.99
Frozen Turkey (Young) 28.76
London Broil 26.44
Chicken Breast Value Pack 21.97
Deli Ham (Virginia) 21.49
Energy Drink (24 count) 19.99
Sheet Cake (from in store bakery) 19.99
Olive Oil (Extra Virgin) 19.99
Bacon (Center Cut) 14.99
Dry Dog Food 14.99
Rib Eye Steak 14.96
T-shirt of your local city 12.99
total cost of the items in the car is 434
total weight of the items in the car is 99.6
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.