Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a class called Snack. It should have data members for the name of a snack, the price of the snack (double), and the number

Write a class called Snack. It should have data members for the name of a snack, the price of the snack (double), and the number of calories in the snack (int). The class should have a constructor that takes three parameters and uses them to initialize the data members. It should also have a default constructor that initializes the data members to "bottled water", 1.75 and 0, respectively. The class should have get methods for all three data members. Write a class called VendSlot. It should have two data members - a Snack, and the amount of that Snack that is currently in the slot. It should also have a default constructor that initializes the data members to a default Snack object and 5. The class should have a constructor that takes two parameters and uses them to initialize the data members. It should have get methods for both data members. It should have a method called decrementAmount that decreases the amount by 1. Write a class called MiniVend, which represents a vending machine with four slots. It should have two data members - an array of 4 VendSlots and the money in the machine. The class should have a constructor that takes 5 parameters - 4 VendSlot objects and the initial money. It should have a get method that returns the amount of money in the machine. It should have a method called numEmptySlots that returns the number of slots that have no Snacks left. It should have a method called valueOfSnacks that returns the total value of the Snacks in the machine. It should have a method called buySnack that takes as a parameter the number of the slot from which to purchase a Snack (from 1 to 4) - if that slot is empty, nothing should happen, otherwise the amount of that Snack should be decremented and the money increased buy the price of the Snack that was selected.

The functions should have the following names:

For the Snack class:

getName

getPrice

getNumCalories

For the VendSlot class:

getSnack

getAmount

decrementAmount

For the MiniVend class:

getMoney

numEmptySlots

valueOfSnacks

buySnack

For example, these classes could be used as follows:

image text in transcribedThe files must be named Snack.hpp, Snack.cpp, VendSlot.hpp, VendSlot.cpp, MiniVend.hpp, and MiniVend.cpp. 
Snack s10"corn chips 0.75, 200) Snack s20' candy bar 1.25, 300) Snack s3C' beer 2.00, 450) root Vend Slot vs10s1, 2 VendSlot vs20s 2, 1); Vend Slot vs3Cs3, 0D; Vend Slot vs4; five bottles of water MiniVend machine(vs1, vs2, vs3, vs4, 0 stod: cout machine.numEmptystotsO std ::endl; sted: cout machine.value0fSnacksO std: endl; stod: :cout machine.getMoneyO std: endl; machine buySnackC1); stod: cout machine.numEmptystotsO std: :endl; sted: cout machine.value0fSnacksO std: endl; stod: :cout machine.getMoneyO std: endl

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

Database Security XI Status And Prospects

Authors: T.Y. Lin, Shelly Qian

1st Edition

0412820900, 978-0412820908

More Books

Students also viewed these Databases questions