defination of class register(header file) class cashRegister { public: int getCu
ID: 3540491 • Letter: D
Question
defination of class register(header file)
class cashRegister
{
public:
int getCurrentBalance() const;
void acceptAmount(int amountIn);
cashRegister(int cashIn = 500);
private:
int cashOnHand;
};
class dispenserType
{
public:
int getNoOfItems() const;
int getCost() const;
void makeSale();
dispenserType(int setNoOfItems = 50, int setCost = 50);
private:
int numberOfItems;
int cost;
};
defination of cashregister header file
#include<iostream>
using namespace std;
int cashRegister::getCurrentBalance() const
{
return cashOnHand;
}
void cashRegister::acceptAmount(int amountIn)
{
cashOnHand = cashOnHand + amountIn;
}
cashRegister::cashRegister(int cashIn)
{
if (cashIn >= 0)
cashOnHand = cashIn;
else
cashOnHand = 500;
}
int dispenserType::getNoOfItems() const
{
return numberOfItems;
}
int dispenserType::getCost() const
{
return cost;
}
void dispenserType::makeSale()
{
numberOfItems--;
}
dispenserType::dispenserType(int setNoOfItems, int setCost)
{
if (setNoOfItems >= 0)
numberOfItems = setNoOfItems;
else
numberOfItems = 50;
if (setCost >= 0)
cost = setCost;
else
cost = 50;
}
main.cpp
#include <iostream>
#include "juicemachinemodified.h"
#include "Juicemachinemodifieda.h"
#include<fstream>
using namespace std;
void showSelection();
void sellProduct(dispenserType& product,
cashRegister& pCounter);
void report();
int main()
{
ifstream inFile;
inFile.open("output.txt");
cashRegister counter;
dispenserType orange(100, 50);
dispenserType apple(100, 65);
dispenserType mango(75, 80);
dispenserType strawberryBanana(100, 85);
dispenserType Water(100,125);
dispenserType RaspberryBananaSmoothie(100,250);
int choice;
showSelection();
cin >>choice;
while (choice != 9)
{
switch (choice)
{
case 1:
sellProduct(orange, counter);
break;
case 2:
sellProduct(apple, counter);
break;
case 3:
sellProduct(mango, counter);
break;
case 4:
sellProduct(strawberryBanana, counter);
break;
case 5:
sellProduct(Water, counter);
case 6:
sellProduct(RaspberryBananaSmoothie, counter);
default:
cout << "Invalid selection." << endl;
}
showSelection();
cin >> choice;
}
//////need to show this in output file////
cout<<"Remaining number of juice in dispenser is given below"
<<" Name of juice" <<" Remainging";
cout <<" Orange" <<" " <<orange.getNoOfItems();
cout <<" Apple" <<" " <<apple.getNoOfItems();
cout <<" Mango" <<" " <<mango.getNoOfItems();
cout <<" Strawberry Banana" <<" " <<apple.getNoOfItems();
cout <<" Water(bottle) " <<" " <<Water.getNoOfItems();
cout <<" Raspberry Banana Smoothie" <<" " <<RaspberryBananaSmoothie.getNoOfItems() <<endl;
return 0;
system("pause");
}
void showSelection()
{
cout << "*** Welcome to Shelly's Candy 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<< "5 Water(bottle)"<<endl;
cout<< "6 Raspberry Banana Smoothie"<<endl;
cout << "9 to exit" << endl;
}
void sellProduct(dispenserType& product,
cashRegister& pCounter)
{
int amount;
int amount2;
if (product.getNoOfItems() > 0)
{
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;
}
if (amount >= product.getCost())
{
pCounter.acceptAmount(amount);
product.makeSale();
cout << "Collect your item at the bottom and "
<< "enjoy." << endl;
}
else
cout << "The amount is not enough. "
<< "Collect what you deposited." << endl;
cout << "*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"
<< endl << endl;
}
else
cout << "Sorry, this item is sold out." << endl;
}
Explanation / Answer
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.