1 2 3 4 5 6 7 8 9 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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <string>
#include <sstream>
using namespace std;
int total_size;
int blob_check(int[50][50], int, int); /* Checks for picture blob size in the grid */
int main(void)
{
/* Declare variables */
int grid[50][50], /* The picture grid */
x_count, /* Counts the rows in the grid */
y_count, /* Counts the columns in the grid */
blob_size; /* The cell number size of the picture blob */
ifstream InputFile;
string fileName;
string line;
char num [225];
int a = 0;
cout << "Enter the file name: ";
cin >> fileName;
InputFile.open(fileName);
if (InputFile)
{
while (getline(InputFile, line))
{
if(line.begin() != line.end())
{
if (a <= 15)
{
cout << line;
cout << endl;
a++;
}
}
}
}
else
{
cout << "Error: This file could not open." << endl;
}
cout << ("\n\n\t ");
/* Count the size of the picture blob */
blob_size = blob_check(grid, 0, 1);
/* Display the size number */
cout << "\nThe picture blob has a cell sizes of \n" << total_size << endl;
cin.ignore();
cin.get();
return 0;
}
int blob_check(int pic_grid[50][50], int x, int y)
{
/* The cell number size of the picture blob */
/* Count size of picture blob */
if (pic_grid[x][y] == 0 || (x < 0 || x > 4) || (y < 0 || y > 4))
total_size = 0;
else
{
pic_grid[x][y] = 0;
total_size = 1 + blob_check(pic_grid, x, y) + blob_check(pic_grid, x + 1, y + 1) + blob_check(pic_grid, x - 1, y - 1) +
blob_check(pic_grid, x + 1, y) + blob_check(pic_grid, x - 1, y) + blob_check(pic_grid, x, y + 1) + blob_check(pic_grid, x, y - 1) +
blob_check(pic_grid, x + 1, y - 1) + blob_check(pic_grid, x - 1, y + 1);
}
return total_size;
}
|