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

Here is the program. Page 162 Algorithm 3-3: Vending MachineAlgorithm 1. Declare

ID: 3611183 • Letter: H

Question

Here is the program. Page 162 Algorithm 3-3: Vending MachineAlgorithm

1.       Declare variables

2.       Read the amount ofchange(amount)

3.       Process the amount

3.1. Determine how many times 25 (the value of a quarter) goesinto the amount (store and display the quantity)

3.2. Determine the amount left over after quarters have beenremoved.

3.3. Determine how many times 10 (the value of a dime) goes intothe amount (store and display this)

3.4. Determine the amount left over after dimes have beenremoved

3.5. Determine how many times 5 (the value of a nickel) goesinto the amount (store and display this)

3.6. Determine the amount left over after nickels are removed(this is the number of pennies – store and display it)

3.7. Add up the sum of the number of quarters, dimes,nickels, and pennies, and display it.

4.       The clear button shouldassign an empty string to the text field of every textbox allowingthe user to begin again.

The diagram of the visual is a square like this

Amount of change (0-99cents)          textbox

Buttoncalculate                              button clear

Number ofdimes                           text box

Number ofnickels                          text box

Number ofpennies                       text box

Totalcoins                                          text box

Explanation / Answer

#include <cstdlib>
#include <iostream>
#include <iomanip>
using namespace std;
const int ICE_LEMON_TEA = 0;
const int NESCAFE = 1;
const int HORLICK = 2;
const int TEA = 3;
float gPrice[4] = {1,1.1,1.2,.9};
int gDrinks[4] = {0, 0, 0, 0};
int gCoins[4] = {0, 0, 0, 0};
float gCash = 0;
void Write_Menu();
void Get_Selection(int&, float&);
float Get_Money(float&);
float Get_Change(float, float);
void Write_Change(float);
void Write_Report_Cash_Out(const int c oins[]);
void Write_Report_Drink s(const int drink s[]);
void Write_Report_Cash_In();
int main(int argc, char *argv[])
{
int selection=0;
float price;
float money;
float change;
while(selection != 6)
{
Write_Menu();
Get_Selection(selection, price);
if(selection < 5) {
money = Get_Money(gCash);
change = Get_Change(money, price);
Write_Change(change);
}
}
system("PAUSE");
return EXIT_SUCCESS;
}
void Write_Menu()
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout <<" "<<endl<<endl;
cout <<"              "<<endl;
cout <<" * * "<<endl;
cout <<" * VENDING MACHINE * "<<endl;
cout <<" * * "<<endl;

cout <<" * Teh Tarik -"<<gPrice[ICE_LEMON_TEA]<<" - Press 1 *"<<endl;
cout <<" * Nescafe - "<<gPrice[NESCAFE]<<" -Press 2 * "<<endl;
cout <<" * Horlick - "<<gPrice[HORLICK]<<" -Press 3 * "<<endl;
cout <<" * Teh 'O' - "<<gPrice[TEA]<<" - Press4 * "<<endl;
cout <<" * Print Report - Press 5 * "<<endl;
cout <<" * Terminate - Press 6 * "<<endl;
cout <<" * * "<<endl;
cout <<"         "<<endl;
}
void Get_Selection(int& selection, float &price)
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout <<" Please enter your selection."<<endl;
cout <<" Then press Enter. "<<endl;
cout <<" Your selection > ";
cin >>selection;
switch(selection)
{
case 1:
cout <<" You chose Teh Tarik -"<<ICE_LEMON_TEA<<endl;
price = gPrice[ICE_LEMON_TEA];
break;
case 2:
cout <<" You chose Nescafe -"<<NESCAFE<<endl;
price = gPrice[NESCAFE];
break;
case 3:
cout <<" You chose Horlick -"<<HORLICK<<endl;
price = gPrice[HORLICK];
break;
case 4:
cout <<" You chose Teh O - "<<TEA<<endl;
price = gPrice[TEA];
break;
case 5:
Write_Report_Cash_Out(gCoins);
Write_Report_Drinks(gDrinks);
Write_Report_Cash_In();
price = 0;
break;
case 6:
price = 0;
break;
default:
price = 0;
cout<<" You must enter a selection between 1 and 6. ThankYou!"<<endl<<endl;
}
}
float Get_Money(float& cash)
{
float money;
cout <<" Please enter the RM amount"<<endl;
cout <<" you are spending. Then pres sEnter."<<endl;
cout <<" Your spending > ";
return money;
}
float Get_Change(float money, float price)
{
float change;
return change;
}