Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C++ class called Snack. It should have data members for the name of a sn

ID: 3822277 • Letter: W

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 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:

The files must be named Snack.hpp, Snack.cpp, VendSlot.hpp, VendSlot.cpp, MiniVend.hpp, and MiniVend.cpp.

Explanation / Answer

//File Snack.hpp..............................

#ifndef SNACK_H

#define SNACK_H

public class Snack

{

private:
//data member declarations
string snackName ;
double snackPrice ;
int snackCal;

public:

//default constructor

Snack();

//parameterized constructor

Snack(string name,double price, int cal);

//get methods

string getName();

double getPrice();

int getNumCalories();

};

#endif

// File Snack.cpp................................................................................................

#include <iostream>

#include<cstring>

#include "Snack.hpp"
using namespace std;

public class Snack
{
//default constructor of this class

Snack :: Snack()
{
snackName ="botteld water";
snackPrice = 1.75;
snackCal = 0;
}
//parameterized constructor
Snack :: Snack(string name,double price, int cal)
{
snackName=name;
snackPrice =price;
snackCal=cal;
}

//Get methods for all variables
string Snack :: getName()
{
return snackName;
}

  double Snack :: getPrice()
{
return snackPrice;
}

int Snack :: getNumCalories()
{
return snackCal;
}

};

---------------------------------------------------------------------------------------------------------------------------------

//file VendSlot.hpp......................................................................

#ifndef VENDSLOT_H
#define VENDSLOT_H
public class VendSlot
{
private:
Snack s;
snackAmt amount;
  
public:
VendSlot();
VendSlot(Snack s,snackAmt i);
Snack getSnack();
int getAmount();
int decrementAmount();
};

#endif

-----------------------------------------------------------------------------------------------------------------------------------

//File VendSlot.cpp.......................

#include <iostream>

#include "VendSlot.hpp"
using namespace std;

public class VendSlot
{  

VendSlot :: VendSlot()
{
Snack s1;
s=s1;
amount =5;
}
VendSlot :: VendSlot(Snack s1,snackAmt i)
{
s=s1;
amount=5;
}
  
Snack VendSlot :: getSnack()
{
Snack ss;
ss=s;
return ss;
}
int VendSlot :: getAmount()
{
return amount;
}
int VendSlot :: decrementAmount()
{
amount = amount -1;
return amount;
}
};

-------------------------------------------------------------------------------------------------------------------------------------

//File MiniVend.hpp

#ifndef MINIVEND_H
#define MINIVEND_H

public class MiniVend
{
private:
VendSlot vs[4];
double money;
  
public:
MiniVend(VendSlot v1,VendSlot v2,VendSlot v3,VendSlot v4,money m);
int numEmptySlots();

double getMoney();
double valueOfSnacks();
void buySnack();
};

#endif

--------------------------------------------------------------------------------------------------------------

//file MiniVend.cpp

#include <iostream>
using namespace std;
#include "MiniVend.hpp"

#include <iostream>
using namespace std;
#include "MiniVend.hpp"

public class MiniVend
{
  
MiniVend::
MiniVend(VendSlot v1,VendSlot v2,VendSlot v3,VendSlot v4,money m)
{
vs[0]=v1;
vs[1]=v2;
vs[2]=v3;
vs[3]=v4;
money=m;
}

double MiniVend::getMoney()

{

return money;

}
int MiniVend :: numEmptySlots()

{

int i=0;

for(j=0;j<4;j++)

{

if

}

}
double valueOfSnacks();
void buySnack();
};

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote