195k views
5 votes
KDS Company has 3 departments: 1. Dept X 2. Dept Y 3. Dept Z. Design a program that will read as input each department's sales for each quarter of the year, and display the result for all divisions. Use a two dimensional array that will have 3 rows and 4 columns and show how the data will be organized.

1 Answer

0 votes

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

User Sibeesh Venu
by
5.1k points