Question

Write a C+OOP program that simulates a vending machine. The program should define at least two classes. Less than two classes will result in 20 points deduction. (30 points) One must be general vending machine (50 points) The other can be either vending machine of soda, or vending machine of snack. It must be a subclass of above general machine These vending machines should have following components and functions e Coin slot o Allow adding coins o Display total coin amount (in cents or dollars) 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 o Display erro messages Your program must utilizes at least two of following three syntactical elements loop e recursion e function Missing anyone will cause deduction of 10 points. In addition, your program must implement following three major OOP features in C++: Encapsulation Inheritance Code separation (between definition and implementation) e Missing of anyone will result in deduction of 15 points. The adoption of polymorphism (more specifically dynamic binding) is encouraged but not required
0 0
Add a comment Improve this question Transcribed image text
Answer #1

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;
}

Add a comment
Know the answer?
Add Answer to:
Write a C+OOP program that simulates a vending machine. The program should define at least two...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • ) Object-Oriented Design 7 Write a program that simulates a vending machine. Products can be purc...

    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...

    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 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...

    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...

    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...

    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...

    ‘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...

    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...

    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...

    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...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT