Given that Sale[NUM_STORES][NUM_MONTHS][NUM_DEPTS] is a three dimensional array
ID: 3784675 • Letter: G
Question
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;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.