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

Pseudocode for the assignment. classes-Soda Vending Machine Follow the direction

ID: 3555737 • Letter: P

Question

Pseudocode for the assignment.


classes-Soda Vending Machine


   Follow the directions preceded by //*
   Replace ??? with correct code (mostly reference to the class)

*/

/**************** specification file ******************/
#include           // needed for string type
using namespace std;
const int SIZE = 5;


//*   add the specification code


/**************** implementation **********************/

//* complete the default constructor
{

  
   inStock[0] = 10;
   inStock[1] = 8;
   inStock[2] = 6;
   inStock[3] = 4;
   inStock[4] = 1;

   price = 1.25; // price is set and cannot be changed because
// there are no accessor methods
}


//*   write the remainder of the implementation file

/******************** client **************************/
/*
   assumptions: Coke is NEVER removed
The user enters numeric data when required
The user enters the school in all uppercase
   // no limits on soda price (not error checked)
*/
#include
#include
// #include // already in the specification file


/**** chooses which school's vending machine
pre   none
post school oontains a valid value
******************************************/
void whichMachine(string &);

/**** displays menu and gets input
pre   school has value, vm exists
post menu displayed, user input is A-D
******************************************/
void displayMenuChoice(char &, string, ???);

/**** validates menu choice
pre   userCharacter contains user input
post   the value is A - D
******************************************/
void errorChkChar(char &);

/***** calls function(s) to act upon the choice
pre choice is in the valid range
post appropriate menu choice is activated
******************************************/
bool evaluateChoice(char, string, ???);

/**** displays menu for the appropriate school
pre   vm exists, school is chosen
post current menu displayed
******************************************/
void displaySodas(string, ???);

/**** buy a soda and update inventory
pre   vm exists
post a particular brand is reduced by 1
******************************************/
void getSoda(???);

/**** sets a new type of soda in machine
pre   vm exists
post an existing brand is replaced by a user defined one
******************************************/
void changeBrand(???);

/**** sets a brand to 20 cans
pre   vm exists
post a particular brand has 20 cans
******************************************/
void restock(???);

/**** states the total number of cans left
pre   vm exists
post FTRVAL is total number of cans left
******************************************/
int totalCans(???);

/**** compares and dispalys # of coke left
pre   vm1 is ASU and vm2 is UA
post   comparative # of cokes left displayed
******************************************/
void compareCoke(???, ???);

/**** displays cans remaining for each ASU and UA
pre total cans for ASU and UA set
post remaining number of cns displayed
*******************************************/
void endDisplay(int cansASU, int cansUA);


void main(void)
{
   //* instantiate some machine               // any machine
   //* instantiate ASU and UA machines       // university machines
   char menuChoice = ' ';
   bool flag = true;
   string university = "";
   int tot_ASU = 0, tot_UA = 0;

   cout << fixed;               // sets up number format
   cout.precision(2);

   do{
       whichMachine(university);

       if(university == "ASU")
           ??? = ???;
       else if(university == "UA")
           vm = vm_UA;
       else if(university == "Q" || university == "q")
           break;
      
       displayMenuChoice(menuChoice, university, ???);
       flag = evaluateChoice(menuChoice, university, ???);

       // transfers collected data to appropriate school machine
       if( university == "ASU")
           vm_ASU = vm;
       else
           ??? = ???

   }while(flag);

   // compare amt of Coke
   compareCoke( vm_ASU, vm_UA);

   // add total cans
   tot_ASU = totalCans(vm_ASU);
   tot_UA = totalCans(vm_UA);

   endDisplay(tot_ASU, tot_UA);

cout << endl;
} // end main()


void whichMachine(string & school)
{
   cout << " Whose machine, ASU or UA? Type Q to quit. ";
   cin >> school;

   while( (school != "ASU") && (school != "UA") && (school != "Q") && (school != "q") )
   {
       cout << "Invalid entry, Case counts. Try again.";
       cout << " Which school, ASU or UA? Type Q to quit. ";
       cin >> school;
   }
   system("cls"); // or put at top of displayMenuChoice()
} // end whichMachine()

void displayMenuChoice(char & choice, string school, ???)
{
   //   display the main menu
   cout << endl;
   cout << " " << school << " Vending Machine Main Menu" << endl;
   cout << " -----------------------------" << endl;
   cout << setw(15) << "A. " << "Get Soda - $ " << vm.getPrice() << endl;
   cout << setw(15) << "B. " << "Change Brand" << endl;
   cout << setw(15) << "C. " << "Restock Soda" << endl;
   cout << setw(15) << "D. " << "Leave This Machine" << endl;
   cout << " -----------------------------" << endl;

   cout << "Enter your menu choice (A - D): ";
   cin >> choice;
   errorChkChar(choice);
}

void errorChkChar(char & userCharacter)
{
userCharacter = toupper(userCharacter);
   while(userCharacter < 'A' || userCharacter > 'D' )
   {
       cout << "Invalid entry. Use only A-D. Try again. ";
       cin >> userCharacter;
       userCharacter = toupper(userCharacter);
   }
}

bool evaluateChoice(char choice, string school, ???)
{
   switch(choice)
   {
       case 'A':
           displaySodas(school, ???);
           getSoda(???);
           return true; //* why is break not required?
       case 'B':
           displaySodas(school, ???);
           changeBrand(vm);
           return true;
       case 'C':
           displaySodas(school, ???);
           restock(vm);
           return true;
       case 'D':
           return false;

   // no default because choice is error checked before being passed
   } // ignore warning C4715: 'evaluateChoice' : not all control paths return a value
// could use "default: return false;" to eliminate warning
} // end evaluateChoice()


void displaySodas( string school, ??? vm)
{
   cout << endl << endl;
   cout << " " << school << " Vending Machine" << endl;
   cout << " ----------------------------" << endl;
   cout << " Soda Type Stock" << endl;
   cout << " ----------------------------" << endl;

   for (int i = 0; i < SIZE; i++)
       cout << setw(13) << i + 1 << "." << setw(16) << ???
           << setw(6) << ??? << endl;
}

void getSoda(???)
{
   int sodaChoice; // menu choice
   bool flag = false; // OK to go on, no errors

   do{
       cout << setw(10) << "Enter your choice: ";
       cin >> sodaChoice;
       while(sodaChoice < 1 || sodaChoice > SIZE) {
           cout << "Please enter only 1 - " << SIZE << ".";
           cout << " Reenter your choice: ";
           cin >> sodaChoice;
       }

       flag = false; // OK to go on, no errors

       // checks to see whether there are sodas left
       if(??? (sodaChoice - 1) < 1) {
           cout << " No " << ???(sodaChoice - 1) << " left. Make another selection. ";
           flag = true;   // an error, repeat choice
       }
   }while(flag);

   // decreases amount of specific soda by 1
   vm.decrementStock(sodaChoice-1);
} // end getSoda(()

void changeBrand(???)
{
   string sodaName, oldSoda;
   int i = 0;               // counter
   int subscript = 0;       // hold place of "Empty'
   bool flag = false;
  
   do{   // put into a separate function?
       cout << "Enter the name of the beverage to change: ";
       getline(cin, oldSoda);

       for (i = 0; i < SIZE; i++)
           if(??? == oldSoda){
               flag = true;
               subscript = i;
           }

       if(flag){
           cout << "Enter the new brand: ";
           getline(cin, sodaName);

           ???setBrand(subscript, sodaName);
           ???setInStock(subscript, 5);
           cout << sodaName << " replaces " << oldSoda << " and is stocked with 5 cans. ";

           flag = false;
       }
       else
           cout << "The brand you entered is not on the list. ";
   }while(flag);

   system("pause");
} // end changeBrand()

void restock(???)
{  
   string sodaName;
   int i = 0;           // counter
   int subscript = 0;   // hold place of "Empty'
   bool flag = false;

   do{   // put into a separate function
       flag = false;
       cout << "Enter the beverage name: ";
       getline(cin, sodaName);

       for (i = 0; i < SIZE; i++)
           if(??? == sodaName){
               flag = true;
               subscript = i;
           }

       // this is different for each function
       if(flag){
           ???(subscript, 20);
           cout << sodaName << " is restocked with 20 cans. ";
           flag = false;
       }
       else
       {
           cout << setw(10) << sodaName << " is not on the list. Make a different selection. ";
           flag = true;
       }
   }while(flag);
} // end restock()

int totalCans(???)
{
   int total = 0;

   for(int i=0; i < SIZE; i++)
       total += ???;

   return total;
}

void compareCoke(???, VendingMachine vm2)
{
   if( ??? > ??? )
       cout << " ASU has more Coke left. ASU " << ???
           << " cokes to UA " << ??? << " cokes";
  
   else if( ??? > ??? )
       cout << " UofA has more Coke left. ASU - " << ???
       << " to UA - " << ???;
   else
       cout << " ASU and UofA have the same amount of Coke, "
       << vm1.getInStock(0);
} // end compareCoke()


void endDisplay(int cansASU, int cansUA)
{
   cout << " ASU has " << cansASU << " cans of soda and "
   << "UofA has " << cansUA << " cans of soda";
} // end endDisplay()

--------------------------------------------------------------------------------------------------------------------------------------------------------------------

Write a complete C++ program which will produce the sample runs shown at the end.
You will first ask the user to choose a school (ASU or UA) or to quit the program. If a school is
chosen, display a menu to access that school's vending machine. Below are the menus and the
starting amounts for each product.
[school] Vending Machine Main Menu
-----------------------------
A. Get Soda - $ 1.25
B. Change Brand
C. Restock Soda
D. Leave This Machine
-----------------------------
[school] Vending Machine
------------------------
Type Stock
------------------------
Coke 10
Orange 8
Dew 6
Ice Tea 4
Evian 1
The following is an explanation of each menu choice:
Get Soda
This menu choice displays the vending machine. It lists out the 6 different sodas available and how
many are in stock.
See the list above for starting types and amounts.
Change Brand
This allows the user to swap out one soda for a different brand of soda. The user will be prompted
for the new soda's name and the name of the old soda to be replaced. The new soda will begin with
five (5) cans of soda. If the user does not type in the exact name of the old soda, an error message
will display, because the program will not be able to match the names. The user may not remove
the Coke. This will be one of your assumptions.
Restock Soda
The user will type in the name of the soda to be restocked. If the user does not type in the exact
name of the old soda, an error message will display, because the program will not be able to match
the names. If there is a soda name match, the user can restock the soda with 20 cans.
Leave this menu
Leaves the menu and again asks for a school or quit the program.
If the user choose to quit the program, the program states Whose machine has more Coke left and
how many Cokes each school has. (See the Sample Runs below.)
All user input must be error checked. If it is out of range, an appropriate error message must be
generated and the user must be prompted again. String input is case sensitive while character input
is case insensitive. (See the Sample Runs below.)
Assignment 4 p 1/6
You may wish to use the following two system calls. Each is a simple statement.
system("CLS");
This command will clear the screen.
system("PAUSE");
This command will pause the screen. Great for displaying reports. This command causes the
onscreen message of "Press any key to continue . . ." in the following sample output. Once the
user presses any key, the program will continue.
Unified Modeling Language (UML)

Explanation / Answer

#include<iostream>
#include<string>
#include<stdlib.h>
#include<iomanip>
#include<limits.h>
using namespace std;
const int SIZE = 5;

class VendingMachine
{
   private:
   string brand[SIZE];
   int inStock[SIZE];
   double price;
  
   public:
   VendingMachine()
   {
       brand[0]="Coke";
       brand[1]="Orange";
       brand[2]="Dew";
       brand[3]="Ice Tea";
       brand[4]="Evian";
       inStock[0] = 10;
       inStock[1] = 8;
       inStock[2] = 6;
       inStock[3] = 4;
       inStock[4] = 1;
       price = 1.25;
   }
   ~VendingMachine()
   {
      
   }
   string getBrand(int i)
   {
       return brand[i];
   }
   void setBrand(int subscript,string sodaName)
   {
       brand[subscript]=sodaName;
   }
   int getInStock(int i)
   {
       return inStock[i];
   }
   void setInStock(int subscript, int count)
   {
       inStock[subscript]=count;
   }
   void decrementStock(int i)
   {
       inStock[i]--;
   }
   double getPrice()
   {
       return price;
   }
};
void whichMachine(string &);
void displayMenuChoice(char &, string, VendingMachine &);
void errorChkChar(char &);
bool evaluateChoice(char, string, VendingMachine &);
void displaySodas(string, VendingMachine &);
void getSoda(VendingMachine &);
void changeBrand(VendingMachine &);
void restock(VendingMachine &);
int totalCans(VendingMachine &);
void compareCoke(VendingMachine &,VendingMachine &);
void endDisplay(int cansASU, int cansUA);


int main(void)
{
   VendingMachine vm_ASU,vm_UA,vm;
   char menuChoice = ' ';
   bool flag = true;
   string university = "";
   int tot_ASU = 0, tot_UA = 0;
   cout << fixed; // sets up number format
   cout.precision(2);
do{
whichMachine(university);
if(university == "ASU")
vm = vm_ASU;
else if(university == "UA")
vm = vm_UA;
else if(university == "Q" || university == "q")
break;
  
displayMenuChoice(menuChoice, university, vm);
flag = evaluateChoice(menuChoice, university, vm);
// transfers collected data to appropriate school machine
if( university == "ASU")
vm_ASU = vm;
else
vm_UA = vm;
}while(flag);
// compare amt of Coke
compareCoke( vm_ASU, vm_UA);
// add total cans
tot_ASU = totalCans(vm_ASU);
tot_UA = totalCans(vm_UA);
endDisplay(tot_ASU, tot_UA);
   cout << endl;
   system("PAUSE");
}

void whichMachine(string & school)
{
cout << " Whose machine, ASU or UA? Type Q to quit. ";
cin >> school;
while( (school != "ASU") && (school != "UA") && (school != "Q") && (school != "q") )
{
cout<<"Invalid entry, Case counts. Try again.";
cout<<" Which school, ASU or UA? Type Q to quit. ";
cin>>school;
}
system("cls");
}

void errorChkChar(char & userCharacter)
{
   userCharacter = toupper(userCharacter);
while(userCharacter < 'A' || userCharacter > 'D' )
{
cout << "Invalid entry. Use only A-D. Try again. ";
cin >> userCharacter;
userCharacter = toupper(userCharacter);
}
}

void displayMenuChoice(char & choice, string school, VendingMachine &vm)
{
cout << endl;
cout << " " << school << " Vending Machine Main Menu" << endl;
cout << " -----------------------------" << endl;
cout << setw(15) << "A. " << "Get Soda - $ " << vm.getPrice() << endl;
cout << setw(15) << "B. " << "Change Brand" << endl;
cout << setw(15) << "C. " << "Restock Soda" << endl;
cout << setw(15) << "D. " << "Leave This Machine" << endl;
cout << " -----------------------------" << endl;
cout << "Enter your menu choice (A - D): ";
cin >> choice;
errorChkChar(choice);
}

void displaySodas( string school, VendingMachine & vm)
{
cout << endl << endl;
cout << " " << school << " Vending Machine" << endl;
cout << " ----------------------------" << endl;
cout << " Soda Type Stock" << endl;
cout << " ----------------------------" << endl;
for (int i = 0; i < SIZE; i++)
cout <<setw(13)<<i + 1<<"."<<setw(16)<<vm.getBrand(i)<<setw(6)<<vm.getInStock(i)<< endl;
}

void getSoda(VendingMachine & vm)
{
int sodaChoice;
bool flag = false;
do{
cout << setw(10) << "Enter your choice: ";
cin>>sodaChoice;
while(sodaChoice<1 || sodaChoice>SIZE){
           cin.clear();
           cin.ignore(INT_MAX,' ');
cout<<"Please enter only 1 - " << SIZE << ".";
cout<<" Reenter your choice: ";
cin>>sodaChoice;
}
flag = false;
// checks to see whether there are sodas left
if(vm.getInStock(sodaChoice - 1)<1){

       cout<<" No "<<vm.getInStock(sodaChoice - 1)<<" left. Make another selection. ";
flag = true; // an error, repeat choice
}
}while(flag);
// decreases amount of specific soda by 1
vm.decrementStock(sodaChoice-1);
}

void changeBrand(VendingMachine & vm)
{
string sodaName, oldSoda;
int i = 0;
int subscript = 0;
bool flag = false;
   cin.clear();
   cin.ignore(INT_MAX,' ');
do{
cout << "Enter the name of the beverage to change: ";
getline(cin, oldSoda);
for (i = 0; i < SIZE; i++)
if(vm.getBrand(i) == oldSoda){
flag = true;
subscript = i;
}
if(flag){
cout << "Enter the new brand: ";
getline(cin, sodaName);
vm.setBrand(subscript, sodaName);
vm.setInStock(subscript, 5);
cout<<sodaName<<" replaces "<<oldSoda<<" and is stocked with 5 cans. ";
flag = false;
}
else
{
       cout << "The brand you entered is not on the list.Make a different selection ";   
       flag=true;
}
}while(flag);
}

void restock(VendingMachine & vm)
{
string sodaName;
int i = 0;   
int subscript = 0;   
bool flag = false;
cin.clear();
   cin.ignore(INT_MAX,' ');
do{   
flag = false;
cout << "Enter the beverage name: ";
getline(cin, sodaName);
for (i = 0; i < SIZE; i++)
if(vm.getBrand(i) == sodaName){
flag = true;
subscript = i;
}
// this is different for each function
if(flag){
vm.setInStock(subscript, 20);
cout << sodaName << " is restocked with 20 cans. ";
flag = false;
}
else
{
cout << setw(10) << sodaName << " is not on the list. Make a different selection. ";
flag = true;
}
}while(flag);
}

int totalCans(VendingMachine & vm)
{
int total = 0;
for(int i=0; i < SIZE; i++)
total += vm.getInStock(i);
return total;
}

bool evaluateChoice(char choice, string school, VendingMachine &vm)
{
switch(choice)
{
case 'A':
displaySodas(school, vm);
getSoda(vm);
return true;
case 'B':
displaySodas(school, vm);
changeBrand(vm);
return true;
case 'C':
displaySodas(school,vm);
restock(vm);
return true;
case 'D':
return false;
}
}

void compareCoke(VendingMachine & vm1, VendingMachine & vm2)
{
if(vm1.getInStock(0)> vm2.getInStock(0) )
cout<<" ASU has more Coke left. ASU "<<vm1.getInStock(0)<<" cokes to UA "<<vm2.getInStock(0)<<" cokes";
  
else if(vm2.getInStock(0) > vm1.getInStock(0) )
cout<<" UA has more Coke left. ASU - "<<vm1.getInStock(0)<<" to UA - "<<vm2.getInStock(0);
else
cout<<" ASU and UA have the same amount of Coke, "<<vm2.getInStock(0);
}

void endDisplay(int cansASU, int cansUA)
{
cout<<" ASU has "<<cansASU<<" cans of soda and "<<"UA has "<<cansUA<<" cans of soda";
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote