Your task in Programming Assignment 5 is to pseudocode the selection and dispens
ID: 3728390 • Letter: Y
Question
Your task in Programming Assignment 5 is to pseudocode the selection and dispensing of a Diet Coke®. Check out the video demonstration on D2L of me purchasing Diet Cokes and pondering the embedded logic in the machines. My favorite Coke® machine in Allgood Hall has Diet Cokes® in selection slots B1 through B5 and each slot (column) holds 10 bottles. When I purchase a Diet Coke®, I always select B1. I don't always get a Diet Coke® from B1. Why? As discussed in the demo video, there's an algorithm coded into this machine that will dispense a Diet Coke® and maintain the B1 - B5 slot inventory as even as possible or at least the front row for as long as possible. In other words, the embedded logic will not necessarily dispense a Diet Coke® from slot B1 when I select B1. Develop an algorithm and write the pseudocode that accomplishes the goal of maintaining that attractive front row as long as possible. The overall goal is to keep the B1 - B5 front row full and not allow an empty slot for as long as possible. Limit your pseudocode to Diet Cokes (slots B1 - B5) and assume you start with a full machine of 50 Diet Cokes (10 rows and 5 columns). You are to pseudocode the selection and dispensing portion of the transaction. Don't worry about entering money, making change, etc… Your pseudocode should be of sufficient detail to describe a complete Diet Coke® selection and dispensing algorithm.
Explanation / Answer
The algorithm is as follows:
Whenever there is a request to get diet coke from the specific
slot, then it is checked if that slot contains the maximum number
o bottles.The idea is to dispense the coke from the slot which is
having the maximum number of bottles. In that way , the number
of bottles in every slot will be evenly maintained. It is possible that
more than slots will have maximum number of bottles.
The pesudocode is as follows:
Input the slot
max = 10 //maximum number of bottles in a slot
dispensed = 0
while dispensed != 1:
i = 0
while i < 5 :
if number of bottles in Bi >= max:
dispense the bottle
dispensed = 1
number of bottles in the slot reduced by 1
break
i = i +1
if dispensed != 1:
max = max - 1
if max == 0:
break
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.