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

Please help on this problem .I need the C++ program source code Comparing the pa

ID: 3552838 • Letter: P

Question

Please help on this problem .I need the C++ program source code

Comparing the pattern"new_Test_Patterns.txt" against InputMatrix.txt, requirement as shown below

Appreicate if you could provide me with comments for the source code this will enable me to understand the program.

I'm using Microsoft Visual C++ 2008 Express version


File Reading and Writing syntax and

procedures. Sample file reading/writing code is given at the end of this

document. You may wish to use this or implement your own code. You need

to conduct 2 test runs.


Patterns can be found almost everywhere. For instance, while processing an

image file, to detect any specific patterns embedded in the original image,

the original will be first converted to equivalent grey scale comprising either

0 or 1 representation. The specific patterns are then searched on this original

image. Following is the problem statement in this application context.

Problem Statement: Consider a matrix (see the file

InputMatrix.txt) of size N x N comprising of numbers 0 or

1. Given such a matrix, problem is to find the location of a

given pattern. For example, if the pattern to be searched is

as follows:

X 0 0 1

0 X 0 0

X X 0 1 (X: don

Explanation / Answer


#include <iostream>
#include <fstream>

using namespace std;

int main(int argc, char *argv[]) {
string file, pattern;
size_t x = 0, count = 0;

cout << "Text file name : ";
getline(cin, file);
ifstream myfile(file.c_str());

if (myfile.is_open()) {
string text((istreambuf_iterator<char>(myfile))... istreambuf_iterator<char>());
myfile.close();
if (text.size() > 0) {
do {
cout << "Enter pattern to find: ";
getline(cin, pattern);
} while (pattern.size() == 0);
do {
if ((x = text.find(pattern, x)) != string::npos) {
++count;
++x;
}
} while (x != string::npos);

cout << """ << pattern << "" found " << count << " time"
<< ((count != 1) ? "s" : " ") << endl;
} else {
cout << file << " is empty" << endl;
}
} else {
cout << "error opening " << file << endl;
}
return(0);
}

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