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: 3814086 • 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.


REQUIREMENTS

Your program should include at least the following:

Global Variables:

NO_OF_ORDER

NO_OF_BRANCH

One Dimensional Arrays:

orderName

Hawiyah

Faisaliah

Qarua

totalQuantity

Input Files:

(orderName.txt) with the content:

Coffee Doughnut Croissant Sandwich Tea Crepe

(orderData.txt) with the content (orderName branchNo orderedQuantity):

Coffee 1

400

Coffee 2

300

Coffee 3

200

Doughnut

1 350

Doughnut

2 300

Doughnut

3 120

Functions:

getOrderName: reads 6 orders names from (orderName.txt) and fills the array orderName.

sortOrders: uses a sort algorithm to sort the array

orderName in alphabetical order.

setToZero: initializes the arrays Hawiya, Faisaliah, Qarua and totalQuantity to zero. All arrays have the same number of rows which is 6.

searchOrders: implement a search algorithm on the array orderName and return the index of the order name if found. This function will be used inside the insertOrders function.

insertOrders: reads orderName, branchNo and orderedQuantity from (orderData.txt) and fills the arrays Hawiya, Faisaliah and Qarua.

sumTotalQuantity: sum total ordered quantity for each order name in the following arrays: Hawiya, Faisaliah and Qarua.

popularBranch: sum total ordered quantity for each branch and return the popular branch name and the total ordered quantity by the this branch.

reportHeading: prints a title for the monthly report and column headings.

reportBody: prints the following arrays: Hawiya, Faisaliah, Qarua and totalQuantity in a parallel tabular form. At the end of the table, the function prints the popular order and the popular branch with their total ordered quantities.

SAMPLE Your program should display the report in the following form: Monthly Report of Taif Coffee Shop---------- Total Order Branches Name Al-Hawi a Al Faisaliah Quantity rua. 200 Coffee 400 300 900 1200 Crepe 600 400 200 150 1000 350 Croissant 500 350 120 Doughnut 770 300 Sandwich 200 190 190 580 300 220 250 770 Tea Popular order: Crepe, Total ordered Quantity: 1200 orders Popular Branch Al-Hawiya, Total orderd Quantity: 2350 orders

Explanation / Answer

#include <iostream>
#include <fstream>

using namespace std;

struct Order
{
    string name;
    int branch;
    int qty;
};

const int NO_OF_ORDER = 6;
const int NO_OF_BRANCH = 3;
string orderName[NO_OF_ORDER];
Order Hawiya[NO_OF_ORDER];
Order Faisaliah[NO_OF_ORDER];
Order Qarua[NO_OF_ORDER];
int totalQuantity[NO_OF_ORDER];


void getOrderName(){
    ifstream file;
    file.open("orderName.txt");
    if(file.is_open())
    {
        while (!file.eof()){
            for(int i = 0; i < 6; ++i)
            {
                file >> orderName[i];
            }
        }
    }
    file.close();
}

void setToZero(){
    Hawiya[NO_OF_ORDER] = {0};
    Faisaliah[NO_OF_ORDER] = {0};
    Qarua[NO_OF_ORDER] = {0};
}

int searchOrders(string s){
    for(int i = 0; i < NO_OF_ORDER; i++){
        if (orderName[i].find(s, 0) != std::string::npos)
            return i;
        else
            return -1;
    }
}

void insertOrders(){
    ifstream file;
    file.open("orderData");
    if(file.is_open())
    {
        string temp;
        while (!file.eof())
        {
            for(int i = 0; i < 6; ++i)
            {
                file >> Hawiya[i].name >> Hawiya[i].branch >> Hawiya[i].qty;
                getline(file, temp);
                file >> Faisaliah[i].name >> Faisaliah[i].branch >> Faisaliah[i].qty;
                getline(file, temp);
                file >> Qarua[i].name >> Qarua[i].branch >> Qarua[i].qty;
            }
        }
    }
    file.close();
}

int sumTotalQuantity(){
    int sumTotalQuantity = 0;
    for(int i = 0; i < 6; ++i)
    {
        totalQuantity[i] = Hawiya[i].qty + Faisaliah[i].qty + Qarua[i].qty;
        sumTotalQuantity += totalQuantity[i];
    }
    return sumTotalQuantity;
}

int popularBranch(){
    int sumTotalQuantityHawiya;
    int sumTotalQuantityFaisaliah;
    int sumTotalQuantityQarua;
    for(int i = 0; i < 6; ++i)
    {
        totalQuantity[i] = Hawiya[i].qty + Faisaliah[i].qty + Qarua[i].qty;
        sumTotalQuantityHawiya += Hawiya[i].qty;
        sumTotalQuantityFaisaliah += Faisaliah[i].qty;
        sumTotalQuantityQarua += Qarua[i].qty;
    }
    if((sumTotalQuantityHawiya > sumTotalQuantityFaisaliah) && (sumTotalQuantityHawiya > sumTotalQuantityQarua))
    {
        cout << "Popular branch: Hawiya" << endl;
        return sumTotalQuantityHawiya;
    }
    if((sumTotalQuantityFaisaliah > sumTotalQuantityHawiya) && (sumTotalQuantityFaisaliah > sumTotalQuantityQarua))
    {
        cout << "Popular branch: Faisaliah" << endl;
        return sumTotalQuantityFaisaliah;
    }
    if((sumTotalQuantityQarua > sumTotalQuantityHawiya) && (sumTotalQuantityQarua > sumTotalQuantityFaisaliah))
    {
        cout << "Popular branch: Qarua" << endl;
        return sumTotalQuantityQarua;  
    }
}

int main() {
    getOrderName();
    insertOrders();
    int t_q = sumTotalQuantity();
    int p_b = popularBranch();
  
  
    return 0;
}