1. Regular Track Write a C+ OOP simul two classes. One must be general vending m
ID: 3709425 • Letter: 1
Question
1. Regular Track Write a C+ OOP simul two classes. One must be general vending machine. The other can be either vending machine of soda, or vending machine of snack. These vending machines should have following components and functions. program that simulates a vending machine. The program should define at least » Coin slot o Allow adding coins o Display total coin amount (in cents or dollars) o Minimum requirement: enable quarter dropping * Merchandise selection pad o One item each transaction o Minimum: five items for selection . Main panel o Display the status of the transaction, such as balance of deposited fund, what have been purchased, what remain for sale, etc. Display error messages. o Your program must utilizes at least two of following three syntactical elements oOp recursion » function In addition, your program must implement all three major C++ OOP features: . Encapsulation » Inheritance * Code separation (between definition and implementation) The adoption of polymorphism (more specifically dynamic binding) is encouraged but not requiredExplanation / Answer
EXECUTABLE CODE
#include <iostream>
#include <map>
using namespace std;
enum stypes
{
GRAPES =1,
STRABERRY=2,
SPRITE= 3,
MANGO = 4,
BLACKBERRY =5
};
class VendingMachine
{
private:
int coinAmount;
map <int, int> sodaTypes;
map <int, int > itemsCount;
public:
VendingMachine();
void setCoinAmount(int amount);
double getCoinAmount();
map <int,int> getSodaTypes();
map <int,int> eachMaxItemsCount();
void showItems();
void displayErrorMessage(string);
~VendingMachine();
};
VendingMachine :: VendingMachine()
{
sodaTypes[1]=5;
sodaTypes[2]=6;
sodaTypes[3]=7;
sodaTypes[4]=6;
sodaTypes[5]=10;
itemsCount[1]=20;
itemsCount[2]=20;
itemsCount[3]=20;
itemsCount[4]=20;
itemsCount[5]=20;
coinAmount=0.0;
}
map <int,int> VendingMachine :: eachMaxItemsCount()
{
return itemsCount;
}
map <int,int> VendingMachine:: getSodaTypes()
{
return sodaTypes;
}
void VendingMachine :: showItems()
{
cout << " Types of soda " <<endl;
cout << " 1. GRAPES " <<endl;
cout << " 2. STRABERRY " <<endl;
cout << " 3. SPRITE " <<endl;
cout << " 4. MANGO " <<endl;
cout << " 5. BLACKBERRY " <<endl;
}
double VendingMachine :: getCoinAmount()
{
return coinAmount;
}
void VendingMachine :: setCoinAmount(int amount)
{
coinAmount += amount;
}
void VendingMachine :: displayErrorMessage(string msg)
{
cout << "Erro Message : "<<msg<<endl;
}
VendingMachine :: ~VendingMachine()
{
}
class Soda : public VendingMachine
{
int item;
int price;
map <int,int > itemsCount;
map <int,int> types;
public:
Soda();
void displayCoinAmount();
bool enableQuater();
void selectionPad();
void addCoins();
void statusTransaction(bool);
};
Soda :: Soda()
{
}
void Soda :: addCoins()
{
cout << " Please Add Coins : ";
cin >> price;
}
void Soda :: displayCoinAmount()
{
cout << " Total Coin Amount : "<< getCoinAmount()<<endl;
}
void Soda :: statusTransaction(bool status)
{
if(status)
{
cout << "Soda is Dispached ... !" <<endl;
if(item == 1)
{
cout << " Taken Item : GRAPES Soda "<<endl;
}
else if(item == 2)
cout << " Taken Item : STRABERRY Soda "<<endl;
else if(item == 3)
cout << " Taken Item : SPRITE Soda "<<endl;
else if(item == 4)
cout << " Taken Item : MANGO Soda "<<endl;
else if(item == 1)
cout << " Taken Item : BLACKBERRY Soda "<<endl;
cout << "Balace Deposited amount : " << price - types[item] <<endl;
cout << "Remain Items for Sale : " <<endl;
cout << " GRAPES Soda "<<itemsCount[1]<<endl;
cout << " STRABERRY Soda "<<itemsCount[2]<<endl;
cout << " SPRITE Soda "<<itemsCount[3]<<endl;
cout << " MANGO Soda "<<itemsCount[4]<<endl;
cout << " BLACKBERRY Soda "<<itemsCount[5]<<endl;
}
}
bool Soda :: enableQuater()
{
if(itemsCount[item] == 0)
return false;
--itemsCount[item];
setCoinAmount(price);
return true;
}
void Soda :: selectionPad()
{
types = getSodaTypes();
itemsCount= eachMaxItemsCount();
cout << GRAPES << "" << types[2]<<endl;
addCoins();
cout << " Select Item which you need " <<endl;
cin >> item;
bool status;
//price =100;
//item = 1;
for(int i=1;i<6;i++)
{
if(i== item)
{
if(price < types[item] )
displayErrorMessage("Insufficent coins inserted...");
else if(itemsCount[item] == 0)
displayErrorMessage("Item is Over...");
else
{
status = enableQuater();
statusTransaction(status);
}
}
}
}
int main()
{
Soda obj;
obj.showItems();
obj.selectionPad();
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.