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 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,...
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...
Problem Specification:Write a C++ program to calculate student’s GPA for the semester in your class. For each student,the program should accept a student’s name, ID number and the number of courses he/she istaking, then for each course the following data is needed the course number a string e.g. BU 101 course credits “an integer” grade received for the course “a character”.The program should display each student’s information and their courses information. It shouldalso display the GPA for the semester. The...
write a code on .C file Problem Write a C program to implement a banking application system. The program design must use a main and the below functions only. The program should use the below three text files that contain a set of lines. Sample data of these files are provided with the assessment. Note that you cannot use the library string.h to manipulate string variables. For the file operations and manipulations, you can use only the following functions: fopen(),...
programming language: C++ *Include Line Documenatations* Overview For this assignment, write a program that will simulate a game of Roulette. Roulette is a casino game of chance where a player may choose to place bets on either a single number, the colors red or black, or whether a number is even or odd. (Note: bets may also be placed on a range of numbers, but we will not cover that situation in this program.) A winning number and color is...