Question: * * * * * * IN C CODE * * * * * * Build a vending machine in c code Your program must

******IN C CODE******
Build a vending machine in c code
Your program must use the data in the configuration file (vending-config.txt)
The first line of the file indicates how many coins of each denomination (U.S.) are provided, e.g.:
100300200500
Indicates that the machine has 100 quarters, 300 dimes, 200 nickels, and 500 pennies. The vending machine will not be configured to hold more than 10,000 coins of a given denomination.
The values for each type of coin are the standard, in US dollars: 0.25 for quarters, 0.10 for dimes, 0.05 for nickels, and 0.01 for each penny.
The second line in the configuration file gives a count of how many different items are for sale in the vending machine, e.g.:
4
The third line onward each include four entries per line: a two-letter code indicating the slot for the item, the name of the item for sale, its cost in dollars, and the amount of each item. There will not be more than 200 items of any given type.
For example:
A1 grape-soda 1.2525
A2 gatorade 2.2550
B1 snickers 1.7540
B2 witergreen-gum 0.7540
In a given configuration, the name of an item will not exceed 50 characters.
Please pay attention to these requirements:
There is no predefined limit on how many different items are on sale in a given vending machine. This must be dynamically allocated at run time.
The vending machine does not accept any payments over $5.00. If more than this amount is attempted, the purchase is rejected due to overpayment.
Once the vending machine is configured, your code must output the initial state of the vending machine, including which items it has for sale and all details for them and how many coins of each denomination it has.
Following configuration, your code must process the purchases.txt file, which has a collection of entries indicating a two-letter code for an attempted purchase and the amount of money paid.
An example of some lines of input are as follows:
A22.50
B11.78
Z9-6.00
A140.00
Note: For these purchases, assume that a gift card is being used-- the vending machine does not collect any coins at all, it merely consumes the amount on the card, and dispenses change.
More requirements:
Processing must include logging the results of each attempted purchase to a text file, vending-out.txt. For each purchase, the log must include the item code, name, cost, amount paid, and other results.
In the case of a rejected purchase, output the status in a human-readable format; in cases where a purchase was successful, include output of coins returned.
Each purchase attempt results in exactly one these statuses based on processing:
If the amount paid is less than the cost, log "insufficient-funds"
If there are no more items remaining, log "insufficient-supply"
If the code entered is invalid, log "invalid-code". The code check should be case-insensitive, i.e. lookup for "A5" is the same as "a5"
If the amount paid is over the limit, log "over-payment"
If there is not enough change in the machine to complete the purchase, log "no-change"
If an item is successfully purchased:
Indicate success
Report the amount of change returned
Report how many coins of each denomination are returned
Update the vending machine by
Removing one of the items purchased
Removing amounts of coins returned as change.
Incrementing a total number of items sold
Adding the amount of the purchase to total sales
At the start and end of the log file, your code must also log the state of the vending machine:
A list each item for sale by code and name and the amount remaining,
The amount of each coin remaining in the system.
The total amount of sales
A count of how many purchases were attempted.
How many purchases were successful.
A count and histogram by percentage of successful purchases by product
Note that the sum of counts for requirement 6 must be the same as the count in requirement 5.
Refer to vending-out.txt for an example of acceptable program output.
At a minimum, your program should report the following steps to stdout:
- Loading the vending machine configuration
- Processing the purchases
- Logfile/Program complete
At a minimum, your submission must include a main.c file, a vending.c file, and a vending.h file. These files should contain code and type declarations as appropriate. The main.c should contain only preprocessor directives needed to run the program and an implementation of the main() function.
Your submission must include all header(.h) and source(.c) files needed to compile and run the code.
You may include your vending-out.txt file, but your grade will be based on my execution of your code using different vending machine configurations and sets of purchases. Note: I will run your code using different vending machine configurations and sets of purchases; you may assume that the format for t

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 Programming Questions!