Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ vectors: count holes function needed. readImage: Creates a two dimensional v

ID: 3853382 • Letter: C

Question

C++ vectors:

count holes function needed.

readImage: Creates a two dimensional vector (a matrix) of 1's and 0's based off of the input files which you send it.

printImage: Takes the matrix which was created in readImage and prints it out.

countHoles: You must come up with a way to iterate through the matrix which you have been dealing with in the past two functions and identify where, and what type, of holes are in the data. Internal holes (i) are made up of three 0's and one 1; External holes (e) are made up of three 1's and one 0. All other combinations are meaningless and should not be taken into account. Then, with the number of external and internal holes that you determined, use the formula provided ((#e - #i) / 4) to determine how many holes are in the matrix as a whole.

Explanation / Answer

#include <stdio.h>

/* Routines called. */
int readImage(char* filename, int* data);
void printImage(int* data, int len);

void main(void)
{
char key;
int len, data[1000];

printf("Hello TV Land! ");

len = readNums("Numbers.txt", data);

showData(data, len);

scanf("%c", &key);
}

int readImage(char* filename, int* data)
{
FILE* in;
int len;
int j;

in = fopen("Numbers.txt", "r");

if (in == NULL) {
printf("Could not find file: %s ", filename);
}
else {
printf("Reading numbers... ");

fscanf(in, "%d", &len);

printf("reading %d numbers from file %s .... ", len, filename);

for (j = 0; j < len; j++) {
fscanf(in, "%d", data + j);
}

fclose(in);
}

return len;
}

void printImage(int* data, int len)
{
int j;

printf("Showing %d numbers from data array.... ", len);
for (j = 0; j < len; j++) {
printf("%d ", *(data + j));
}
printf(" ");
}

void printCountHoles()
{

int N;
bool flag;

//Open data files to read in data
ifstream myfile("data1.txt");

if (myfile.is_open()) {
//read in the size of the matrix
myfile >> N;

//declare double pointer matrix
int** matrix = new int*[N];

//Allocate Memory
for (int i = 0; i < N; i++) {
matrix[i] = new int[N];
}

//make sure fileis not at end and read int the contents into the array matrix
while (myfile.good()) {
char filename[5];
for (int i = 0; filename[i] != ''; i++)
filename[i] = '';
for (int i = 0; i <= 8; i++) {
filename = "file" + (i + '0');
ifstream myfile(filename);
printf("Number of CountHoles:" + PrintImage());
}
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote