Answered step by step
Verified Expert Solution
Question
1 Approved Answer
c++ question, i put the txt attachment picture for this question... please include comments on calculations and varibles Description In this program, you will write
c++ question, i put the txt attachment picture for this question... please include comments on calculations and varibles
Description In this program, you will write a program to emulate a vending machine (somewhat). In this version of the program, you will use a struct type defined below struct snackType string name; string code; double price; int remaining; Where name contains the snack's name, code contains the 2 digit code for the item, price holds the item's price, and remaining holds the amount of that item left in the vending machine. You will then create an array snackType snacks [MAX_ITEMS] where MAX_ITEMS will be a constant of type int and will hold the value of 20. The vending machine will not necessary hold 20 different items, but the max is 20, and you will need a counter to keep track of the number of different items in the vending machine. In this program to access an item's data, we would have snacks [0].name to retrieve the snack name at position 0 and snacks [0].code retrieves the stack code at position 0 and so on You will read the data from a provided input file of arbitrary number of lines, each line of the input will consist of ItemName itemCode amount price and each item will be separated by a space and each line is separated by and end of file character, so you will need to read the data from a file using an end of file controlled while loop, and you need to maintain a counter after each line read to know the amount of items stored in the vending machine. Then your program will output to the user all the contents in the machine, and the user wil have the option to choose an item by entering an item code (you will just read a string), then the snacks [i].remaining of element i will be decremented by 1, then the program will output all the contents again to the screen (any item that has at at least 1 for its remaining value), of course this will also be a menu driven program that will loop until the user enters N to quit or until the vending machine becomes empty (for all i amountLeft[i] -- 0). You will need to write the following functions int readItems (ifstream& infile, snackType snacks[]) - will read all the contents from the file, and it will keep track of the number of lines read and populate the array by updating each element's field, then it will return an integer that represents the number of items stored in the vending machineStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started