Inside main() declare a two dimensional array Sales that will store sales of fou
ID: 3647794 • Letter: I
Question
Inside main() declare a two dimensional array Sales that will store sales of four districts for three months. Pass an array to a function that will input sales for different districts from a keyboard. Use the following data (Don't input the district No.) Pass the same array to another function Print() that will print sales in a row and columns format Call a third function that will print the row total sales of each district for three months. The function also prints the column totals for each month for all four districts.Explanation / Answer
please rate - thanks
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
void inputData(double [][3]);
void Print(double [][3]);
void Totals(double [][3]);
int main()
{double sales[4][3];
inputData(sales);
Print(sales);
Totals(sales);
system("pause");
return 0;
}
void inputData(double sales[][3])
{int i,j;
for(i=0;i<4;i++)
{cout<<"for district "<<i+1<<endl;
for(j=0;j<3;j++)
{cout<<"Enter sales for month "<<j+1<<": ";
cin>>sales[i][j];
}
}
}
void Print(double sales[][3])
{int i,j;
cout<<" Month ";
for(i=1;i<=3;i++)
cout<<i<<" ";
cout<<endl;
for(i=0;i<4;i++)
{cout<<"District "<<i+1;
for(j=0;j<3;j++)
cout<<setw(12)<<setprecision(2)<<fixed<<sales[i][j];
cout<<endl;
}
}
void Totals(double sales[][3])
{int i,j;
double row=0,col[3]={0,0,0};
cout<<" Totals ";
cout<<" Month ";
for(i=1;i<=3;i++)
cout<<i<<" ";
cout<<"Total ";
for(i=0;i<4;i++)
{row=0;
cout<<"District "<<i+1;
for(j=0;j<3;j++)
{cout<<setw(12)<<setprecision(2)<<fixed<<sales[i][j];
row+=sales[i][j];
col[j]+=sales[i][j];
}
cout<<setw(12)<<setprecision(2)<<fixed<<row<<endl;
}
cout<<"Totals ";
for(i=0;i<3;i++)
cout<<setw(12)<<setprecision(2)<<fixed<<col[i];
cout<<endl;
}