Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 less than 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

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_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

1. Are my sources credible?

Answered: 1 week ago