Code Wars V
     

Program / Task Name:

   Quench Your Thirst

Level:

 

 Intermediate

Point Value:

 

 5

 

Task Description

The local convenience store is having problems keeping its soda machine stocked.  They’ve asked you to write a program to simulate the process of buying soda from the machine.  The cost of a soda is 55 cents and you will accept nickels, dimes and quarters.  After a customer has inserted enough money and selected a soda, give them a soda and return their change (if any) in the least amount of coins possible.

 You can assume:

  • The customer will complete all transactions they start (in other words, once the first coin goes in, they’re committed),

  • Only one soda will be purchased per transaction,

  • The machine is fully stocked with (Coke, Sprite, Dr. Pepper) and it will not run out, and

The machine is fully stocked with change (nickels, dimes, and quarters) and it will not run out.

Program Input

Prob06.in contains the initial contents of the machine (soda and change), as well as all of the data for the soda purchases for a single day.  A sample input file, might look as follows:

64 48 32
100 400 300
C 25 25 25
S 10 10 25 5 5
D 25 25 25 25
C 10 5 10 5 10 5 10 5
C 25 25 10
C 25 25 5 5 5
S 25 25 25 25 25 25
C 10 10 10 10 10 10 10
D 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
S 10 25 5 10 25 5
C 25 25 25
D 25 25 25
C 25 25 10 10
C 25 25 10
C 10 25 10 10
S 25 25 5 5 5 5

The first line is the number of Cokes (64), Sprites (48), and Dr. Peppers (32) in the machine.

The second line is the number of quarters (100), dimes (400), and nickels (300).

All subsequent lines contain the information for purchasing a soda:

  • The first parameter is the type of soda (C = Coke, S = Sprite, D = Dr. Pepper), and

  • The rest of the parameters are the coins inserted into the machine (25 = quarter, 10 = dime, 5 = nickel).

Program Output

Store all results in prob06.out according to the following specifications:

 

 

  • Before starting the simulation create an inventory report of the machine:

    • Total number of sodas in the machine,

    • Number of each type of soda in the machine (Coke, Sprite, Dr. Pepper),

    • Total amount of money in the machine, and

    • Number of each type of coin in the machine (quarters, nickels, dimes).

  • Print out a line stating that the simulation of purchasing soda has begun,

  • Report each purchase of soda using this format:

    • Type of soda purchased (Coke, Sprite, Dr. Pepper)

    • Amount of money inserted

    • Amount of change returned

    • A list of each coin returned

  • After all of the purchases have been completed, print out another line stating that the simulation of purchasing soda has completed,

  • After all of the purchases have been completed, create an inventory report of the machine exactly like the report before you started your simulation

For the data specified above, the report would look as follows:

Number of sodas: 144 (64 Cokes, 48 Sprites, 32 Dr. Peppers)
Amount of money: $80.00 (100 Quarters, 400 Dimes, 300 Nickels)

Begin purchasing inserting money and purchasing a soda.

Deposited   Soda        Change
---------   ----        ---------------------------
$0.75       Coke        $0.20 (2 dime)
$0.55       Sprite      $0.00
$1.00       Dr. Pepper  $0.45 (1 quarter, 2 dime)
$0.60       Coke        $0.05 (1 nickel)
$0.60       Coke        $0.05 (1 nickel)
$0.65       Coke        $0.10 (1 dime)
$1.50       Sprite      $0.95 (3 quarter, 2 dime)
$0.70       Coke        $0.15 (1 dime, 1 nickel)
$1.00       Dr. Pepper  $0.45 (1 quarter, 2 dime)
$0.80       Sprite      $0.25 (1 quarter)
$0.75       Coke        $0.20 (2 dime)
$0.75       Dr. Pepper  $0.20 (2 dime)
$0.70       Coke        $0.15 (1 dime, 1 nickel)
$0.60       Coke        $0.05 (1 nickel)
$0.55       Coke        $0.00
$0.70       Sprite      $0.15 (1 dime, 1 nickel)

All purchases have been processed

Number of sodas: 128 (55 Cokes, 44 Sprites, 29 Dr. Peppers
Amount of money: $88.80 (127 Quarters, 406 Dimes, 329 Nickels)

 

hp Code Wars
Hello -- Dominos?...
   
  (c) 2004 Hewlett-Packard Company