Answer:
In C++:
#include<iostream>
using namespace std;
int main() {
int depts[3][4];
char dptcod [3] ={'X','Y','Z'};
for (int rrw = 0; rrw < 3; rrw++) {
for (int cll = 0; cll < 4; cll++) {
cout<<"Dept "<<dptcod[rrw]<<" Q"<<(cll+1)<<": ";
cin>>depts[rrw][cll]; } }
for (int rrw = 0; rrw < 3; rrw++) {
int total = 0;
for (int cll = 0; cll < 4; cll++) {
total+=depts[rrw][cll]; }
cout<<"Dept "<<dptcod[rrw]<<" Total Sales: "<<total<<endl;}
return 0; }
Step-by-step explanation:
This declares the 3 by 4 array which represents the sales of the 3 departments
int depts[3][4];
This declares a character array which represents the character code of each array
char dptcod [3] ={'X','Y','Z'};
This iterates through the row of the 2d array
for (int rrw = 0; rrw < 3; rrw++) {
This iterates through the column
for (int cll = 0; cll < 4; cll++) {
This prompts the user for input
cout<<"Dept "<<dptcod[rrw]<<" Q"<<(cll+1)<<": ";
This gets the input
cin>>depts[rrw][cll]; } }
This iterates through the row of the array
for (int rrw = 0; rrw < 3; rrw++) {
This initializes total sum to 0
int total = 0;
This iterates through the column
for (int cll = 0; cll < 4; cll++) {
This calculates the total sales of each department
total+=depts[rrw][cll]; }
This prints the total sales of each department
cout<<"Dept "<<dptcod[rrw]<<" Total Sales: "<<total<<endl;}
I hope this helps a little bit