Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The code won't run in xcode. //main.cpp #include #include #include #includeInventory.h #includeMoney.h using namespace std; Money report; Inventory InventoryReport; void menuFunction(int &, double &); void

The code won't run in xcode.

//main.cpp #include #include #include #include"Inventory.h" #include"Money.h"

using namespace std; Money report; Inventory InventoryReport; void menuFunction(int &, double &); void totalMoney(); void EnterCoin(double &); void returnChange(double &); void displayReturnChange(); double checkValidCoin(double &);

int main() {

int selection=0, turnMachineOn; int decreaseQuantitByOne = 1; double enterAmount, totalAmount = 0, returnAmount = 0; double price; int toBuyMore;

do { cout << "Enter 1 - To turn Machine ON. "; cin >> turnMachineOn;

if (turnMachineOn == 1) { do { toBuyMore = 0; InventoryReport.setDefaultInventory(); menuFunction(selection, price); // coke if (selection == 1) { InventoryReport.setCokeInventory(decreaseQuantitByOne); do { cout << "Insert Coin / Bill = $"; cin >> enterAmount; checkValidCoin(enterAmount); EnterCoin(enterAmount); totalAmount += enterAmount; } while (totalAmount <= price); returnAmount = totalAmount - price; returnChange(returnAmount); }// Doritos else if (selection == 2) { InventoryReport.setDoritosInventory(decreaseQuantitByOne); do { cout << "Insert Coin / Bill = $"; cin >> enterAmount; checkValidCoin(enterAmount); EnterCoin(enterAmount); totalAmount += enterAmount; } while (totalAmount <= price); returnAmount = totalAmount - price; returnChange(returnAmount); }// snickers else if (selection == 3) { InventoryReport.setSnickersInventory(decreaseQuantitByOne); do { cout << "Insert Coin / Bill = $"; cin >> enterAmount; checkValidCoin(enterAmount); EnterCoin(enterAmount); totalAmount += enterAmount; } while (totalAmount <= price); returnAmount = totalAmount - price; returnChange(returnAmount); }//chex mix else if (selection == 4) { InventoryReport.setChexMixInventory(decreaseQuantitByOne); do { cout << "Insert Coin / Bill = $"; cin >> enterAmount; checkValidCoin(enterAmount); EnterCoin(enterAmount); totalAmount += enterAmount; } while (totalAmount <= price); returnAmount = totalAmount - price; returnChange(returnAmount); }//pepsi else if (selection == 5) { InventoryReport.setPepsiInventory(decreaseQuantitByOne); do { cout << "Insert Coin / Bill = $"; cin >> enterAmount; checkValidCoin(enterAmount); EnterCoin(enterAmount); totalAmount += enterAmount; } while (totalAmount <= price); returnAmount = totalAmount - price; returnChange(returnAmount); } displayReturnChange(); report.setReturnCoinDefault(); returnAmount = 0; totalAmount = 0;

cout << "Do you want to purchase anything else (press 1 - yes and 0 - no) = "; cin >> toBuyMore; cout << endl; } while (toBuyMore == 1);

totalMoney(); cout << endl; cout << "Do you want to turn off the machine again enter 1- yes and 2 - no = "; cin >> turnMachineOn;

if (turnMachineOn == 1)break;

} else { cout << "Inapproprite selection to turn Machine ON. Try again. Thank you! "; cout << "Do you want to try to start machine again enter 1- yes and 2 - no = "; cin >> turnMachineOn; } } while (turnMachineOn == 1); system("pause"); return 0; }

// check if inserted coin is valid or not double checkValidCoin(double &money) {

if (money != 0.25 && money != 0.1 && money != 0.05 && money != 1 && money != 5) { cout << "Invalid! Insert Valid Coin / Bill Again = $"; cin >> money; } return money; }

// deduct the return amount from the total amount in the machine void returnChange(double &money) { double returnAmount = 0; double value = 0; if (money >= 0.25 && money <= 0.99) { value = 0.25; report.setReturnQuater(value); returnAmount = money - 0.25; //cout << "Return amount = $" << 0.25 << endl; returnChange(returnAmount); } else if (money >= 0.10 && money <= 0.24) { value = 0.10; report.setReturnDime(value); returnAmount = money - 0.1; //cout << "Return amount = $" << 0.10 << endl; returnChange(returnAmount);

} else if ((money <= 0.05 && money >= 0.01) || (money >= 0.05 && money <= 0.09)) { value = 0.05; report.setReturnNickle(value); returnAmount = money - 0.05; //cout << "Return amount = $" << 0.05 << endl; returnChange(returnAmount);

} else if (money >= 1 && money <= 4.99) { value = 1; report.setReturnOneDollar(value); returnAmount = money - 1; //cout << "Return amount = $" << 1 << endl; returnChange(returnAmount);

} else if (money >= 5) { value = 5; report.setReturnFiveDollar(value); returnAmount = money - 5; //cout << "Return amount = $" << 5 << endl; returnChange(returnAmount); } }

// display the return change by its type void displayReturnChange() { cout << " Return Change. "; cout << "Quaters = $" << report.getReturnQuater() << endl; cout << "Dimes = $" << report.getReturnDime() << endl; cout << "Nickles = $" << report.getReturnNickle() << endl; cout << "One Dollar = $" << report.getReturnOneDollar() << endl; cout << "Five Dollar = $" << report.getReturnFiveDollar() << endl << endl; }

// enter the coin to machine and set it void EnterCoin(double &money) {

if (money == 0.25) { report.setQuater(money); } if (money == 0.10) { report.setDime(money); } if(money == 0.05) { report.setNickle(money); } if (money == 1) { report.setOneDollar(money); } if (money == 5) { report.setFiveDollar(money); } }

// display the total amount of money in the machine void totalMoney() { cout << "Total Amount In Machine. "; cout << "Quater = $" << report.getQuater() - report.getReturnQuater() << ", Total Quater = $" << report.getTotalQuater()<< endl; cout << "Dime = $" << report.getDime() - report.getReturnDime() << ", Total Dime = $" << report.getTotalDime() << endl; cout << "Nickle = $" << report.getNickle() - report.getReturnNickle() << ", Total Nickle = $" << report.getTotalNickle() << endl; cout << "One Dollar = $" << report.getOneDollar() - report.getReturnOneDollar() << ", Total One Dollar = $" << report.getTotalOneDollar() << endl; cout << "Five Dollar = $" << report.getFiveDollar() - report.getReturnFiveDollar() << ", Total Five Dollar = $" << report.getTotalFiveDollar() << endl; }

// diplsay the list of menu on calling void menuFunction(int &selection, double &price) {

cout << "Here is the list of Product in the Vending Machine. "; cout << "1. Coke - $0.95 "; cout << "2. Doritos - $0.75 "; cout << "3. Snickers - $0.55 "; cout << "4. Chex Mix - $0.60 "; cout << "5. Pepsi - $0.90 ";

cout << "Enter you selection = "; cin >> selection; switch (selection) { case 1: price = 0.95; break; case 2: price = 0.75; break; case 3: price = 0.55; break; case 4: price = 0.60; break; case 5: price = 0.90; break; default: cout << "wrong selection, please try again. Thank you! "; break; } } -------------------------------------------------------------------------------------------------------

//Inventory.cpp #include "Inventory.h"

Inventory::Inventory() { } void Inventory::setDefaultInventory() { if (cokeInventory <= 5) cokeInventory = 30; if (doristosInventory <= 5) doristosInventory = 30; if (snickersInventory <= 5) snickersInventory = 30; if (chexMixInventory <= 5) chexMixInventory = 30; if (pepsiInventory <= 5) pepsiInventory = 30; } // coke void Inventory::setCokeInventory(int &buy) { cokeInventory = cokeInventory -buy;

} int Inventory::getCokeInventory() { return cokeInventory; } // doritos void Inventory::setDoritosInventory(int &buy) { doristosInventory = doristosInventory - buy; } int Inventory::getDoritosInventory() { return doristosInventory; } // snickers void Inventory::setSnickersInventory(int &buy) { snickersInventory = snickersInventory - buy; } int Inventory::getSnickersInventory() { return snickersInventory; } // chex mix void Inventory::setChexMixInventory(int &buy) { chexMixInventory = chexMixInventory - buy; } int Inventory::getChexMixInventory() { return chexMixInventory; } // pepsi void Inventory::setPepsiInventory(int &buy) { pepsiInventory = pepsiInventory - buy; } int Inventory::getPepsiInventory() { return pepsiInventory; }

Inventory::~Inventory() { } ------------------------------------------------------------------------ //Inventory.h #pragma once class Inventory { private: int cokeInventory=0; int doristosInventory=0; int snickersInventory=0; int chexMixInventory=0; int pepsiInventory=0; public: Inventory(); void setDefaultInventory(); void setCokeInventory(int&); int getCokeInventory(); void setDoritosInventory(int&); int getDoritosInventory(); void setSnickersInventory(int&); int getSnickersInventory(); void setChexMixInventory(int&); int getChexMixInventory(); void setPepsiInventory(int&); int getPepsiInventory(); ~Inventory(); }; --------------------------------------------------------------------------- //Money.cpp #include "Money.h" #include using namespace std;

Money::Money() { } // if money excedded in machine then make it to default void Money::setDefaultQuater() {

if (Quater == 25) { totalQuater += Quater - 20; Quater = 5; } } double Money::getTotalQuater() { return totalQuater; } void Money::setDefaultDime() { if (Dime == 10) { totalDime += Dime - 5; Dime = 2; } } double Money::getTotalDime() { return totalDime; } void Money::setDefaultNickle() { if (Nickle == 5) { totalNickle += Nickle - 1; Nickle = 1; } } double Money::getTotalNickle() { return totalNickle; } void Money::setDefaultOneDOllar() { if (OneDollar == 100) { totalQOneDollar += OneDollar - 20; OneDollar = 20; } } double Money::getTotalOneDollar() { return totalQOneDollar; } void Money::setDefaultFiveDollar() { if (FiveDollar == 300) { totalFiveDolllar += FiveDollar - 100; FiveDollar = 100; } } double Money::getTotalFiveDollar() { return totalFiveDolllar; }

// input money void Money::setQuater(double &amount) { Quater += amount; } double Money::getQuater() { return Quater; } void Money::setDime(double &amount) { Dime += amount; } double Money::getDime() { return Dime; } void Money::setNickle(double &amount) { Nickle += amount; } double Money::getNickle() { return Nickle; } void Money::setOneDollar(double &amount) { OneDollar += amount; } double Money::getOneDollar() { return OneDollar; } void Money::setFiveDollar(double &amount) { FiveDollar += amount; } double Money::getFiveDollar() { return FiveDollar; }

// return change if money exceed the price of product void Money::setReturnQuater(double &amount) { returnQuater = Quater - amount; totalReturnQuater += amount; } double Money::getReturnQuater() { return totalReturnQuater; } void Money::setReturnDime(double &amount) { returnDime = Dime - amount; totalReturnDime += amount; } double Money::getReturnDime() { return totalReturnDime; } void Money::setReturnNickle(double &amount) { returnNickle = Nickle - amount; totalReturnNickle += amount; } double Money::getReturnNickle() { return totalReturnNickle; } void Money::setReturnOneDollar(double &amount) { returnOneDollar = OneDollar - amount; totalReturnOneDollar += amount; } double Money::getReturnOneDollar() { return totalReturnOneDollar; } void Money::setReturnFiveDollar(double &amount) { returnFiveDollar = FiveDollar - amount; totalReturnFiveDollar += amount; } double Money::getReturnFiveDollar() { return totalReturnFiveDollar; }

void Money::setReturnCoinDefault() { totalReturnQuater = 0; totalReturnDime = 0; totalReturnNickle = 0; totalReturnOneDollar = 0; totalReturnFiveDollar = 0; } Money::~Money() { } ----------------------------------------------------------------------------------- //Money.h #pragma once class Money { private: double Quater = 5, totalQuater = 0, returnQuater = 0, totalReturnQuater = 0; double Dime = 2, totalDime = 0, returnDime = 0, totalReturnDime = 0; double Nickle = 1, totalNickle = 0, returnNickle = 0, totalReturnNickle = 0; double OneDollar = 20, totalQOneDollar = 0, returnOneDollar = 0, totalReturnOneDollar = 0; double FiveDollar = 100, totalFiveDolllar=0, returnFiveDollar = 0, totalReturnFiveDollar = 0; public: Money(); // if the amount exceed by specific amount in the machine then make it default void setDefaultQuater(); double getTotalQuater(); void setDefaultDime(); double getTotalDime(); void setDefaultNickle(); double getTotalNickle(); void setDefaultOneDOllar(); double getTotalOneDollar(); void setDefaultFiveDollar(); double getTotalFiveDollar();

// increase the amount in the machine by accespting the coin void setQuater(double&); double getQuater(); void setDime(double&); double getDime(); void setNickle(double&); double getNickle(); void setOneDollar(double&); double getOneDollar(); void setFiveDollar(double&); double getFiveDollar();

// return the change void setReturnCoinDefault(); void setReturnQuater(double&); double getReturnQuater(); void setReturnDime(double&); double getReturnDime(); void setReturnNickle(double&); double getReturnNickle(); void setReturnOneDollar(double&); double getReturnOneDollar(); void setReturnFiveDollar(double&); double getReturnFiveDollar(); ~Money(); };

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

The Power Of Numbers In Health Care A Students Journey In Data Analysis

Authors: Kaiden

1st Edition

8119747887, 978-8119747887

More Books

Students also viewed these Databases questions