Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Program in Language Arm Assembly code. Soft Drink Machine. Write a program which

ID: 3871051 • Letter: P

Question

Program in Language Arm Assembly code.

Soft Drink Machine. Write a program which simulates the operation of a soft drink machine. The machine will dispense, upon reception of the correct amount of change of 55 cents, a choice of Coke, Sprite, Dr. Pepper, Diet Coke, or Mellow Yellow. The program should accept only nickels, dimes, quarters, and one dollar bills, and return any excess amount of change. Also allow the customer (user) to switch his or her mind on purchasing a soft drink. Currency belonging to the set of acceptable correct change includes nickels, dimes, quarters, and one dollar bills. Like the actions of a real soft drink machine, this program will be interactive. Input to the program will be read from the keyboard and output will be displayed to the screen. Prompt the user with an initial message describing the choices of soft drinks

Explanation / Answer


#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
#include <cctype>
using namespace std;
struct Machine
{
string name;
double cost;
int num;
};
void init(Machine []);
int menu(Machine[]);
void payment(double);
int main()
{
Machine drink[5];
int choice;
double made=0;
init(drink);
choice=menu(drink);
while(choice!=5)
{
payment(drink[choice].cost);
made+=drink[choice].cost;
drink[choice].num--;
choice=menu(drink);
}
cout<<"Today the machine has made $"<<setprecision(2)<<fixed<<made<<endl;
system("pause");
return 0;
}
void payment(double p)
{
double pay;
cout<<"Your drink costs $"<<setprecision(2)<<fixed<<p<<endl;
cout<<"Enter payment: ";
cin>>pay;
while(pay<0||pay>1.||pay<p)
{
cout<<"please insert the correct amount for your drink! ";
cout<<"maximum payment is $1.00 ";
cout<<"Enter payment: ";
cin>>pay;
}
cout<<"Your change is: $"<<setprecision(2)<<fixed<<pay-p<<endl;
return;
}
void init(Machine d[])
{
ifstream infile("DrinkMachineInventory.txt");

if(infile.fail())
{
cout << "Could not find the file DrinkMachineInventory.txt ";
cout << "Exiting the program ";
exit(0);
}
int i=0;
char ch;
string word= "";
while(!infile.eof())
{
word= "";
ch = infile.get();
while(true)
{
if(isdigit(ch) || ch == ' ')
break;
else
word += ch;
ch = infile.get();
}
if(word != "")
{
d[i].name = word;
infile >> d[i].cost >> d[i].num ;
i++;
}
}
infile.close();
}
int menu(Machine d[])
{
int choice=8,i;
bool soldout=true;
while((choice<1||choice>6)||soldout)
{
soldout=false;
cout<<"Menu ";
cout<<" Drink Cost left ";
for(i=0;i<5;i++)
{
cout<<i+1<<". "<<setw(15)<<left<<d[i].name<<setw(5);
cout<<setprecision(2)<<fixed<<d[i].cost<<" "<<d[i].num<<endl;
}
cout<<"6. Exit ";
cout<<"Enter Choice ";
cin>>choice;
if(choice<1||choice>6)
cout<<"invalid entry ";
else
if(d[choice-1].num==0)
{cout<<"sold out ";
soldout=true;
}
}
return choice-1;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote