#include "VendingMachine.h" #include #include using namespace std; VendingMachine::VendingMachine(void) { for (int i=0; i < NUM_TYPES; i ++) sodaCount[i] = MAX_CANS; names[0] = "Coke"; names[1] = "Diet Coke"; names[2] = "Sprite"; names[3] = "Cherry Coke"; names[4] = "Yoohoo"; names[5] = "Grape Soda"; cash = 0; cout << "I'm alive." << endl; } VendingMachine::~VendingMachine() { for (int i=0; i < NUM_TYPES; i ++) sodaCount[i] = 0; cash = 0; cout << "Going offline now." << endl; } void VendingMachine::DisplayTypes(void) { for (int i=0; i < NUM_TYPES; i++) if (sodaCount[i] > 0) cout << i << " : " << names[i] << endl; } void VendingMachine::Vend (int type) { if (sodaCount[type] <= 0) cout << "ERROR - there are no " << names[type] << "s available." << endl; else { sodaCount[type]--; cash += 0.75; cout << "Enjoy your " << names[type] << "!" << endl; } } void VendingMachine::Stock (int type) { sodaCount[type] = MAX_CANS; cout << names[type] << " all stocked!" << endl; } void VendingMachine::WithdrawCash() { cout << "$" << cash << " emptied from the machine." << endl; cash = 0; }