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

Given that Sale[NUM_STORES][NUM_MONTHS][NUM_DEPTS] is a three dimensional array

ID: 3784675 • Letter: G

Question


Given that Sale[NUM_STORES][NUM_MONTHS][NUM_DEPTS] is a three dimensional array of point type. Write a C++ function to calculate and print the total value of sales during a specific month by each department and in each store. The return type of the function is void and the function should have 2 input parameters: Sale array and the month user specified. The constants NUM_STORES, NUM_MONTHS, and NUM_DEPTS may be accessed globally by defining the following global variables: #define NUM_DEPTS 2 #define NUM_STORES 2 #define NUM_MONTHS 12 The array Sale is initialized by the following statement in your main(): float Sale[NUM_STORES][NUM_MONTHS][NUM_DEPTS] = {1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 24, 2.5, 2.6, 2.7, 2.8, 2.9, 3.0, 3.1, 3.2, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 4.0, 4.1, 4.2, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3.0, 3.1, 3.2};

Explanation / Answer

#include<iostream>

#define NUM_DEPTS 2

#define NUM_STORES 2

#define NUM_MONTHS 12

using namespace std;

// function declaration

void sales(float s[][NUM_MONTHS][NUM_DEPTS],int mon);

int main()

{

    float Sale[NUM_STORES][NUM_MONTHS][NUM_DEPTS] =

    {

        1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2,

        2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3.0, 3.1, 3.2,

        3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 4.0, 4.1, 4.2,

        2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3.0, 3.1, 3.2

    };

    int month;

    // take input

    cout << " Enter the month (between 1 and 12): ";

    cin >> month;

    // call function

    sales(Sale,month);

    return 0;

}

void sales(float s[][NUM_MONTHS][NUM_DEPTS],int mon)

{

    // iterating variable for store and deptt

    int st,dept;

    float sum;

    string mon_value[12] = {"January","February","March","April","May","June","July","August","September","October","November","December"};

    cout << " *** Sales for the month of " + mon_value[mon-1] + " *** ";

    for(st=0;st<2;st++)

    {

        cout << " ---------Sales for store " << st+1 << "----------- ";

        sum = 0;

        for(dept=0;dept<2;dept++)

        {

            // Printing the value of sales

            cout << "Department " << dept+1 << " : " << s[st][mon-1][dept] << " ";

            // Sum of sales for each deptt

            sum = sum + s[st][mon-1][dept];

        }

        cout << "Total Sales : " << sum << " ";

    }

    return;

}

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