Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I'm trying to create a product class for a vending machine that manage the name of the product, the quantity of the product available and
I'm trying to create a product class for a vending machine that manage the name of the product, the quantity of the product available and the cost of the product.
- Its constructor should initialize the fields. The name field should be a C-string.
- It should have a getName() accessor function that returns the name of the product as a C-string if there is one or more of the product available. Otherwise, it returns "Empty".
- It should have a getCount() accessor function that returns the quantity of the product available.
- It should have a getCost() accessor function that returns the cost of the product if there is one or more of the product available. Otherwise, it returns 0.0.
- It should have a purchase() mutator function that decrements the quantity of the product and returns the cost of the product if there is one or more of the product available. Otherwise, it returns 0.0.
- It should have a restock() mutator function that adds the value of its one parameter to the quantity of the product.
- It should have a setCost() mutator function that changes the product's cost to its one parameter.
My Code:
class Product
{
public:
int Count;
double Cost;
int purchase;
int restock;
Product(string Name)
{
Name = "name";
}
string getName()
{
if(getName().empty()){
cout << "Empty";
}
else {
return Name;
}
}
int getCount()
{
return Count;
}
};
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