C++ PROGRAM:
#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 << "\n Please Add Coins : ";
cin >> price;
}
void Soda :: displayCoinAmount()
{
cout << "\n 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 << "\nSelect Item which you need " <<endl;
cin >> item;
bool status;
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;
}
Write a C+OOP program that simulates a vending machine. The program should define at least two...
Write a program in Java that simulates a vending machine: The vending machine sells three types of food: 1) Potato chips $1.25; 2) Cookies $0.85; 3) Candies $0.95. The program will prompt for the buyer to enter the amount in quarters (25 cents), dimes (10 cents), and nickels (5 cents). The program will then present a selection menu for the foods and prompt the buyer to enter the amount of quarters, dimes and nickels. The machine would then proceed to...
Please Walk me through this problem. Write a program that simulates the functionality of a vending machine having the following characteristics: The vending machine offers 5 products The vending machine accepts coins, 1 dollar bills, and 5 dollar bills The change is always given in coins, with maximum possible number of coins in each value: 25, 10, 5 or 1 cent. The selections available for user are numbers from 1 to 5. The user enters the money – simulate the...
Write in java as simple as possible coding..
) Object-Oriented Design 7 Write a program that simulates a vending machine. Products can be purchased by inserting coins with a value at least equal to the cost of the product. A user selects product from a list of available products, adds coins, and either gets the productor gets the coins returned. The coins are returned if insufficient money was supplied or if the product is sold out. The machine does not...
1. Create a new multi-class Java program which implements a vending machine simulator which contains the following functionality: A) At program startup, the vending machine is loaded with a variety of products in a variety of packaging for example soda/tonic/Coke in bottles, peanuts in bags, juice in cartons, etc. Also included is the cost of each item. The program should be designed to easily load a different set of products easily (for example, from a file). Also at program startup,...
write a program in C that determines the change to be dispensed from a vending machine. An item in the machine can cost between 25 cents and a dollar, in a 5-cent increments(25,30,35.....,90,95,or 100), and the machine accepts only a single dollar bill to pay for the item. for example a possible dialogue with the user might be "Enter price of item (from 25 cents to a dollar, in 5-cent increments):45 you boughtan item for 45 cents and gave me...
program Java oop
The project description As a programmer; you have been asked to write a program for a Hospital with the following The Hospital has several employees and each one of them has an ID, name, address, mobile number, email and salary. . The employees are divided into Administration staff: who have in addition to the previous information their position. Nurse: who have their rank and specialty stored in addition to the previous o o Doctor: who have the...
C++ HW Question Your program will simulate a simple change maker for a vending machine. It will start with a stock of coins and dollars. It will then repeatedly request the price for an item to be purchased or to quit. If given a price, it will accept nickels, dimes, quarters, one-dollar and five-dollar bills—deposited one at a time—in payment. When the user has deposited enough to cover the cost of the item, the program will calculate the coins to...
Write a program in C++ that simulates a soft drink machine. The program will need several classes: DrinkItem, DrinkMachine and Receipt. For each of the classes you must create the constructors and member functions required below. You can, optionally, add additional private member functions that can be used for doing implementation work within the class. DrinkItem class The DrinkItem class will contains the following private data members: name: Drink name (type of drink – read in from a file). Type...
Written in Java Your job is to produce a program that sorts a list of numbers in ascending order. Your program will need to read-in, from a file, a list of integers – at which point you should allow the user an option to choose to sort the numbers in ascending order via one of the three Sorting algorithms that we have explored. Your program should use the concept of Polymorphism to provide this sorting feature. As output, you will...
‘C’ programming language question Write a MENU DRIVEN program to A) Count the number of vowels in the string B) Count the number of consonants in the string C) Convert the string to uppercase D) Convert the string to lowercase E) Display the current string X) Exit the program The program should start with a user prompt to enter a string, and let them type it in. Then the menu would be displayed. User may enter option in small case...