Question: In this problem, you will write a function called do_expiration to manage a supply of magical food ingredients. The function will take in a vector

In this problem, you will write a function called do_expiration to manage a supply of magical food ingredients. The function will take in a vector of strings called ingredients, a vector of ints called good_stock, a vector of ints called expire_days, and an integer days_passed. ingredients contains the name of each ingredient, good_stock contains the quantity of good (not expired) ingredients, and expire_days contains the number of days before an ingredient expires (is no longer good). Because these are magical ingredients, any particular ingredient will only expire one at a time. This means if you have 6 onions and onions expire after 2 days, then if 4 days pass, only 2 onions will expire (one on day 2, and one on day 4). The function should update good_stock as necessary, and return a vector showing how many of each ingredient expired. Your function should also output the number of days passed, and if an ingredient expires, how many of that ingredient has expired.

Let's see an example where we start with 8 potatoes, 20 fish, 5 eggs, and 6 onions. And a potato expires after 30 days, a fish expires after 1 day, an egg expires after 7 days, and an onion expires after 5 days. We pass in 5 for days_passed:

 expired = do_expiration(ingredients, good_stock, expire_days, 5); 

Here's the situation before the call to do_expiration:

 ingredients: potato fish egg onion good_stock: 8 20 5 6 expire_days: 30 1 7 5 

Your do_expiration function should print the following 3 lines to STDOUT:

 Doing 5 day(s) of expiration. 5 fish(s) expired. 1 onion(s) expired. 

And here's the situation after the call to do_expiration:

 ingredients: potato fish egg onion good_stock: 8 15 5 5 expire_days: 30 1 7 5 expired: 0 5 0 1 

In the box below, write your implementation for do_expiration Sample solution: 14 lines

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!