Question

In: Computer Science

1. Two 2-D arrays A [ ] [ ] and B [ ] [ ] are...

1. Two 2-D arrays A [ ] [ ] and B [ ] [ ] are of type boolean and represent two black and white images ( 1’s (black) and 0’s (white) ) having the same size (n x m).
Implement a Boolean function to receive these two images(arrays) as an input and return true if A is the negative of B (i.e. each pixel of A is the complement of the corresponding pixel of B) and false otherwise.

Solutions

Expert Solution

CODE SCREENSHOTS:

OUTPUT SCREENSHOT:

CODE:

#include <bits/stdc++.h>
#define SIZE 100
using namespace std;
bool check(int m, int n, int a[][SIZE], int b[][SIZE])
{
    for (int i = 0; i < m; i++)
        for (int j = 0; j < n; j++)
            if (a[i][j] == b[i][j]) // if the pixel is same return false
                return false;
    return true;
}
int main()
{
    int m, n;
    cout << "\nEnter the dimensions: ";
    cin >> m >> n;
    int a[SIZE][SIZE], b[SIZE][SIZE];
    cout << "\nEnter array A:\n"; // Input array A
    for (int i = 0; i < m; i++)
        for (int j = 0; j < n; j++)
            cin >> a[i][j];
    cout << "\nEnter array B:\n"; // Input array B
    for (int i = 0; i < m; i++)
        for (int j = 0; j < n; j++)
            cin >> b[i][j];

    if (check(m, n, a, b)) // check function called
        cout << "\nTrue\n";
    else
        cout << "\nFalse\n";
    return 0;
}

Please comment in case of doubts or queries.
It would be really helpful if you upvote :)


Related Solutions

1) a) Give short code example of parallel arrays. b) Explain how parallel arrays work. 2)...
1) a) Give short code example of parallel arrays. b) Explain how parallel arrays work. 2) a) How would you compare two arrays to check if they have the same values? b) Assume array1 and array2 are int arrays with 10 elements in each. if(array1 == array2) What is this comparing? 3 a) Can you encounter memory violation using an array? b) If yes explain. If no, explain why not.
Given two arrays: A[0..m-1] and B[0..n-1]. Find whether B[] is a subset of A[] or not....
Given two arrays: A[0..m-1] and B[0..n-1]. Find whether B[] is a subset of A[] or not. Both the arrays are not in sorted order. It may be assumed that elements in both array are distinct. Design an O(n) time algorithm that solves this problem. Provide pseudocode Ex: Input: A[] = {11, 1, 13, 21, 3, 7}, B[] = {11, 3, 7, 1} Output: B[] is a subset of A[] Input: A[] = {1, 2, 3, 4, 5, 6}, B[] =...
Part 1: answer (a), (b), (c), and (d). Part 2: answer (a), (b), (c), and (d)....
Part 1: answer (a), (b), (c), and (d). Part 2: answer (a), (b), (c), and (d). Godspeed, and good luck!!! CC11 Cookie Creations Natalie and her friend Curtis Lesperance decide that they can benefit from joining Cookie Creations and Curtis’s coffee shop. In the first part of this problem, they come to you with questions about setting up a corporation for their new business. In the second part of the problem, they want your help in preparing financial information following...
java by using Scite Objectives: 1. Create one-dimensional arrays and two-dimensional arrays to solve problems 2....
java by using Scite Objectives: 1. Create one-dimensional arrays and two-dimensional arrays to solve problems 2. Pass arrays to method and return an array from a method Problem 2: Find the largest value of each row of a 2D array             (filename: FindLargestValues.java) Write a method with the following header to return an array of integer values which are the largest values from each row of a 2D array of integer values public static int[] largestValues(int[][] num) For example, if...
java by using Scite Objectives: 1. Create one-dimensional arrays and two-dimensional arrays to solve problems 2....
java by using Scite Objectives: 1. Create one-dimensional arrays and two-dimensional arrays to solve problems 2. Pass arrays to method and return an array from a method Problem 1: Find the average of an array of numbers (filename: FindAverage.java) Write two overloaded methods with the following headers to find the average of an array of integer values and an array of double values: public static double average(int[] num) public static double average(double[] num) In the main method, first create an...
In arduino: 1.Given two Arrays A= {2,4,7,8,3) and B={11,3,2,8,13). Write a program that find the numbers...
In arduino: 1.Given two Arrays A= {2,4,7,8,3) and B={11,3,2,8,13). Write a program that find the numbers into A but not in B. For the example C=A-B= {4,7} Print the values (Use for loops) 2.Create a vector of five integers each in the range from -10 to 100 (Prompt the user for the five integer x). Perform each of the following using loops: a) Find the maximum and minimum value b)Find the number of negatives numbers Print all results
Write a method weave that takes two arrays of ints, a and b, and that returns...
Write a method weave that takes two arrays of ints, a and b, and that returns an array that contains the elements of a and b in the order a[0], b[0], a[1], b[1], etc. If one of the arrays a or b is longer than the other, just add the extra elements at the end of the array. In your solution, you can use only 3 arrays, namely the two arrays a, and b passed to the method and the...
1. Evaluate: (a+b)/(c-d) + 9/(a+d) when a=5, b=3, c=8, d=4 a. 6 b. 3 c. 15/2...
1. Evaluate: (a+b)/(c-d) + 9/(a+d) when a=5, b=3, c=8, d=4 a. 6 b. 3 c. 15/2 d. 17/13 2. Solve for x: 5(x+3) = 35 a. 2 b. 7 c. 4 d. -4 3. Acid rain occurs primarily as a result of a. operating a nuclear power plant b. burning coal or oil containing sulfur c. by-products created by operating an oil refinery d. the use of Freon and other refrigerants 4. The "ozone holes" at the polar region arise...
Atomicity of phosphorus is (a) 1 (b) 2 (c) 3 (d) 4
Atomicity of phosphorus is ________.(a) 1(b) 2(c) 3(d) 4
You are given two integer arrays a and b of the same length. Let's define the...
You are given two integer arrays a and b of the same length. Let's define the difference between a and b as the sum of absolute differences of corresponding elements: difference = |a[0] - b[0]| + |a[1] - b[1]| + ... + |a[a.length - 1] - b[b.length - 1]| You can replace one element of a with any other element of a. Your task is to return the minimum possible difference between a and b that can be achieved by...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT