Question
Write a C++ class called Snack. It should have data members for the name of a snack, the price of the snack (double), and the
Write a C++ 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 0 to 3) - 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:
Snack s1("corn chips", 0.75, 200); Snack s2("candy bar", 1.25, 300); Snack s3("root beer", 2.00, 450); VendSlot vs1(s1, 2); VendSlot vs2(s2, 1); VendSlot vs3(s3, 0); VendSlot vs4; // five bottles of water MiniVend machine(vs1, vs2, vs3, vs4, 0); std::cout << machine.numEmptySlots() << std::endl; std::cout << machine.valueOfSnacks() << std::endl; std::cout << machine.getMoney() << std::endl; machine.buySnack(1); std::cout << machine.numEmptySlots() << std::endl; std::cout << machine.valueOfSnacks() << std::endl; std::cout << machine.getMoney() << std::endl;
The files must be named Snack.hpp, Snack.cpp, VendSlot.hpp, VendSlot.cpp, MiniVend.hpp, and MiniVend.cpp.
Step 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