Use a two-dimensional array to solve the following problem. A company has four salespeople (1 to 4) who sell five different products (1 to 5). Once a day, each salesperson passes in a slip for each different type of product sold.

Each slip contains the following:
a) The salesperson number
b) The product number
c) The total dollar value of that product sold that day

Thus, each salesperson passes in between 0 and 5 sales slips per day. Assume that the information from all of the slips for last month is available. Write a program that will read all this information for last month’s sales and summarize the total sales by salesperson by product. All totals should be stored in the two-dimensional array sales. After processing all the information for last month, print the results in tabular format with each of the columns representing a particular salesperson and each of the rows representing a particular product. Cross total each row to get the total sales of each product for last month; cross total each column to get the total sales by salesperson for last month. Your tabular printout should include these cross totals to the right of the totaled rows and to the bottom of the totaled columns


that's the exercise i want to do.English is NOT my first language,that's why i am confused.

i want to clear that i dont ask for code or anything similar.i know how to solve it but dont know how to start cause that i dont understand a part of it.
the bold part is what i dont understand.

what it asks to create an array like in array[x][y]={values of last month}?
or asks to make a loop and ask every time for the slip?
or something else?

answer me using words or example,not code please,i am beginner and i prefer to write alone the code.

Recommended Answers

All 5 Replies

There are 4 salespeople and 5 products. Let's number the salespeople 0 through 3 and the products 0 through 4. Then the problem is asking you to create a 4 by 5 array, where each row represents a different salesperson and each column represents a different product.

So, for example, sales[2][3] would hold the information for salesperson number 2 and product number 3.

Your problem is to read all of the slips. For each slip:

1) Find which array element corresponds to the information on the slip.
2) Update that array element with the information from the slip.

When you are done, figure out how to print the whole array.

int sales[6][5];

Row indexes are 0 to 5. Rows 0 to 4 represent each product. Row 5 is a totals row.
Column indexes are 0 to . Column 0 to 3 represent each salesman. Column 4 is a totals row.

If salesman 2 sells $10 of product 1, then sales[1][2] would equal 10.

Fill in rows 0 to 4/columns 0 to 3 with input. Row 5/column 4 is calculated based on summing the input rows/columns.

How you fill in the rows/columns isn't mentioned, so I imagine that's up to you. Read it from a file or read it in with cin statements or hard-code it.

Use a two-dimensional array to solve the following problem. A company has four salespeople (1 to 4) who sell five different products (1 to 5). Once a day, each salesperson passes in a slip for each different type of product sold.

Each slip contains the following:
a) The salesperson number
b) The product number
c) The total dollar value of that product sold that day

Thus, each salesperson passes in between 0 and 5 sales slips per day. Assume that the information from all of the slips for last month is available. Write a program that will read all this information for last month’s sales and summarize the total sales by salesperson by product. All totals should be stored in the two-dimensional array sales. After processing all the information for last month, print the results in tabular format with each of the columns representing a particular salesperson and each of the rows representing a particular product. Cross total each row to get the total sales of each product for last month; cross total each column to get the total sales by salesperson for last month. Your tabular printout should include these cross totals to the right of the totaled rows and to the bottom of the totaled columns


that's the exercise i want to do.English is NOT my first language,that's why i am confused.

i want to clear that i dont ask for code or anything similar.i know how to solve it but dont know how to start cause that i dont understand a part of it.
the bold part is what i dont understand.

what it asks to create an array like in array[x][y]={values of last month}?
or asks to make a loop and ask every time for the slip?
or something else?

answer me using words or example,not code please,i am beginner and i prefer to write alone the code.

You're right it was a little confusing to me. "Summarize the total sales by salesperson by product."--this is a little misleading. Just ignore that and keep reading, and it becomes clear.

For this assignment you should assume that the sales slips are from a file. Truly, your instructor should provide you with a text file so you can test your program. Your first step would be to generate your own text file with the format:
num1 num2 num3
num1 num2 num3
where num1 is the salesperson 1-4, num2 is the product 1-5, and num3 is how much they sold it for. So just make up some numbers until you have 10 or so lines.
Read those values from the file into variables. Since they specify you use a 2d array, you should set it up like this:
int your_array[4][5];
Where [4] represents salesperson, and [5] represents the total sales of that product for each salesperson. Use float instead of int if you need to include cents.
Let me clarify: After reading in a slip, lets say it the slip is: "1 4 300"
You would read "1" into num1, "4" into num2, and "5" into num3.
Then:
your_array[num1 - 1][num2 - 1] += num3; //where the "-1" is since you start at 0 not 1.

From there you should have all the information you need to make your rows and columns.
-Greywolf

my instructor is the book c++ how to program :P

How you fill in the rows/columns isn't mentioned, so I imagine that's up to you. Read it from a file or read it in with cin statements or hard-code it.

actually thats my problem not the rest.
i dont know how to read from files yet.
But i understood more or less what to do.
i will just create an array with the values at declaration.
and fix it.

thanks all for your answer

>> Then the problem is asking you to create a 4 by 5 array, where each row represents a different salesperson and each column represents a different product.

The rows versus columns is backwards. It would be a 5 x 4, not a 4 x 5.

each of the columns representing a particular salesperson and each of the rows representing a particular product.

And it needs to be a 6 x 5 since the totals are stored in the array, so they need a row/column too, at least that was my interpretation, though one could interpret each individual cell as a "total" (since it is) too. Anyway, you have to store the row and column totals somewhere, so one might as well add a column and row for the cross totals even if that isn't mandated, just for ease of computation.

All totals should be stored in the two-dimensional array sales.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.