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

Taif coffee shop wants to open three branches at Taif University at the followin

ID: 3822848 • Letter: T

Question

Taif coffee shop wants to open three branches at Taif University at the following locations: Al-Hawiya, Al Faisaliah and Qarua. The coffee shop manager needs to computerize orders to generate reports at the end of each month. He requests you to write a C++ program to input ordered data and generate monthly report. The manger asks you to display the monthly report in a tabular form with all orders names in alphabetical order. The report should display each order name with its ordered quantity by each branch and total ordered quantity by all branches. At the end of the report, he wants you to print the popular order and the popular branch. To simplify the testing, your program can manage six order types but you can easily increase the number of order types. Therefore, you will need an array of string called orderName (NO OF ORDER], where No oF ORDER is a constant variable. SAMPLE Your program should display the report in the following form: Monthly Report of Taif Coffee shop Order Branches Total Quantity Name Al-Hawiya Al Faisaliah Qarua. Coffee 400 300 200 900 600 Crepe 400 200 1200 Croissant. 500 350 150 1000 350 Doughnut 300 120 770 Sandwich 200 190 190 Tea 300 250 220 770 Popular order: crepe, Total ordered Quantity 1200 orders Popular Branch: Al-Hawiya, Total orderd Quantity: 2350 orders

Explanation / Answer

#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int const NO_OF_ORDER=6;
int const NO_OF_BRANCH = 3;

string ordername[NO_OF_ORDER];
int Haiywah[NO_OF_ORDER];
int Faisaliah[NO_OF_ORDER];
int Qarua[NO_OF_ORDER];
int totalQuantity[NO_OF_ORDER];


void getOrderName()
{
   int i = 0;
   string name;
   ifstream input("orderName.txt");
   while (input >> name)
   {
       ordername[i] = name;
           i++;
   }

}

void sortOrders()
{

   int i, j, first;
       string temp;
   int numLength = NO_OF_ORDER;
   for (i = numLength - 1; i > 0; i--)
   {
       first = 0; // initialize to subscript of first element
       for (j = 1; j <= i; j++) // locate smallest between positions 1 and i.
       {
           if (ordername[j] < ordername[first])
               first = j;
       }
       temp = ordername[first]; // Swap smallest found with element in position i.
       ordername[first] = ordername[i];
       ordername[i] = temp;
   }

}

void setToZero(int a[])
{
   a = { 0 };
}

int searchOrders(string a[],string name)
{

   for (int i = 0; i < NO_OF_ORDER; i++)
   {
       if (a[i] == name)
       {
           return i;
       }
   }

   return -1;
}

void insertOrders(string ordername[],int a[],int b[],int c[])
{
   string name;
   int branch;
   int quantity;
   ifstream input("orderData.txt");
   int i = 0;
  
  
   while (input >> name >> branch >> quantity)
   {
       i=searchOrders(ordername, name);
       if (branch == 1)
       {
           a[i] = quantity;
       }
       else if (branch == 2)
       {
           b[i] = quantity;
       }
       else
       {
           c[i] = quantity;
  
       }

   }
}

int sumTotalQuantity(int a[])
{

   int sum = 0;
   for (int i = 0; i < NO_OF_ORDER; i++)
   {
       sum = sum + a[i];
   }
   return sum;
}

void reportHeading()
{
   cout << "name haiywa faisaliah qarua totalquantity ";

}

void reportBody(string pop,int tot)
{
   int sum = 0;
   int maxq = 0;
   int maxi = 0;
   for (int i = 0; i < NO_OF_ORDER; i++)
   {
       sum = Haiywah[i] + Faisaliah[i] + Qarua[i];
       if (sum > maxq)
       {
           maxq = sum;
           maxi = i;
       }
       cout << ordername[i] << " " << Haiywah[i] << " " << Faisaliah[i] << " " << Qarua[i] << " " << sum<<endl;
  


   }

   cout << "popular order is :" << ordername[maxi] << " quantity: " << maxq;

   cout << "popularbranch is :" << pop << " quantity: " << tot;

}

pair<string,int> popularBranch(int a[],int b[],int c[])
{
   int sum1 = sumTotalQuantity(a);
   int sum2 = sumTotalQuantity(b);
   int sum3 = sumTotalQuantity(c);
   pair<string, int> p;

   if (sum1 > sum2)
   {
       if (sum1 > sum3)
       {
       p=   make_pair("Hawiyah", sum1);

       }
       else
       {
           p=make_pair("Fasaliah", sum2);

       }
   }
   else
   {
       if (sum2 > sum3)
       {
           p=make_pair("Fasaliah", sum2);

       }
       else
       {
           p=make_pair("Qarua", sum3);

       }
   }
   return p;
}
int main()
{
  
   getOrderName();
   sortOrders();
   setToZero(Haiywah);
   setToZero(Faisaliah);
   setToZero(Qarua);
   setToZero(totalQuantity);

   insertOrders(ordername,Haiywah,Faisaliah,Qarua);
   pair<string,int> p=popularBranch(Haiywah,Faisaliah,Qarua);

   reportHeading();
   reportBody(p.first,p.second);

}