Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ANSWER IN C PLEASE DUE 11TH MARCH There are 3 tasks to be completed. Task 1 - The first function gets a 10x10 two- dimensional

ANSWER IN C PLEASE DUE 11TH MARCH

There are 3 tasks to be completed.

Task 1 - The first function gets a 10x10 two- dimensional array and return the number of distinct cells. This array represents each unique cell with a unique number. Please see the right picture below in which you can see there are 7 distinct cells, each represented with a unique number. If the right picture below is sent to this function, it should return 7, as there are 7 distinct groups of data.

Task 2 - The second function labels each cell with a unique number. For example, if the given image (i.e., two-dimensional array) is something like the left picture below, one sample solution can be something like the right picture. It is not important how you choose the numbers for the cell, as long as it is not zero or a negative number. Also, the numbers do not need to be in a consecutive order. For example, one might label the cells in the example below with arbitrary numbers of 20, 3, 4, 8, 18, 7, 1.

image text in transcribed

Task 3 -

image text in transcribed

#include

#include

#define IMAGE_SIZE 10

// this function prints the array

void printImgArray(int array[IMAGE_SIZE][IMAGE_SIZE])

{

printf("------ Image Contents ------- ");

for (int i=0; i

{

for (int j=0; j

printf("%02d, ",array[i][j]);

printf(" ");

}

printf("----------------------------- ");

}

/**

* This function counts the number of distinct

* number (i.e. the number of cells)

**/

int cellCount(int image[IMAGE_SIZE][IMAGE_SIZE]){

// insert code for Task 1 here

// you may want to change the return value.

return 0;

}

/**

* This function colors each cell with a unique color

* (i.e. unique number)

**/

void color(int image[IMAGE_SIZE][IMAGE_SIZE]){

// Insert Code for Task 2 here

}

void colorPtr(int* image){

// Insert Code for Task 3 here

}

#ifndef __testing

int main(){

// DO not change anything in main(), it will confuse the

// auto-checker.

puts("testing the code with color() function");

int count = 0;

int cellImg[IMAGE_SIZE][IMAGE_SIZE]={{0,0,1,1,0,0,1,0,0,1},\

{1,0,1,1,0,0,1,1,0,1},\

{1,0,0,1,1,0,1,1,0,1},\

{1,1,0,0,0,0,0,0,0,0},\

{1,0,0,1,1,1,0,0,1,0},\

{0,0,0,0,1,0,0,1,1,0},\

{0,0,1,0,0,1,0,1,0,0},\

{0,0,1,1,0,0,1,0,0,0},\

{0,0,1,0,0,0,0,0,1,1},

{0,1,1,0,0,0,1,1,1,1}};

printImgArray(cellImg);

color(cellImg);

printImgArray(cellImg);

count=cellCount(cellImg);

printf("Total number of cells in the image: %d ",count);

puts("Testing the code with colorPtr");

int cellImg_[IMAGE_SIZE][IMAGE_SIZE]={{0,0,1,1,0,0,1,0,0,1},\

{1,0,1,1,0,0,1,1,0,1},\

{1,0,0,1,1,0,1,1,0,1},\

{1,1,0,0,0,0,0,0,0,0},\

{1,0,0,1,1,1,0,0,1,0},\

{0,0,0,0,1,0,0,1,1,0},\

{0,0,1,0,0,1,0,1,0,0},\

{0,0,1,1,0,0,1,0,0,0},\

{0,0,1,0,0,0,0,0,1,1},

{0,1,1,0,0,0,1,1,1,1}};

int* ptr = cellImg_;

printImgArray(ptr);

colorPtr(ptr);

printImgArray(ptr);

count=cellCount(ptr);

printf("Total number of cells in the image: %d ",count);

puts("Testing the code with colorRecursively");

int cellImg__[IMAGE_SIZE][IMAGE_SIZE]={{0,0,1,1,0,0,1,0,0,1},\

{1,0,1,1,0,0,1,1,0,1},\

{1,0,0,1,1,0,1,1,0,1},\

{1,1,0,0,0,0,0,0,0,0},\

{1,0,0,1,1,1,0,0,1,0},\

{0,0,0,0,1,0,0,1,1,0},\

{0,0,1,0,0,1,0,1,0,0},\

{0,0,1,1,0,0,1,0,0,0},\

{0,0,1,0,0,0,0,0,1,1},

{0,1,1,0,0,0,1,1,1,1}};

printImgArray(cellImg__);

colorRecursively(cellImg__, 0, 0, 1, 0);

printImgArray(cellImg__);

count=cellCount(cellImg__);

printf("Total number of cells in the image: %d ",count);

return 0;

}

#endif

void color (int image (IMAGE_SIZE] [IMAGE_SIZE]); This function gets the 10x10 two-dimensional array (like the left picture) and label each group of 1s (a distinct cell) with a unique number (like the right picture). 0 0 1 1 0 0 1 0 0 1 1 0 1 1 0 0 1 1 0 1 1 0 0 1 1 0 1 1 0 1 1100000000 1 0 0 1 1 1 0 0 1 0 0000100110 0 0 1 0 0 1 0 1 0 0 0 0 1 1 0 0 1 0 0 0 0 0 100000 1 1 0 1 1 0 0 0 1 1 1 1 002 2003 004 10 2200 3 3 0 4 10 0 2 2 0 3 3 0 4 11 1005 5 5 0 0 5 0 0000 50 0 5 5 0 0060050500 00 6600 5000 00600000 77 0 7777 To solve this problem, you are free to define as many helper functions as required. To test your code, we only look at the return value and the content of the array, expecting that each blood cell is labeled with a unique number. For this task I'd like you to re-implement function color(), where the input parameter is defined as a pointer. For this, you require to use pointer arithmetic instead of using array indices to get access to the elements of the array. The function signature is: void colorper (int image); Hint: You have already learned in the lecture as to how get access to the element of the arrays using a pointer. So if ptr, is pointer that holds the address of the first element of your array li.e. int* ptr - &array[0]), then ptrt1, ptr+2, .ptrti points to the second, third and 1+1 element of the array. If ptr points to a first element of two-dimensionals array (ie. int ptr - 6 array [0] [0]) and the array has n columns then array[i][j] can be accessed via (array+ ( in) + 3). Suppose you define the array as int array[4] [3]. Int this casen 3, therefore array+ (i * 3) + 3 will give you the address of the elements at index []G). The memory that is assigned to this array looks like below: 100 101 302 103 104 105 106 107 108 109 110 111 Memory Address Array's Elements a fool alon 2013 Bull alu 021 12101 aalul 121121 all gal void color (int image (IMAGE_SIZE] [IMAGE_SIZE]); This function gets the 10x10 two-dimensional array (like the left picture) and label each group of 1s (a distinct cell) with a unique number (like the right picture). 0 0 1 1 0 0 1 0 0 1 1 0 1 1 0 0 1 1 0 1 1 0 0 1 1 0 1 1 0 1 1100000000 1 0 0 1 1 1 0 0 1 0 0000100110 0 0 1 0 0 1 0 1 0 0 0 0 1 1 0 0 1 0 0 0 0 0 100000 1 1 0 1 1 0 0 0 1 1 1 1 002 2003 004 10 2200 3 3 0 4 10 0 2 2 0 3 3 0 4 11 1005 5 5 0 0 5 0 0000 50 0 5 5 0 0060050500 00 6600 5000 00600000 77 0 7777 To solve this problem, you are free to define as many helper functions as required. To test your code, we only look at the return value and the content of the array, expecting that each blood cell is labeled with a unique number. For this task I'd like you to re-implement function color(), where the input parameter is defined as a pointer. For this, you require to use pointer arithmetic instead of using array indices to get access to the elements of the array. The function signature is: void colorper (int image); Hint: You have already learned in the lecture as to how get access to the element of the arrays using a pointer. So if ptr, is pointer that holds the address of the first element of your array li.e. int* ptr - &array[0]), then ptrt1, ptr+2, .ptrti points to the second, third and 1+1 element of the array. If ptr points to a first element of two-dimensionals array (ie. int ptr - 6 array [0] [0]) and the array has n columns then array[i][j] can be accessed via (array+ ( in) + 3). Suppose you define the array as int array[4] [3]. Int this casen 3, therefore array+ (i * 3) + 3 will give you the address of the elements at index []G). The memory that is assigned to this array looks like below: 100 101 302 103 104 105 106 107 108 109 110 111 Memory Address Array's Elements a fool alon 2013 Bull alu 021 12101 aalul 121121 all gal

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

Students also viewed these Databases questions

Question

2. Define communication.

Answered: 1 week ago