Вы находитесь на странице: 1из 4

Dipl.-Inform.

Ursula Derichs
Praktikum „Praktische Informatik II“
TH Köln, Fakultät 07
29.04.2019

Internship Exercise 2

Delivery:
Please create a zip archive with the following content:

- Filled-in, signed and scanned cover sheet


- All headers and source files that contribute to the solution
- The executable and running program (.exe)
- compiler log
- All generated output files and a console output log

This zip-archive must be uploaded to Ilias by 23:55 hrs on 20.05.2019. Late submissions are
not possible. At the attendance appointment you demonstrate the solution from your archive.

Topics:
• Inheritance and Polymorphie
• Abstract classes
• Overloading and overwriting of methods

Task:
The snack machine from task sheet 1 is to be improved and further developed. For this
purpose CoinSlot, Keypad and DropCheck are introduced as new components, which can be
seen in the UML class diagram in Figure 1 and are described in more detail below:

Class CoinSlot

coinAmount To add up the amount of coins that have already been inserted
during the current purchase process.
coinValues This should be a fixed array which is needed to calculate the coins
returned as change. It should contain all coin values (in cents),
starting from the highest coin to the lowest coin (2 Euro = 200 cents
to 1 cent).
Constructor Initialisizes coinAmount with 0.
updateCoinAmount() Prompts the user to insert a coin or enter -1 to cancel the purchase
process. If the user enters a valid coin, the amount should be
added to coinAmount. The number entered is returned.
getCoinAmount() Getter for coinAmount.
Clear() Resets coinAmount to 0.
returnCoins() Receives the current price as a parameter and determines which
coins shall be returned as change. This method should show on the
screen which coins the machine ejects, e.g. 2 x 2 Euro, 1 x 0.50
Euro etc.

-1-
Dipl.-Inform. Ursula Derichs
Praktikum „Praktische Informatik II“
TH Köln, Fakultät 07
29.04.2019

Class Keypad:

getSelection() Requests the user to enter the number of the product slot from which
the product is to be ejected. A value of -1 serves as an abort here.

Class DropCheck:

productReleased() Checks whether the product has fallen from the product tray into the
output tray. In the real machine, this would be checked using the
infrared beams, which are interrupted when the product is ejected.
This is to be simulated here by the method randomly delivers false
with a probability of 10% (false means, infrared beams were not
interrupted, the product was not ejected), and deliver true with 90%
probability (the infrared beams were interrupted, the product is in the
output tray).

Figure 1 Enhanced UML Diagramm

-2-
Dipl.-Inform. Ursula Derichs
Praktikum „Praktische Informatik II“
TH Köln, Fakultät 07
29.04.2019

A specialization is to be used for the two slot variants (single motor, twin motor), the two
classes SmallSlot and WideSlot are to be derived from Slot as shown in Figure 1. The
method drop() should be abstract in Slot and implemented in both derived classes. The
method Automat.addSlot() shall be overloaded so that it can be used for a narrow slot with
one motor or a wide slot with two motors. Avoid code duplication at this point by overloading
addSlot() one more time with a pointer to Slot as a parameter.

The functionality of the automat is to be changed somewhat: First the product is to be


selected and then the coin is entered:

1. Product selection:
The buyer selects the number of the product slot on the keypad. By entering -1 the
program can be aborted.
2. Coin insertion:
The buyer inserts coins, the inserted amount appears in the display. As soon as
enough coins have been inserted, the product is ejected. With Cancel (input of -1) the
buyer can cancel the current purchase process.
3. Product release:
The product is pushed forward by a spiral motor and falls into the output tray. Infrared
beams are used to check whether the product is actually falling down.
4. Change in coins:
The return money is ejected.

The control logic in the main program should work with states that are to be defined as
enumerations in C++. In figure 2 the state diagram for the snack automat is sketched.

Figure 2 States of the snack machine

-3-
Dipl.-Inform. Ursula Derichs
Praktikum „Praktische Informatik II“
TH Köln, Fakultät 07
29.04.2019

In the main function a switch is to be implemented in the simulation loop, which executes
actions dependent on the current state. The initial state is IDLE. The table below briefly
describes the meaning and realization of the states and state changes.

IDLE This is the state when no valid entry has been made yet. If an entry is
made via the keypad, the automaton either goes into the final state
(with an entry of -1) or into the state COLLECT_MONEY (with a valid
entry), otherwise the automaton remains in the state IDLE. When
switching to the COLLECT_MONEY state, the price to be paid must be
determined.
COLLECT_MONEY In this state, coins are inserted and collected in the coin slot until the
amount is sufficient for the purchase or an abort has been initiated (by
entering -1). If the sum of all inserted coins covers the price, the
automat changes its state to DROP. If aborted, the price is set to 0 and
the automat changes state to RETURN_MONEY.
DROP In this state, the product is ejected from the selected tray. The
DropCheck.productReleased() method checks whether the product was
actually ejected. Only if this check is positive, the automat changes
state to RETURN_MONEY, otherwise the automat remains in state
DROP and in the next loop execution the system tries to eject the
product again.
RETURN_MONEY Here the change is ejected, the coin slot is reset and the automat
changes state to IDLE.

-4-

Вам также может понравиться