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
  • Write a program in Java that simulates a vending machine: The vending machine sells three types...

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

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

  • ) 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,...

  • write a program in C that determines the change to be dispensed from a vending machine....

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

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