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

Beverage Orders A high-end coffee shop has just hired you as their senior progra

ID: 3681374 • Letter: B

Question

Beverage Orders

A high-end coffee shop has just hired you as their senior programmer. They have tasked you to design and

implement two C++ applications allowing employees to take orders from its customers and to determine weekly

sales.

Application #1: Create an application allowing employees to take orders and then tally up the total costs from its

customers.

The coffee shop offers the following items on its menu:

Coffee

Tea

Soda

Juice

Manager Special (store manager offers a drink of their choice to customers)

The application must be able to:

Accept one or more drinks in a single order; use a sentinel value to terminate an order

Once an order has been placed, tally up the total cost of the order

Application #2: Create another application to process an input file, weekly_sales.txt, and tally up its weekly sales

total. The data file consists of 7 entries representing the sales from last week.

If the input file does not exist, prompt user to try again.

Project Requirements

Proper formatting must be utilized. For example, currency format was be used for any order amount.

Data validations

o When an order for coffee is placed, the application should accept ‘c’ or ‘C’. See sample run.

o When an invalid menu item is entered, the application should ignore it. ‘w’ or ‘W’ should be ignored.

If the weekly sales data file is not available, display an appropriate error message. DON’T crash the program.

Be sure to thoroughly test both applications – valid and invalid test cases must be included.

Explanation / Answer

/**** C++
Application #1: allowing employees to take orders and then tally up the total costs from its customers.
******/

#include <cstdlib>
#include <iostream>
#include <math.h>
#include <stdio.h>

using namespace std;


int main()
{
   char ch;
   int c = 0, j = 0, s = 0, t = 0, m = 0;
   while(true)
   {
           cout <<"Welcome to My Coffee Shop! Our Offer: ";
           cout <<"C - Coffee ($1.29) ";
           cout <<"J - Juice ($1.50) ";
           cout <<"S - Soda ($1.00) ";
           cout <<"T - tea ($1.39) ";
           cout <<"M - Manager Special ($2.99) ";
           cout <<"X - Done with Placing order ";
           cout <<"What drink would you like> Select C,J,S,T,M (or X to finish with order): ";
       cin >> ch;
       if(ch == 'c' || ch == 'C')
           {
               c++;
               cout <<"Thank you. You have ordered coffee as your drink ";
           }

       else if(ch == 'j' || ch == 'J')
           {
               j++;
               cout <<"Thank you. You have ordered juice as your drink ";
           }

       else if(ch == 's' || ch == 'S')
           {
               s++;
               cout <<"Thank you. You have ordered soda as your drink ";
           }

       else if(ch == 't' || ch == 'T')
           {
               t++;
               cout <<"Thank you. You have ordered tea as your drink ";
           }

       else if(ch == 'm' || ch == 'M')
           {
               m++;
               cout <<"Thank you. You have ordered manager special as your drink ";
           }

       else if(ch == 'x' || ch == 'X')
           {
               break;
           }

       else cout <<"Invalid selection. Please place your order again ";

   }

   int sum = c+j+s+t+m;
   double total = 1.29*c + 1.50*j+ 1.00*s + 1.39*t+ 2.99*m ;
   cout<< "You have ordered "<<sum<<" drinks. Here is your order : ";
   cout<< " Beverage Quantity ";
   if(c> 0) cout<<"Coffee "<<c<<endl;
   if(j> 0) cout<<"Juice "<<j<<endl;
   if(s> 0) cout<<"Soda "<<s<<endl;
   if(t> 0) cout<<"Tea "<<t<<endl;
   if(m> 0) cout<<"Manager Special "<<m<<endl;

   cout<< "Total: $"<<total<<endl;
   cout<<"Done. Have a Great Day ";

return 0;
}

/***** C++
Application #2:application to process an input file, weekly_sales.txt, and tally up its weekly sales
**********/

#include <iostream>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <fstream>
#include <iomanip>
#include <vector>

using namespace std;

int main()
{   
char filename[] = "weekly_sales.txt";
int c = 0, j = 0, s = 0, t = 0, m = 0;
ifstream inputfile;
inputfile.open(filename, ios::in);

// test if fail to open fail for reading
if(inputfile.fail())
{
cout<<"DON'T crash the program ";
return 0;
}

// if successful opening file for reading
else
{
char ch;
while(inputfile >> ch)
{
if(ch == 'c' || ch == 'C')
{
c++;
cout <<"coffee was ordered ";
}

else if(ch == 'j' || ch == 'J')
{
j++;
cout <<"juice was ordered ";
}

else if(ch == 's' || ch == 'S')
{
s++;
cout <<"soda was ordered ";
}

else if(ch == 't' || ch == 'T')
{
t++;
cout <<"tea was ordered ";
}

else if(ch == 'm' || ch == 'M')
{
m++;
cout <<"manager special was ordered ";
}
else cout<<"Invalid Input, Ignored ";
}
}

inputfile.close();
double total = 1.29*c + 1.50*j+ 1.00*s + 1.39*t+ 2.99*m ;
cout<< "Weekly order: ";
cout<< " Beverage Quantity ";
if(c> 0) cout<<"Coffee "<<c<<endl;
if(j> 0) cout<<"Juice "<<j<<endl;
if(s> 0) cout<<"Soda "<<s<<endl;
if(t> 0) cout<<"Tea "<<t<<endl;
if(m> 0) cout<<"Manager Special "<<m<<endl;

cout<< "Total: $"<<total<<endl;
  
}