#include // Function declarations bool are_arrays_equal( int const array1[], int const array2[], std::size_t const capacity ); int main(); int main() { int array11[1]{ 18 }; int array12[1]{ 18 }; int array13[1]{ 42 }; int array21[2]{ 25, 26 }; int array22[2]{ 25, 26 }; int array23[2]{ 25, 27 }; int array31[8]{ 19, 20, 21, 22, 23, 24, 25, 26 }; int array32[8]{ 19, 20, 21, 22, 23, 24, 25, 26 }; int array33[8]{ 19, 20, 21, 22, 23, 24, 24, 26 }; int array41[30]{ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39 }; int array42[30]{ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39 }; int array43[30]{ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 30, 33, 34, 35, 36, 37, 38, 39 }; // The first two should always return 'true' (1) and the third // should always return 'false' (0) std::cout << are_arrays_equal( array11, array11, 1 ) << std::endl; std::cout << are_arrays_equal( array11, array12, 1 ) << std::endl; std::cout << are_arrays_equal( array11, array13, 1 ) << std::endl; std::cout << std::endl; std::cout << are_arrays_equal( array21, array21, 2 ) << std::endl; std::cout << are_arrays_equal( array21, array22, 2 ) << std::endl; std::cout << are_arrays_equal( array21, array23, 2 ) << std::endl; std::cout << std::endl; std::cout << are_arrays_equal( array31, array31, 8 ) << std::endl; std::cout << are_arrays_equal( array31, array32, 8 ) << std::endl; std::cout << are_arrays_equal( array31, array33, 8 ) << std::endl; std::cout << std::endl; std::cout << are_arrays_equal( array41, array41, 30 ) << std::endl; std::cout << are_arrays_equal( array41, array42, 30 ) << std::endl; std::cout << are_arrays_equal( array41, array43, 30 ) << std::endl; std::cout << std::endl; std::cout << are_arrays_equal( array11, array11, 1 ) << std::endl; std::cout << are_arrays_equal( array12, array11, 1 ) << std::endl; std::cout << are_arrays_equal( array13, array11, 1 ) << std::endl; std::cout << std::endl; std::cout << are_arrays_equal( array21, array21, 2 ) << std::endl; std::cout << are_arrays_equal( array22, array21, 2 ) << std::endl; std::cout << are_arrays_equal( array23, array21, 2 ) << std::endl; std::cout << std::endl; std::cout << are_arrays_equal( array31, array31, 8 ) << std::endl; std::cout << are_arrays_equal( array32, array31, 8 ) << std::endl; std::cout << are_arrays_equal( array33, array31, 8 ) << std::endl; std::cout << std::endl; std::cout << are_arrays_equal( array41, array41, 30 ) << std::endl; std::cout << are_arrays_equal( array42, array41, 30 ) << std::endl; std::cout << are_arrays_equal( array43, array41, 30 ) << std::endl; return 0; } // Write a function that determines if all the corresponding entries // of the two argument arrays are equal. If they are all equal, // return 'true', otherwise, return 'false'. // // We should assume both arrays have the same capacity. bool are_arrays_equal( int const array1[], int const array2[], std::size_t const capacity ) { // Enter your implementation here return false; } // See if you can do this in two ways: // The first simpy returns 'false' as soon as two // corresponding entries are determined to be different, // and once all entries have been checked, return 'true'. // // The second sets a flag to be 'true', and if it is ever // determined that two entries are different, set the flag // to 'false'. At the end, return this flag. // Here are multiple solutions. The first has multiple 'return' // statements, while the second has only a single 'return' // statement at the end. /* bool are_arrays_equal( int const array1[], int const array2[], std::size_t const capacity ) { for ( std::size_t k{ 0 }; k < capacity; ++k ) { // If the kth entries differ, the two arrays are not // equal so return false. if ( array1[k] != array2[k] ) { return false; } } // If we have gone through all entries and no correponding // entries were found to differ, the two arrays must be // equal, so return 'true'. return true; } bool are_arrays_equal( int const array1[], int const array2[], std::size_t const capacity ) { // Assume the arrays are equal until we determine otherwise bool found{ true }; for ( std::size_t k{ 0 }; k < capacity; ++k ) { // If we find two corresponding entries that are // different, set 'found' to 'false' and break // out of this loop: // - There is no more point in searching, // the arrays are unequal if ( array1[k] != array2[k] ) { found = false; break; } } // Return whatever 'found' is finally set to: return found; } */