Modify the 6 th Edition Chapter 10 Programming Example Juice Machine program to
ID: 3560252 • Letter: M
Question
Modify the 6th Edition Chapter 10 Programming Example Juice Machine program to add two new dispensers:
Also print a report at the completion of the program that shows what was sold and the status of each dispenser.
Required for program
Main
Program
//*****************************************************
// Author: D.S. Malik
//
// This program uses the classes cashRegister and
// dispenserType to implement a juice machine.
// ****************************************************
#include
#include "juiceMachine.h"
using namespace std;
void showSelection();
void sellProduct(dispenserType& product,
cashRegister& pCounter);
int main()
{
cashRegister counter;
dispenserType orange(100, 50);
dispenserType apple(100, 65);
dispenserType mango(75, 80);
dispenserType strawberry banana(100, 85);
int choice; //variable to hold the selection
showSelection();
cin >> choice;
{
switch (choice)
{
case 1:
sellProduct(orange, counter);
break;
case 2:
sellProduct(apple, counter);
break;
case 3:
sellProduct(mango, counter);
break;
case 4:
sellProduct(strawberry banana, counter);
break;
default:
cout << "Invalid selection." << endl;
}//end switch
showSelection();
cin >> choice;
}//end while
return 0;
}//end main
void showSelection()
{
cout << "*** Welcome to Shelly's Juice Shop ***" << endl;
cout << "To select an item, enter " << endl;
cout << "1 for orange juice" << endl;
cout << "2 for apple juice" << endl;
cout << "3 for mango juice" << endl;
cout << "4 for strawberry banana" << endl;
cout << "9 to exit" << endl;
}//end showSelection
void sellProduct(dispenserType& product,
cashRegister& pCounter)
{
int amount; //variable to hold the amount entered
int amount2; //variable to hold the extra amount needed
if (product.getNoOfItems() > 0) //if the dispenser is not
//empty
{
cout << "Please deposit " << product.getCost()
<< " cents" << endl;
cin >> amount;
if (amount < product.getCost())
{
cout << "Please deposit another "
<< product.getCost()- amount
<< " cents" << endl;
cin >> amount2;
amount = amount + amount2;
}
Explanation / Answer
// QandA.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
void showSelection();
void sellProduct(dispenserType& product, cashRegister& pCounter);
int main()
{
cashRegister counter;
dispenserType orange(100, 50);
dispenserType apple(100, 65);
dispenserType mango(75, 80);
dispenserType strawberry banana(100, 85);
int choice; //variable to hold the selection
showSelection();
cin >> choice;
{
switch (choice)
{
case 1:
sellProduct(orange, counter);
break;
case 2:
sellProduct(apple, counter);
break;
case 3:
sellProduct(mango, counter);
break;
case 4:
sellProduct(banana, counter);
break;
default:
cout << "Invalid selection." << endl;
}//end switch
showSelection();
cin >> choice;
}//end while
system("pause");
return 0;
}//end main
void showSelection()
{
cout << "*** Welcome to Shelly's Juice Shop ***" << endl;
cout << "To select an item, enter " << endl;
cout << "1 for orange juice" << endl;
cout << "2 for apple juice" << endl;
cout << "3 for mango juice" << endl;
cout << "4 for strawberry banana" << endl;
cout << "9 to exit" << endl;
}//end showSelection
void sellProduct(dispenserType& product, cashRegister& pCounter)
{
int amount; //variable to hold the amount entered
int amount2; //variable to hold the extra amount needed
if (product.getNoOfItems() > 0)
//if the dispenser is not empty
{
cout << "Please deposit " << product.getCost()
<< " cents" << endl;
cin >> amount;
if (amount < product.getCost())
{
cout << "Please deposit another "<< product.getCost()- amount<< " cents" << endl;
cin >> amount2;
amount = amount + amount2;
}
class cashRegister
{
private: int cashOnHand;
public:
int getCurrentBalance() const;
//Function to show the current amount in the cash
//register.
//Postcondition: The value of cashOnHand is returned.
void acceptAmount(int amountIn);
//Function to receive the amount deposited by
//the customer and update the amount in the register.
//Postcondition: cashOnHand = cashOnHand + amountIn;
cashRegister(int cashIn = 500);
//Constructor
//Sets the cash in the register to a specific amount.
//Postcondition: cashOnHand = cashIn;
// If no value is specified when the
// object is declared, the default value
// assigned to cashOnHand is 500.
};
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.