We would like to model a soft drink distributor available to the employees of a company. We assume that there are several types of drinks belonging to type \(\texttt{t_drink}\). There are 2 types of users: customers and service agents.

Operations to be defined are the following: buy a can of a particular beverage, creating an empty distributor, supplying a distributor with a number of cans of a particular beverage, test if there are no more drinks of some type (function \(\texttt{Unavailable}\)), consult the number of tokens, consult the number of drinks of a given type.

The first operation is performed by customers, while others are performed by service agents.

We assume that the customer manages to have tokens. A drink costs one token.

We define the \(\texttt{Distributor}\) abstract data type as follows:

Type: \(\texttt{Distributor}\)
Parameter: \(\texttt{t_drink}\)
Use: \(\texttt{Boolean, integer}\)
Functions:
\(\begin{array}{p{1cm} l l l} & \textbf{Create_distributor} & & \rightarrow \texttt{Distributor}\\ & \textbf{Buy} & \texttt{Distributor} \times \texttt{t_drink} & \rightarrow \texttt{Distributor}\\ & \textbf{Supply} & \texttt{Distributor} \times \texttt{Integer} \times \texttt{t_drink} & \rightarrow \texttt{Distributor}\\ & \textbf{Unavailable} & \texttt{Distributor} \times \texttt{t_drink} & \rightarrow \texttt{Boolean}\\ & \textbf{Number_of_tokens} & \texttt{Distributor} & \rightarrow \texttt{Integer}\\ & \textbf{Number_of_cans} & \texttt{Distributor} \times \texttt{t_drink} & \rightarrow \texttt{Integer}\\ \end{array} \)

Constructors:...
Preconditions: ...
Axioms: ...

 

Fill in missing paragraphs.


Difficulty level
This exercise is mostly suitable for students
Constructors
	Create_distributor,  Supply 
Preconditions
	Let d be a distributor and b a drink :
	Purchase(d,b) is defined iff not Unavailable (d,b)
Axioms
	Let d be a distributor and b a drink, e an integer :
	A1.	Unavailable(Create_distributor(),b) = True
	A2.	Unavailable(Supply(d,e,b),b) = False
	A3.	Number_of_cans(Create_distributor(),b) = 0
	A4.	Number_of_cans(Supply(d,e,b),b) = Number_of_cans(d,b)+e
	A5.	Number_of_tokens(Create_distributor()) = 0
	A6.	Number_of_tokens(Supply(d,e,b)) = Number_of_tokens(d)
	A7.	Purchase(Supply(d,e,b),b) = Supply(d,e-1,b)

Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Asymptotic Analysis 19