Question
How do I update my code so that it works? I am really stuck on the miniVend part of my code and was wondering if
How do I update my code so that it works? I am really stuck on the miniVend part of my code and was wondering if you could help? I included the main function which is a sample of what will be run. Thank you !
My Snack.h file
#ifndef SNACK_CPP #include
class Snack { private: string nameOfSnack; double snackPrice; int numOfCalories;
public: Snack(); //default constructor Snack(string, double, int); //overload constructor ~Snack(); //destructor
//Accessor functions
string getNameOfSnack(); //returns name of snack double getSnackPrice(); //returns the price of the snack int getNumOfCalories(); //returns number of calories of snack };
#endif // !SNACK_CPP
My Snack.cpp file
#include "Snack.h" #include
using std::endl; using std::string; using std::cout; using std::cin;
Snack::Snack() //default constructor { nameOfSnack = "bottled water"; snackPrice = 1.75; numOfCalories = 0; }
Snack::Snack(string name, double price, int cals) { nameOfSnack = name; snackPrice = price; numOfCalories = cals;
}
Snack::~Snack() {
}
string Snack::getNameOfSnack() { return nameOfSnack; }
double Snack::getSnackPrice() { return snackPrice; }
int Snack::getNumOfCalories() { return numOfCalories; }
My VendSlot.h file
#ifndef VENDSLOT_CPP #include "Snack.h" #include
class VendSlot { public: VendSlot(); //default constructor VendSlot(Snack snackItem, int quantity); string getSnack(); //get snack name int getAmount(); //get amount of snacks available void decrementAmount(); //function to decrease storage in vending machine by 1. ~VendSlot(); //destructor
private: Snack snack; //passes snack object int numOfSnacks; // number of snacks };
#endif // !VENDSLOT_CPP
My VendSlot.cpp file
#include "VendSlot.h" #include "Snack.h" #include
using std::cout; using std::cin; using std::endl; using std::string;
VendSlot::VendSlot() { Snack; numOfSnacks = 5; }
VendSlot::VendSlot(Snack snackItem, int quantity) { snackItem = snack; numOfSnacks = quantity; }
int VendSlot::getAmount() { return numOfSnacks; } /********************************* *Description: decrease count in vendSlot by when it's purchased. **********************************/ void VendSlot::decrementAmount() { int quantity =- 1; }
VendSlot::~VendSlot() { }
string VendSlot::getSnack() { return snack.getNameOfSnack(); }
My minVend.h file - a work in process.
#ifndef MINIVEND #include
class miniVend { public: miniVend(); miniVend(VendSlot vendslot1, VendSlot vendslot2, VendSlot vendslot3, VendSlot vendslot4, double initialMoney); //constructor int numEmptySlots(); double valOfSnacks(); int buySnack(VendSlot, bool); ~miniVend(); //desructor
private: VendSlot vendslot1; //declare all the vending slots. VendSlot vendslot2; //declare all the vending slots. VendSlot vendslot3; //declare all the vending slots. VendSlot vendslot4; //declare all the vending slots. double moneyInMachine; //money in the machine
}; #endif // !MINIVEND
My miniVend.cpp file (very stumped here so it's kinda incomplete.)
#include "miniVend.h" #include "VendSlot.h"
miniVend::miniVend() { int vendslot1 = 0; int vendslot2 = 0; int vendslot3 = 0; int vendslot4 = 5; }
miniVend::miniVend(VendSlot vendSlot1, VendSlot vendSlot2, VendSlot vendSlot3, VendSlot vendSlot4, double moneyInMachine) { VendSlot vendSlot1; VendSlot vendSlot2; VendSlot vendSlot3; VendSlot vendSlot4; double moneyInMachine = 0; }
int miniVend::numEmptySlots() { return numEmptySlots;
}
double miniVend::valOfSnacks() { double valueOfSnacks = quantity * snackPrice; return valueOfSnacks; }
int miniVend::buySnack(VendSlot, bool) { if (VendSlot = 0) return 0; if (bool buySnack = 1) { return quantity; return valueOfSnacks;
}
miniVend::~miniVend() { }
Finally the Main function which will be run for testing.
#include
using std::cout; using std::cin; using std::string; using std::endl;
int main() { 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
return 0;
}
Project 3.c 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 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 get Price get NumCalories For the VendSlot class: get Snack get Amount decrementAmount For the MiniVend class: get Money numEmpty Slots valueOf Snacks buy Snack
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