CODE
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
class LineData {
public:
int lineNumber;
string text;
LineData(int num, const string &txt) {
lineNumber = num;
text = txt;
};
class FileData {
private:
vector<LineData> lines;
bool caseInsensitive;
public:
string filename;
FileData(const string &file, bool caseInsensitiveFlag) {
filename = file;
caseInsensitive = caseInsensitiveFlag;
readFile();
void readFile() {
ifstream inputFile(filename);
string line;
int lineNumber = 0;
if (!inputFile.is_open()) {
cerr << "Error opening file: " << filename << endl;
return;
while (getline(inputFile, line)) {
lineNumber++;
if (caseInsensitive)
line = toLower(line);
lines.push_back(LineData(lineNumber, line));
inputFile.close();
const vector<LineData>& getLines() const {
return lines;
static string toLower(const string &str) {
string lowered = str;
transform(lowered.begin(), lowered.end(), lowered.begin(), ::tolower);
return lowered;
}
};
class PlagiarismChecker {
private:
FileData mainFile;
vector<FileData> otherFiles;
public:
PlagiarismChecker(const string &mainFilename, const vector<string> &otherFilenames, bool
caseInsensitive)
: mainFile(mainFilename, caseInsensitive) {
for (const string &file : otherFilenames) {
otherFiles.push_back(FileData(file, caseInsensitive));
void compareFiles() {
const vector<LineData>& linesA = mainFile.getLines();
if (linesA.empty()) {
cerr << "Main file is empty or could not be opened.\n";
return;
for (const auto& file : otherFiles) {
const vector<LineData>& linesOther = file.getLines();
if (linesOther.empty()) {
cerr << "Skipping file: " << file.filename << " (empty or error opening)\n";
continue;
}
cout << "\nComparing " << mainFile.filename << " with " << file.filename << ":\n";
bool matchFound = false;
for (const auto &a : linesA) {
for (const auto &b : linesOther) {
if (a.text == b.text) {
cout << " Match Found!\n";
cout << " -> " << mainFile.filename << " (line " << a.lineNumber << "): " << a.text << "\
n";
cout << " -> " << file.filename << " (line " << b.lineNumber << "): " << b.text << "\n\n";
matchFound = true;
if (!matchFound) {
cout << " No matches found between " << mainFile.filename << " and " << file.filename <<
".\n";
};
int main() {
string fileA = "fileA.txt";
vector<string> otherFiles = {"fileB.txt", "fileC.txt", "fileD.txt", "fileE.txt"};
bool caseInsensitive = true;
PlagiarismChecker checker(fileA, otherFiles, caseInsensitive);
checker.compareFiles();
return 0;