Question
Modifiy the code below so it applies to the rules above CokeMachine cpp: using namespace std; int menu() { cout } int main() { CokeMachine
Modifiy the code below so it applies to the rules above
CokeMachine cpp:
using namespace std;
int menu() {
cout
}
int main() {
CokeMachine MyCokeMachine("CSE 1325 Coke Machine", 50, 500, 100);
int option;
do { cout
menu();
cout
cin>>option;
cout
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; } CokeMachine H 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; } std::string displayMoney(int amount) const { std::string dollars{std::to_string(amount / 100)}; std::string cents{std::to_string(std::abs(amount % 100))}; return dollars + "." + (cents.size() == 1 ? "0" : "") + cents; } }; #endif MakeFile: SRC = OBJ = $(SRC:.cpp=.o) EXE = $(SRC:.cpp=.e) HFILES = CokeMachine.h CFLAGS = -g -std=c++11 all : $(EXE) $(EXE): $(OBJ) g++ $(CFLAGS) $(OBJ) -o $(EXE) $(OBJ) : $(SRC) $(HFILES) g++ -c $(CFLAGS) $(SRC) -o $(OBJ) Cokelib CPP: // Coke Library #include "CokeLib.h" bool ParseCokeLine(const std::string& CokeMachineLine, std::vector<:string>& params) { int x = 0, z = 0, i = 0; if (CokeMachineLine.length() == 0) { return false; } else { while (z { x = CokeMachineLine.find("|", z) - z; params[i++] = CokeMachineLine.substr(z, x); z += params[i-1].length() + 1; } } return true; } CokeLIb.h: #ifndef COKE_LIB_H #define COKE_LIB_H #include #include bool ParseCokeLine(const std::string& CokeMachineLine, std::vector<:string>& params); #endif InputCokeFile: Machine Bugs Bunny|50|500|50 Machine Cecil Turtle|45|545|45 Machine Daffy Duck|40|540|1 Machine Elmer Fudd|100|1000|10 Machine Fog Horn|35|350|99
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