Question: I'm trying to create a C++ Machine class for a vending machine that keeps track of all the money collected Its constructor takes one parameter

I'm trying to create a C++ Machine class for a vending machine that keeps track of all the money collected

  • Its constructor takes one parameter that represents the number of products the machine can hold. It should make sure that it allows no more of the same one product. It should allocate the data structure to represent that many products.
  • It should have a restock() mutator function that takes three parameters: The name of a product as a C-string, the quantity of that product and its cost. If it finds a product of the same name in its inventory, it should update that product's count and cost. If it doesn't find the product in its inventory, it should instantiate the product in a location without a product or a location whose product has been exhausted.
  • It should have a getBank() accessor function that returns the total of all purchases.
  • It should have a purchase() mutator function that takes a single parameter identifying the item to be purchased. It then purchases that item and adds the cost to the "bank".
  • It should have a getName() accessor function that takes a single parameter identifying the item. If the given location is invalid, it returns "Invalid selection". If no product is at the given location, it returns "Empty". Otherwise, it returns the name of the item as a C-string.
  • It should have a getCount() accessor function that takes a single parameter identifying the item. If the given location is invalid, it returns 0. If no product is at the given location, it returns 0. Otherwise, it returns the count of the item.
  • It should have a getCost() accessor function that takes a single parameter identifying the item. If the given location is invalid, it returns 0.0. If no product is at the given location, it returns 0.0. Otherwise, it returns the cost of the item.

My Code:

class Machine

{

public:

const char *Name;

double Bank;

double Purchase;

int Count;

int Restock;

double Cost;

Machine(int ProductLimit)

{

ProductLimit = 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!