Using your FileReader and TupleSearching algorithm, read the "Tuple.csv" file. Store each element in: vector tupleVector. 2. Read, using your FileReader, the PunchCard.txt file. Each Punch Card represents a matrix of 12 rows and 80 columns: -------------------------------------------------------------------------------- Y 00000000000000000000000000000000000000000000000000000000000000000000000000000000 X 00000000000000000000000000000000000000000000000000000000000000000000000000000000 0 10000000000000000000000000000000000000000000000000000000000000000000000000000000 1 01000000000000000000000000000000000000000000000000000000000000000000000000000000 2 00100000000000000000000000000000000000000000000000000000000000000000000000000000 3 00010000000000000000000000000000000000000000000000000000000000000000000000000000 4 00001000000000000000000000000000000000000000000000000000000000000000000000000000 5 00000100000000000000000000000000000000000000000000000000000000000000000000000000 6 00000010000000000000000000000000000000000000000000000000000000000000000000000000 7 00000001000000000000000000000000000000000000000000000000000000000000000000000000 8 00000000100000000000000000000000000000000000000000000000000000000000000000000000 9 00000000010000000000000000000000000000000000000000000000000000000000000000000000 -------------------------------------------------------------------------------- Each card in the data file is seperated by dashed lines. The matrix is 12x80. To read the file, read a line, store the 80 characters in a string and store the string in a Translation vector: vector translate. While the line-count is less than 13, read and translate the next line. Process the in-memory matrix and then read the next card. 3. To Process the matrix, read the rows by the 80 columns. Each complete column is a EBDIC character. Lookup the EBDIC character in the tupleVector and find the ASCII character in the found tuple. Repeat for each character in the file. The end result is English readable text. 4. Design a Decryption class to model the decryption process as outlined in step 3. Your Decryption class needs a Process function CallBack, as each encrypted file is encrypted differently. The class should also contain a vector for the translated strings. Determine which member functions are appropriate for decryption behavior. To answer that question, ask yourself: "What methods would you expect from a Decryption class?" FileReader.cpp #include #include #include #include #include #include #include #include using namespace std; class FileReader { private: string fileName; int fileSize; vector rawData; function callback; public: FileReader(string name, function cb) { fileName = name; callback = cb; } int size() { return fileSize; } string name() { return fileName; } vector raw() { return rawData; } void parse() { // Read the file into the raw data vector ifstream f(fileName, ios::out | ios::app | ios::binary | ios::ate); f.seekg(0, ios::end); fileSize = f.tellg(); f.seekg(0, ios::beg); rawData.resize(fileSize); f.read(rawData.data(), fileSize); string rawDataStr(rawData.begin(), rawData.end()); rawDataStr = callback(rawDataStr); vector newRawData(rawDataStr.begin(), rawDataStr.end()); rawData = newRawData; } }; // Define a regex callback function for parsing binary files string RemoveSpace(string s) { regex nonSpace(" "); return regex_replace(s, nonSpace, ""); } // Search void searchInVector(vector> tupleVector) { vector> searchVector; searchVector.push_back(make_tuple("082", "A8", '=')); auto itr = search(tupleVector.begin(), tupleVector.end(), searchVector.begin(), searchVector.end(), [](auto& i1, auto& i2) { return (get<0>(i1) == get<0>(i2) || get<1>(i1) == get<1>(i2) || get<2>(i1) == get<2>(i2)); }); if (itr != tupleVector.end()) cout << "Tuple found: " << get<0>(*itr) << " " << get<1>(*itr) << " " << get<2>(*itr) << '\n'; else cout << "Tuple not found."; } int main() { // Read a csv file FileReader csvFileReader("Tuple.csv", RemoveSpace); csvFileReader.parse(); cout << "File name: " << csvFileReader.name() << endl; cout << "File size: " << csvFileReader.size() << " bytes." << endl; cout << "Parsed Data: " << endl; for (char c : csvFileReader.raw()) { cout << c; } cout << endl << endl; // Store data in vector tuple vector> tupleVector; ifstream infile("Tuple.csv"); string line; string code; string column; char ascii; while (getline(infile, line)){ stringstream ss(line); getline(ss, code, ','); getline(ss, column, ','); ss >> ascii; tupleVector.push_back(tuple (code, column, ascii)); } infile.close(); // Print the content of the vector cout << "Data in vector tuple: " << endl; for (const auto& i : tupleVector) { cout << get<0>(i) << " " << get<1>(i) << " " << get<2>(i) << endl; } cout << endl; searchInVector(tupleVector); return 0; }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

Using your FileReader and TupleSearching algorithm, read the "Tuple.csv" file. Store each element in: vector<MyTuple<string,string,char> tupleVector.

2. Read, using your FileReader, the PunchCard.txt file. Each Punch Card represents a matrix of 12 rows and 80 columns:
--------------------------------------------------------------------------------
Y 00000000000000000000000000000000000000000000000000000000000000000000000000000000
X 00000000000000000000000000000000000000000000000000000000000000000000000000000000
0 10000000000000000000000000000000000000000000000000000000000000000000000000000000
1 01000000000000000000000000000000000000000000000000000000000000000000000000000000
2 00100000000000000000000000000000000000000000000000000000000000000000000000000000
3 00010000000000000000000000000000000000000000000000000000000000000000000000000000
4 00001000000000000000000000000000000000000000000000000000000000000000000000000000
5 00000100000000000000000000000000000000000000000000000000000000000000000000000000
6 00000010000000000000000000000000000000000000000000000000000000000000000000000000
7 00000001000000000000000000000000000000000000000000000000000000000000000000000000
8 00000000100000000000000000000000000000000000000000000000000000000000000000000000
9 00000000010000000000000000000000000000000000000000000000000000000000000000000000
--------------------------------------------------------------------------------

Each card in the data file is seperated by dashed lines. The matrix is 12x80. To read the file, read a line, store the 80 characters in a string and store the string in a Translation vector: vector<string> translate. While the line-count is less than 13, read and translate the next line. Process the in-memory matrix and then read the next card.

3. To Process the matrix, read the rows by the 80 columns. Each complete column is a EBDIC character. Lookup the EBDIC character in the tupleVector and find the ASCII character in the found tuple. Repeat for each character in the file. The end result is English readable text.

4. Design a Decryption class to model the decryption process as outlined in step 3. Your Decryption class needs a Process function CallBack, as each encrypted file is encrypted differently. The class should also contain a vector<string> for the translated strings. Determine which member functions are appropriate for decryption behavior. To answer that question, ask yourself: "What methods would you expect from a Decryption class?"

FileReader.cpp

#include <iostream>
#include <fstream>
#include <string>
#include <functional>
#include <vector>
#include <tuple>
#include <regex>
#include <algorithm>

using namespace std;

class FileReader {
private:
string fileName;
int fileSize;
vector<char> rawData;
function<string(string)> callback;

public:
FileReader(string name, function<string(string)> cb) {
fileName = name;
callback = cb;
}

int size() { return fileSize; }

string name() { return fileName; }

vector<char> raw() { return rawData; }

void parse() {

// Read the file into the raw data vector
ifstream f(fileName, ios::out | ios::app | ios::binary | ios::ate);

f.seekg(0, ios::end);
fileSize = f.tellg();
f.seekg(0, ios::beg);
rawData.resize(fileSize);
f.read(rawData.data(), fileSize);

string rawDataStr(rawData.begin(), rawData.end());
rawDataStr = callback(rawDataStr);
vector<char> newRawData(rawDataStr.begin(), rawDataStr.end());
rawData = newRawData;
}
};

// Define a regex callback function for parsing binary files
string RemoveSpace(string s) {
regex nonSpace(" ");
return regex_replace(s, nonSpace, "");
}
// Search
void searchInVector(vector<tuple<string, string, char>> tupleVector) {
vector<tuple<string, string, char>> searchVector;
searchVector.push_back(make_tuple("082", "A8", '='));
auto itr = search(tupleVector.begin(), tupleVector.end(), searchVector.begin(), searchVector.end(), [](auto& i1, auto& i2) {
return (get<0>(i1) == get<0>(i2) || get<1>(i1) == get<1>(i2) || get<2>(i1) == get<2>(i2));
});
if (itr != tupleVector.end())
cout << "Tuple found: " << get<0>(*itr) << " " << get<1>(*itr) << " " << get<2>(*itr) << '\n';
else
cout << "Tuple not found.";
}

int main() {
// Read a csv file
FileReader csvFileReader("Tuple.csv", RemoveSpace);
csvFileReader.parse();
cout << "File name: " << csvFileReader.name() << endl;
cout << "File size: " << csvFileReader.size() << " bytes." << endl;
cout << "Parsed Data: " << endl;
for (char c : csvFileReader.raw()) {
cout << c;
}
cout << endl << endl;

// Store data in vector tuple
vector<tuple<string, string, char>> tupleVector;
ifstream infile("Tuple.csv");
string line;
string code;
string column;
char ascii;

while (getline(infile, line)){
stringstream ss(line);
getline(ss, code, ',');
getline(ss, column, ',');
ss >> ascii;
tupleVector.push_back(tuple<string, string, char> (code, column, ascii));
}

infile.close();

// Print the content of the vector
cout << "Data in vector tuple: " << endl;
for (const auto& i : tupleVector) {
cout << get<0>(i) << " " << get<1>(i) << " " << get<2>(i) << endl;
}
cout << endl;
searchInVector(tupleVector);
return 0;
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY