Question

In: Computer Science

C++ include a class called VendingMachine. A user can buy a bottle of water ($1.50), a...

C++

include a class called VendingMachine.

A user can buy a bottle of water ($1.50), a bottle of coffee ($2.00), a chip ($1.00), and a chocolate bar ($2.50) from the machine. The user can select several item(s) if the items are available from the machine. Furthermore, the user can de-select item(s) that are already selected.

After finishing the selection of item(s), the user can pay for the items with either a debit card (Valid PIN: 7777) or cash. A user should pay the item(s) selected just one trial and if the user fails to pay due to the incorrect PIN or insufficient cash amount, the machine should de-select all sections the user chose.

Note that an administrator of the machine can refill the machine or reset it to the initial status.

At the payment() function, if a user provides incorrect payment information such as an incorrect PIN or insufficient money amount, all selections the user chose should be de-selected.

At the payment() function, if a user didn’t select any items before, the function should return false because there’s nothing to pay.

Solutions

Expert Solution

#include <iostream>

#include<functional>

using namespace std;

int options;

double chips,water,coffee,chocolate bar,milk,cola,quantity_chips,quantity_water,quantity_coffee,quantity_chocolate bar,quantity_milk,quantity_cola,payment,pi,error,tax,final_cost;

void menu()

{

cout<<"welcome .. \n";

do {    cout<<"select from menu..\n";

<< "\t1 chips ... $1.00\n"

<< " \t2 water........$1.50\n"

<< "\t3 coffee.....$2.00\n"

  << "\t4 chocolate bar.........$2.50\n"

cout<<"enter your option: ";

cin>>option;

switch(option)

{ case 1: cout<<"quantity:";

cin>>quantity_chips;

chips=(1*quantity_chips); break;

case 2:

cout<<"quantity:";

cin>>quantity_water;

water=(1.50*quantity_water); break;

case 3:

cout<<"quantity";

cin>>quantity_coffee;

coffee=(2*quantity_cofffee); break;

case 4:

cout<<"quantity";

cin>>quantity_chocolate bar;

chocolate bar=(2.5*quantity_chocolate bar); break;

case 5:

void checkout(); break;

default:

cout<<"invalid option:"<<endln;

}

} while(option<5);

}

void checkout() {

if(quantity_chips>0||quantity_water>0||quantity_coffee>0||quantity_chocolate bar>0) {

total=(chips)+(water)+(coffee)+(chocolate bar);

cout<<"select payment option (1:debit card 2:cash):";

cin>>payment;

if(payment=1)

{ void debit card(); }

else if(payment=2) { void cash(); }

else { cout<<"unknown option, please try again later \n";

} } else { cout<<"please select atleast one item \n"; } }

void debitcard()

{

error=1;

cout<<"enter pin:";

cin>>pin;

if(pin=7777) {

void receipt(); } else {

while(error>=1) {

cout<<"invalid pin. tryagain:";

cin>>pin;

error++;

if(pin=7777)

{ void receipt(); }

else{ cout<<"we are sorry.. invalid card details \n";

return; } } } }

void receipt()

{ cout<< "this is your reciept:\n";

if(quantity_chips>0) {

cout<<"chips:1.00 x"<< quantity_chips<<"=$"<<chips<<endl; }

if(quantity_water>0){

cout<<" water : 1.50 x"<<quantity_water<<"=$"<<water<<endl; }

if (quantity_coffee>0){

cout<<"coffee:2.00 x"<<quantity_coffee<<"=$"<<coffee<<endl; }

if(quantity_chocolate bar>0) {

cout<<"chocolate bar:2.50 x"<<quantity_chocolate bar<<"=$"<<chocolate bar<<endl; }

tax=(total* .10);

final_cost=tax+total;

cout<<"tax(12.2%): $"<<tax<<endl;

cout<<"total:$"<<final_cost<<endl;

}

int main()

{  

menu();

checkout();

debitcard();

receipt();

return 0;

}


Related Solutions

Cola. You can get a quart bottle of cola for $1.50 or a liter bottle for...
Cola. You can get a quart bottle of cola for $1.50 or a liter bottle for $1.55. A. What is the price per volume of each? B. Which is the better buy in terms of price per volume? Round answers to 3 decimal places. ( Use a conversion factor to change liters to quarts, then quarts to ounces). List your work here.
C++ Assignment 1) Write a C++ program specified below: a) Include a class called Movie. Include...
C++ Assignment 1) Write a C++ program specified below: a) Include a class called Movie. Include the following attributes with appropriate types: i. Title ii. Director iii. Release Year iv. Rating (“G”, “PG”, “PG-13”, etc) - Write code that instantiates a movie object using value semantics as text: - Write code that instantiates a movie object using reference semantics: - Write the print_movie method code: - Write Constructor code: - Write Entire Movie class declaration
Problem Description: SavingsAccount Develop a C++ class declaration called SavingsAccount class that allows user to input...
Problem Description: SavingsAccount Develop a C++ class declaration called SavingsAccount class that allows user to input initial values of dollars and cents and then asks for deposits and withdrawals. The class should include the following information: Operations (Member Functions) 1. Default constructor that sets both dollars and cents to 0. 2. The constructor has 2 parameters that set dollars and cents to the indicated values. 3. Open account (with an initial deposit). This is called to put initial values in...
Implement a class called DoublyLinkedList. In the main function, instantiate the DoublyLinkedList class and make sure that there is a user loop and a menu so that the user can access all the list operators.
C++  Implement a class called DoublyLinkedList. In the main function, instantiate the DoublyLinkedList class and make sure that there is a user loop and a menu so that the user can access all the list operators. You should implement the following operators, and any others that you may deem best. DestroyList InitializeList GetFirst InsertFirst, InsertLast, Insert DeleteFirst, DeleteLast, Delete IsEmpty Length Print, ReversePrint
Assuming that a. you can buy a euro call with strike price of $1.50 for 3...
Assuming that a. you can buy a euro call with strike price of $1.50 for 3 cents b. you can sell a euro put at the same strike price for 4 cents c. the prevailing forward rate is $1.54 per euro d. the annual risk-free rate in the US is 6%. Show how arbitrageurs can generate riskless profit. Explain how the different prices will adjust
In Angel, you will find a class called Employee. This class should include a constructor which...
In Angel, you will find a class called Employee. This class should include a constructor which sets name to blanks and salary to $0.00 and a constructor which sets name to a starting name and salary to a set amount. Additionally, the class should include methods to set the name and salary and return the name and salary. Create another method to return the name and salary nicely formatted as a string (hint – research the toString method). You will...
In Angel, you will find a class called Employee. This class should include a constructor which...
In Angel, you will find a class called Employee. This class should include a constructor which sets name to blanks and salary to $0.00 and a constructor which sets name to a starting name and salary to a set amount. Additionally, the class should include methods to set the name and salary and return the name and salary. Create another method to return the name and salary nicely formatted as a string (hint – research the toString method). You will...
Write a Java class called GuessMyNumber that prompts the user for an integer n, tells the...
Write a Java class called GuessMyNumber that prompts the user for an integer n, tells the user to think of a number between 0 and n−1, then makes guesses as to what the number is. After each guess, the program must ask the user if the number is lower, higher, or correct. You must implement the divide-and-conquer algorithm from class. In particular, you should round up when the middle of your range is in between two integers. (For example, if...
Write a class in Java called 'RandDate' containing a method called 'getRandomDate()' that can be called...
Write a class in Java called 'RandDate' containing a method called 'getRandomDate()' that can be called without instantiating the class and returns a random Date between Jan 1, 2000 and Dec 31, 2010.
Create a class called clsTextProcessor.java. Your program should deliver the following: Asks the user for a...
Create a class called clsTextProcessor.java. Your program should deliver the following: Asks the user for a location of a text file, with (FileNotFound) exception handling: Keep asking for a valid file name and location If an invalid file is provided, display an error message. Once provided, proceed. Opens the text file and finds the following: Minimum value Maximum value The average value of all number in the text Prints a message displaying the values in step No. 2
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT