Given that Sale[NUM_STORES][NUM_MONTHS][NUM_DEPTS] is a three dimensional array
ID: 3785660 • Letter: G
Question
Given that Sale[NUM_STORES][NUM_MONTHS][NUM_DEPTS] is a three dimensional array of float 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 output will be a value for each possible department and each possible store for a total of 4 outputs. 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 constants: const int NUM_DEPTS = 2; const int NUM_STORES = 2; const int NUM_MONTHS = 12; The array Sale is initialized by the following statement in your main(): float Sale[NUM_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};Explanation / Answer
#include <iostream>
using namespace std;
const int NUM_DEPTS = 2;
const int NUM_STORES = 2;
const int NUM_MONTHS = 12;
void mon_sales(int mon,float sales[][2][12])
{
cout<<"The sales for month "<<mon<<" are:"<<endl;
mon--;
for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
{
cout<<"For store "<<i+1<<" and department "<<j+1<<" sales are "<<sales[i][j][mon]<<endl;
}
}
}
int main()
{
float Sale[2][2][12] = {
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
};
mon_sales(1,Sale);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.