Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C++ console app that determines if two 2D arrays (or 2D vectors) are identical. parameters. Should the parameters be declared as constant? Define

image text in transcribed
Write a C++ console app that determines if two 2D arrays (or 2D vectors) are identical. parameters. Should the parameters be declared as constant? Define a boolean function that receives two 2D arrays as input From main, prompt the user to input two 3 x 3 arrays of integers. Pass the arrays to the boolean function and store the return value into a variable. Display the results from main. 1O below that the positions of the values 1 and The order of the elements in the arrays do not matter. Notice in the 1st example I 2 are swapped and the arrays are still considered identical. One approach to solving this problem would be to count the occurrences of each value in the two arrays. The number of occurrences of each value in each array should be the same if the two arrays are identical.Another way of looking at this is that the number of occurrences of any value should be an even number if the two arrays are identical. Recall from CS& 131 the use of a vector to count occurrences. Each element of the vector has an index and a value. The index represents the integer that is being counted and the value represents the number of occurrences of that integer. Note that to use this approach you will need to limit the range of allowed input, for example if you limit the user input to be in the range 11, 100] you would need a vector of size 100 which essentially stores 100 counter variables. Example IO: Please input two 3 x 3 arrays Enter mi: 12315 16 6 788 Enter m2: 2 1 3 15 16 678 The two arrays are identical. Please input two 3 x3 arrays Enter mi: 1 2 3 15 16 6889 Enter n2: 213 15 16 68810 The two arrays are not identical. Another approach would be to use a 2D vector to store the counter variables and the values that they are counting. For example, in 2nd example above. The 2D vector might look like: 2 3 15 166 8 9 10 22 2 2 2 2 4 1 1 Because there is odd number of occurrences of the values 9 and 10, the 2 arrays are not identical

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Management Systems

Authors: Patricia Ward, George A Dafoulas

1st Edition

1844804526, 978-1844804528

More Books

Students also viewed these Databases questions