Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Modifiy the code below so it applies to the rules above CokeMachine cpp: using namespace std; int menu() { cout } int main() { CokeMachine

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

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

1. Create Code3 xxxxxxxxxx. cpp Copy your working version of Code2_xxxxxxxxxx.cpp to Code3_xxxxxxxxxx.cpp 2. Create CokeMachine.cpp Move the member function code out of the CokeMachine's class structure. Use the scope resolution operator to tie the prototypes left in the class definition to the actual member function code in CokeMachine.cpp. Only the function prototypes and data members should still reside in CokeMachine.h 3. Add include guard to CokeMachine.h Add aninclude guard to CokeMachine.h. Use the name COKE_MACHINE_H in your include guard. 4. makefile Download CokeLib. cppand CokeLib h from Blackboard. Do not alter these files. if you alter them to make your code work, then your code will fail when graded because the graders will not use your versions-they will be using the versions from Blackboard to grade your assignment. Be sure to add includes where needed to use the new function in CokeLib. Create a new makefile that can compile these 4 files and creates an executable named code3xxxcxxxxx e Code3_xxxxxxxxxx. cpp CokeMachine.cpp CokeLib.cpp CokeMachine.h 4. Add two new member functions - se tMachineName ) and setcokePrice(o Add a new member function called setMachineName. Add it as menu item 5, "Update Machine Name". Prompt the user "Enter a new machine name". Take in newMachineName and call setMachineName) with one string parameter of newMachineName and no return value. After calling member function, print "Machine name has been updated Add a new member function called setCokePrice(). Add it as menu item 6, "Update Coke Price". Prompt the user Enter a new Coke price". Take in newCokePrice and call setCokePrice) with one int parameter of newCokePrice and no return value. After calling member function, print "Coke price has been updated" 1. Create Code3 xxxxxxxxxx. cpp Copy your working version of Code2_xxxxxxxxxx.cpp to Code3_xxxxxxxxxx.cpp 2. Create CokeMachine.cpp Move the member function code out of the CokeMachine's class structure. Use the scope resolution operator to tie the prototypes left in the class definition to the actual member function code in CokeMachine.cpp. Only the function prototypes and data members should still reside in CokeMachine.h 3. Add include guard to CokeMachine.h Add aninclude guard to CokeMachine.h. Use the name COKE_MACHINE_H in your include guard. 4. makefile Download CokeLib. cppand CokeLib h from Blackboard. Do not alter these files. if you alter them to make your code work, then your code will fail when graded because the graders will not use your versions-they will be using the versions from Blackboard to grade your assignment. Be sure to add includes where needed to use the new function in CokeLib. Create a new makefile that can compile these 4 files and creates an executable named code3xxxcxxxxx e Code3_xxxxxxxxxx. cpp CokeMachine.cpp CokeLib.cpp CokeMachine.h 4. Add two new member functions - se tMachineName ) and setcokePrice(o Add a new member function called setMachineName. Add it as menu item 5, "Update Machine Name". Prompt the user "Enter a new machine name". Take in newMachineName and call setMachineName) with one string parameter of newMachineName and no return value. After calling member function, print "Machine name has been updated Add a new member function called setCokePrice(). Add it as menu item 6, "Update Coke Price". Prompt the user Enter a new Coke price". Take in newCokePrice and call setCokePrice) with one int parameter of newCokePrice and no return value. After calling member function, print "Coke price has been updated

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: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions