Question: Write a program that does the following in C++: Read in up to 100 positive non-zero integers. Your input should come from the keyboard, not
Write a program that does the following in C++:
- Read in up to 100 positive non-zero integers. Your input should come from the keyboard, not a file. Your program should not crash if bad data are entered, such as negative numbers, letters, etc. You can use a sentinel value such as zero to indicate the end of your input.
- Allocate a matrix of n+1 x n+1 and arrange the numbers across the top and down the left side, as shown in the diagram below (although it shows them along the bottom.)
- Allocate a new matrix of exactly the size of your original and copy the original to it.
- Create a sum grid for one of the matrices and a product grid for the other. That is, for the first one, add, for example, the numbers in position 1, 1 (in the example below assuming that 0,0 is the bottom left) and put the result in the 2,1 position. And so on.
- In the other matrix, create a product gird using a similar process, except with multiplication.
- Print both grids neatly and labeled. You can print them one under the other. Use a column width of 7 spaces, and right-justify the numbers.
- For each grid, determine how many unique sums or products there are and the frequency of each one. For example, in the sum grid shown, there are 7 unique numbers, from 2 to 8. The value 2 occurs once, three occurs twice 8 occurs once. Display this information in a column. Obviously the maximum number of unique sums or products is n^2 (read as n squared,) so allocate a linear array of this size for tracking the counts. You may not need all of it, so keep track of how it has been filled.
- Return to the start and ask for another set of numbers. Stop if zero is entered for the first number.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
