Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Overview Wecome to the vending machine! Item # Item Name Price # in-stock - - - - - - - - - - - -

image text in transcribed

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Overview Wecome to the vending machine! Item # Item Name Price # in-stock - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Chips Candy Soda 1.75 1.25 1.00 Nuw Enter a number of quarters: 5 Amount Entered: $1.25 Enter a number between 1 and 3 to make your selection: 3 Item has been dispensed below $0.25 dispensed below Continue? (Y / N): y Item # Item Name Price # in-stock - - - - - - - - - - - - - - - - - - - - Chips Candy Soda 1.75 1.25 1.00 uwi Enter a number of quarters: For this lab, you will be creating a program that simulates a simple vending machine that sells chips, candy, and soda. Each of these snacks has a different price and will have a different amount in stock. When the program is running, the current contents of the vending machine will be displayed to the user, and then a prompt to enter a number of quarters will appear. After the user enters a number, the amount of money they entered will appear in dollars and cents. For example, if the user entered 7 quarters, $1.75 would be displayed. Next, the user will be prompted to make a selection from the vending machine. If they have entered enough money and the snack is in-stock, the item will be dispensed, and the number in-stock will decrease by one. If the user entered more money than necessary to make the purchase, a message will be displayed indicated that the appropriate amount of change has been returned. See the sample run at the end for clarification. Requirements First, design a Snack class that... 1. contains the following private member variables: string - name of snack double - price of snack int - quantity in stock int - number of items sold You will also need to create the appropriate accessor and mutator functions for these member variables. 2. has two constructors A default constructor that initializes the name of the snack to an empty string, and the price, quantity, and number of items sold to 0 An overloaded constructor that accepts a string, a double, and an int and assigns these values to the name, price, and quantity member variables, respectively. The number of items sold should be initialized to 0. 3. has a destructor that display the quantity still in stock, the number of items sold, and the money gained from the sales. Remember that destructors are called when objects are destroyed, so you can think of the destructor in this case as a closing report for the day's sales. See the sample run at the end for the format. has a public buy Item method that: Has the following function header: bool buyItem( double& money Entered) If money Entered >= price, take away the appropriate value from the money Entered argument, decrease the quantity in stock by one, increase the number of items sold by one, tell the user that the item has been dispensed, and return true If money Entered ) Remember: do not worry about the contents of the function, just worry about the return type so that you can properly use it This method should be called whenever an item is successfully bought to store the current time that the transaction occurred. The time of the transaction should be stored in a dynamically- allocated array. This means you will need add a string pointer private member variable to your class. There are a few important things to keep in mind: 1. The size of the dynamically-allocated array will be determined by the number of items in- stock. When the first item is sold, the time of the transaction should be stored in the first index of the array. The second successful sale should store the item in the second index, and so on. 2. Remember that your class has two constructors. If the default constructor is called, remember that you do not yet know the number of items in stock. If the overloaded constructor is called, you will know how many items are in stock, so you will create your dynamically-allocated array. Because you are required to use the default constructor for the 'chips' object, add code to dynamically-allocate the array in the mutator function for the member variable that holds the number in stock. 3. Your destructor should output the times of the transaction ONLY if the array has times. If no times are stored (meaning nothing was bought), do not output anything. Remember that you need to appropriately clean the heap. Please post questions on Canvas if anything is confusing. Your question will benefit your classmates as well! Sample Run Welcome to the vending machine! Item # Item Name # in-stock Price -------- 1.75 1.25 1.00 Chips Candy Soda WN Enter a number of quarters: -1 Please enter a number greater than 0 Enter a number of quarters: 8 Amount Entered: $2.00 Enter a number between 1 and 3 to make your selection: 3 Item has been dispensed below $1.00 dispensed below Continue? (Y / N): Y Item # Item Name Price # in-stock Chips Candy Soda WN 1.75 1.25 1.00 Enter a number of quarters: 4 Amount Entered: $1.00 Enter a number between 1 and 3 to make your selection: 3 Item has been dispensed below Continue? (Y / N): y Item # Item Name # in-stock W NP Chips Candy Soda Price -------- 1.75 1.25 1.00 ouw Enter a number of quarters: 4 Amount Entered: $1.00 Enter a number between 1 and 3 to make your selection: 3 Error: item is sold-out! $1.00 dispensed below Continue? (Y / N): Y Item# Item Name Price # in-stock W NPL Chips Candy Soda 1.75 1.25 1.00 ouw Enter a number of quarters: 10 Amount Entered: $2.50 Enter a number between 1 and 3 to make your selection: 1 Item has been dispensed below $0.75 dispensed below Continue? (Y / N): y Item # Item Name Price # in-stock Chips Candy Soda 1.75 1.25 1.00 OUNT 3 Enter a number of quarters: 5 Amount Entered: $1.25 Enter a number between 1 and 3 to make your selection: 2 Item has been dispensed below Continue? (Y / N): y Item # Item Name Price # in-stock W NP Chips Candy Soda 1.75 1.25 1.00 Enter a number of quarters: 9 Amount Entered: $2.25 Enter a number between 1 and 3 to make your selection: 1 Item has been dispensed below $0.50 dispensed below Continue? (Y / N): n Closing info for Soda: 0 in stock 2 sold for a profit of $2.00 Transactions occurred at: 00:25:55 00:26:03 Closing info for Candy: 4 in stock 1 sold for a profit of $1.25 Transactions occurred at: 00:26:24 Closing info for Chips: 1 in stock 2 sold for a profit of $3.50 Transactions occurred at: 00:26:17 00:26:38 Overview Wecome to the vending machine! Item # Item Name Price # in-stock - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Chips Candy Soda 1.75 1.25 1.00 Nuw Enter a number of quarters: 5 Amount Entered: $1.25 Enter a number between 1 and 3 to make your selection: 3 Item has been dispensed below $0.25 dispensed below Continue? (Y / N): y Item # Item Name Price # in-stock - - - - - - - - - - - - - - - - - - - - Chips Candy Soda 1.75 1.25 1.00 uwi Enter a number of quarters: For this lab, you will be creating a program that simulates a simple vending machine that sells chips, candy, and soda. Each of these snacks has a different price and will have a different amount in stock. When the program is running, the current contents of the vending machine will be displayed to the user, and then a prompt to enter a number of quarters will appear. After the user enters a number, the amount of money they entered will appear in dollars and cents. For example, if the user entered 7 quarters, $1.75 would be displayed. Next, the user will be prompted to make a selection from the vending machine. If they have entered enough money and the snack is in-stock, the item will be dispensed, and the number in-stock will decrease by one. If the user entered more money than necessary to make the purchase, a message will be displayed indicated that the appropriate amount of change has been returned. See the sample run at the end for clarification. Requirements First, design a Snack class that... 1. contains the following private member variables: string - name of snack double - price of snack int - quantity in stock int - number of items sold You will also need to create the appropriate accessor and mutator functions for these member variables. 2. has two constructors A default constructor that initializes the name of the snack to an empty string, and the price, quantity, and number of items sold to 0 An overloaded constructor that accepts a string, a double, and an int and assigns these values to the name, price, and quantity member variables, respectively. The number of items sold should be initialized to 0. 3. has a destructor that display the quantity still in stock, the number of items sold, and the money gained from the sales. Remember that destructors are called when objects are destroyed, so you can think of the destructor in this case as a closing report for the day's sales. See the sample run at the end for the format. has a public buy Item method that: Has the following function header: bool buyItem( double& money Entered) If money Entered >= price, take away the appropriate value from the money Entered argument, decrease the quantity in stock by one, increase the number of items sold by one, tell the user that the item has been dispensed, and return true If money Entered ) Remember: do not worry about the contents of the function, just worry about the return type so that you can properly use it This method should be called whenever an item is successfully bought to store the current time that the transaction occurred. The time of the transaction should be stored in a dynamically- allocated array. This means you will need add a string pointer private member variable to your class. There are a few important things to keep in mind: 1. The size of the dynamically-allocated array will be determined by the number of items in- stock. When the first item is sold, the time of the transaction should be stored in the first index of the array. The second successful sale should store the item in the second index, and so on. 2. Remember that your class has two constructors. If the default constructor is called, remember that you do not yet know the number of items in stock. If the overloaded constructor is called, you will know how many items are in stock, so you will create your dynamically-allocated array. Because you are required to use the default constructor for the 'chips' object, add code to dynamically-allocate the array in the mutator function for the member variable that holds the number in stock. 3. Your destructor should output the times of the transaction ONLY if the array has times. If no times are stored (meaning nothing was bought), do not output anything. Remember that you need to appropriately clean the heap. Please post questions on Canvas if anything is confusing. Your question will benefit your classmates as well! Sample Run Welcome to the vending machine! Item # Item Name # in-stock Price -------- 1.75 1.25 1.00 Chips Candy Soda WN Enter a number of quarters: -1 Please enter a number greater than 0 Enter a number of quarters: 8 Amount Entered: $2.00 Enter a number between 1 and 3 to make your selection: 3 Item has been dispensed below $1.00 dispensed below Continue? (Y / N): Y Item # Item Name Price # in-stock Chips Candy Soda WN 1.75 1.25 1.00 Enter a number of quarters: 4 Amount Entered: $1.00 Enter a number between 1 and 3 to make your selection: 3 Item has been dispensed below Continue? (Y / N): y Item # Item Name # in-stock W NP Chips Candy Soda Price -------- 1.75 1.25 1.00 ouw Enter a number of quarters: 4 Amount Entered: $1.00 Enter a number between 1 and 3 to make your selection: 3 Error: item is sold-out! $1.00 dispensed below Continue? (Y / N): Y Item# Item Name Price # in-stock W NPL Chips Candy Soda 1.75 1.25 1.00 ouw Enter a number of quarters: 10 Amount Entered: $2.50 Enter a number between 1 and 3 to make your selection: 1 Item has been dispensed below $0.75 dispensed below Continue? (Y / N): y Item # Item Name Price # in-stock Chips Candy Soda 1.75 1.25 1.00 OUNT 3 Enter a number of quarters: 5 Amount Entered: $1.25 Enter a number between 1 and 3 to make your selection: 2 Item has been dispensed below Continue? (Y / N): y Item # Item Name Price # in-stock W NP Chips Candy Soda 1.75 1.25 1.00 Enter a number of quarters: 9 Amount Entered: $2.25 Enter a number between 1 and 3 to make your selection: 1 Item has been dispensed below $0.50 dispensed below Continue? (Y / N): n Closing info for Soda: 0 in stock 2 sold for a profit of $2.00 Transactions occurred at: 00:25:55 00:26:03 Closing info for Candy: 4 in stock 1 sold for a profit of $1.25 Transactions occurred at: 00:26:24 Closing info for Chips: 1 in stock 2 sold for a profit of $3.50 Transactions occurred at: 00:26:17 00:26:38

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 22nd European Conference Adbis 2018 Budapest Hungary September 2 5 2018 Proceedings Lncs 11019

Authors: Andras Benczur ,Bernhard Thalheim ,Tomas Horvath

1st Edition

3319983970, 978-3319983974

More Books

Students also viewed these Databases questions