Question
Modify the Code(s) below so that it satisfies the Information required above Cpp file #include #include #include CokeMachine.h using namespace std; void menu() { cout
Modify the Code(s) below so that it satisfies the Information required above
Cpp file
#include
#include
#include "CokeMachine.h"
using namespace std;
void menu()
{
cout
}
int main()
{
CokeMachine MyCokeMachine("CSE 1325 Coke Machine", 50, 500, 100);
int option;
do
{
menu();
cout
cin>>option;
if(option==1)
{
int payment;
cout
cin>>payment;
if(MyCokeMachine.buyACoke(payment))
{
if(payment==MyCokeMachine.getCokePrice())
cout
else
{
cout
}
}
else
{
if(payment
{
cout
}
else
cout
}
}
else if(option==2)
{
int products;
cout
cin>>products;
if(MyCokeMachine.incrementInventory(products))
cout
else
cout
cout
}
else if(option==3)
{
int amount;
cout
cin>>amount;
if(MyCokeMachine.incrementChangeLevel(amount))
{
cout
}
else cout
cout
}
else if(option==4)
{
cout
cout
cout
cout
}
else if(option!=0)
cout
} while(option!=0);
return 0;
}
Header File
#ifndef COKEMACHINE_H_INCLUDED
#define COKEMACHINE_H_INCLUDED
#include
using namespace std;
class CokeMachine
{
private:
string machineName;
int changeLevel,maxChangeCapacity,CokePrice,inventoryLevel,maxinventoryCapacity;
public:
CokeMachine(string machine_name, int Coke_Price, int change_Level, int inventory_Level)
{
machineName = machine_name;
CokePrice = Coke_Price;
changeLevel = change_Level;
inventoryLevel = inventory_Level;
maxChangeCapacity = 5000;
maxinventoryCapacity = 100;
}
string getMachineName()
{
return machineName;
}
bool buyACoke(int payment)
{
if(payment==CokePrice)
{
inventoryLevel--;
return true;
}
else if(payment>CokePrice)
{
if(changeLevel>=payment-CokePrice)
{
changeLevel -= (payment-CokePrice);
inventoryLevel--;
return true;
}
}
return false;
}
int getInventoryLevel()
{
return inventoryLevel;
}
int getMaxInventoryCapacity()
{
return maxinventoryCapacity;
}
bool incrementInventory(int amountToAdd)
{
if(amountToAdd+inventoryLevel>getMaxInventoryCapacity())
return false;
else
{
inventoryLevel += amountToAdd;
return true;
}
}
int getChangeLevel()
{
return changeLevel;
}
bool incrementChangeLevel(int amountToAdd)
{
if(maxChangeCapacity>=amountToAdd+changeLevel)
{
changeLevel += amountToAdd;
return true;
}
else
return false;
}
int getMaxChangeCapacity()
{
return maxChangeCapacity;
}
int getCokePrice()
{
return CokePrice;
}
string displayMoney(int amount)
{
return ""+amount;
}
};
#endif // COKEMACHINE_H_INCLUDED
Additional Information about the using of action in buyACoke ) buyACoke () returns true/false to indicate whether or not the function worked. buyACoke() also sets action to different values depending on what happened while executing the code in buyACoke) For example, if a Coke costs $0.50 and a payment of 30 cents is entered, then buyACoke () will fail but your .cpp program needs to know why so it can print a message to inform the user what went wrong-your .cpp program needs to know what action to take. buyACoke () would assign a specific value to action that would relay back to your .cpp program what happened so that it can print a message about it. For example, buyACoke () if payment is insufficient, then action would be set to 3 (for example) .cpp program get action back from buyACoke () and print a message about insufficient funds because action is3 You will need to define multiple values for action to mean the various actions that your.cpp program needs to take based on what happened when buyACoke () was called. I used an enumerated type so that I could use words instead of numbers to make my code easier to read. enum ACTION OK, NOINVENTORY, NOCHANGE, INSUFFICIENTFUNDS, EXACTCHANGE
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