QuestionQuestion

Transcribed TextTranscribed Text

In this assignment you are to consider a rectangular grid, some of whose cells contain periods and some asterisks. For example on an 8x8 grid, we could have something similar to the following: .**.**. ..**..*. Two cells are contiguous if they are adjacent to each other in the same row or the same column. We will then define a blob as follows: A blob contains at least one asterisk If an asterisk is in a blob, then so is any asterisk that is contiguous to it. If a blob has more than two asterisks, then each asterisk in it is contiguous to at least one other asterisk in the blob. You are to write a program that determines the number of blobs and the placement of these blobs within a grid. The grid above contains 13 blobs. You will indicate individual blob placement by assigning each blob a distinct letter (starting with a and incrementing each time a new blob is encountered. aa aa..b..c dd.ee. .dd..e. .f..g...) ii.jj. ii.jj. k..l..m The grid shown above would be part of the output indicating the blob placement. Output should also include the number of blobs contained in the grid. Design Notes You can use an (m+2)x(n+2) array with the additional rows and columns containing periods to be used as a frame around the grid. This will simplify processing of the blobs. ** This would be the actual grid that will be processed. The main idea is to traverse the grid row by row and for each asterisk, call a function that processes the cell. The asterisk should be replaced by the proper letter. Using up to four recursive calls in the function, you should process each of the other asterisks in the blob. Remember that you can add one to a char variable to increase its letter value. 'a' + 1 results in 'b' and so on. Requirements: remaining lines will be the grid itself. The input file for the program will contain the size of the grid on the first line and the The array must be dynamically allocated and its size is determined by the input file. The grid array must be freed properly when no longer needed. There will be no more than 52 blobs in any grid so the regular English alphabet using both lower and upper cases will be sufficient for the blob identification. You should use lower case first and switch to upper when you have processed a blob using 'Z'. You can assume that there will be no array larger than 100 x 100 and if the input indicates a larger array, you should print an error message and exit. You should use separate functions for reading the input file, creating the output file and processing the grid to locate blobs. The output should be written to the specified file and should contain the information listed above. You should pass the input and output file names in through the command line and process it within main as shown in class.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

#include <stdio.h>
#include <stdlib.h>
char * readFile(FILE * file, int * row, int * col){
    char * grid, * buf; int i, j, currentIndex, total; char ch; fscanf(file, "%d %d", row, col); if (*row < 0 || *row > 100 || *col < 0 || *col > 100) { perror("array larger than 100x100"); return NULL; }   
    total = (*row) *(*col); grid = (char *) calloc( total + 1, sizeof(char)); i = 0; while (i < total && fscanf(file, "%c", &ch) == 1) { if (ch == '*' || ch == '.') { grid[i] = ch; i++; } } return grid;
}
void blobbing(char * grid, int index, int row, char letter){
    if ( grid[index] == '*') { grid[index] = letter; blobbing(grid, index + row, row, letter); blobbing(grid, index - row, row, letter); blobbing(grid, index + 1, row, letter); blobbing(grid, index - 1, row, letter); }
}
int fillBlob(char * grid, int row, int col){   
    int i, length, blobNum ; char letter...

By purchasing this solution you'll be able to access the following files:
main.c and input.txt.

50% discount

Hours
Minutes
Seconds
$23.00 $11.50
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats