
Using your FileReader and TupleSearching
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;
}

Trending nowThis is a popular solution!
Step by stepSolved in 3 steps

- Help nowarrow_forwarddef perceptron_single_step_update(feature_vector,label,current_theta,current_theta_0):"""Properly updates the classification parameter, theta and theta_0, on asingle step of the perceptron algorithm. Args:feature_vector - A numpy array describing a single data point.label - The correct classification of the feature vector.current_theta - The current theta being used by the perceptronalgorithm before this update.current_theta_0 - The current theta_0 being used by the perceptronalgorithm before this update. Returns: A tuple where the first element is a numpy array with the value oftheta after the current update has completed and the second element is areal valued number with the value of theta_0 after the current updated hascompleted.arrow_forward1. Write two ways to display the following matrix 3 4 5 6 ( 13 14 15 16 17 2. 4 3 3 4 Let A 9 6 a) using the columns operator (:) , creat a column vector that contains all the columns of A. b) using the columns operator (:) , creat a column vector that contains all the Rows of A. c) using the columns operator (:),creat a Row vector that contains the 1*t row and 3rd columns of A. d) using the columns operator (:) , creat a column vector that contains all the columns of A. e) using the columns operator (:) , creat a column vector that contains all the columns of A.arrow_forward
- Case number three. what is the best way to insert the total_tuition into the FBTEAM vector. This vector is a string but the total_tuition is an integer so it sends an error. How can I store it into a string vector? How do I convert an int into a string? #include "stdafx.h"#include <iostream>#include <cstdlib>#include <ctime>#include <string>#include <vector>#include <cctype>#include <iterator>#include <algorithm>#include <cmath>#include "ConsoleApplication11.h" using namespace std; string FBTeam;string College[5];string location;string Price_of_Ticket;int choice; int main(){vector<string> CULIST(5);vector<string> FBTEAM(5);string itemNumber; int tuition = 0;int dorm = 0;int meal = 0;int total_tuition[5];int average;const int size = 5;double averages[size] = { 0.0 };bool stop = false, itemFound; cout << "--------------------------------------------------------------------------------" << endl;cout << "…arrow_forwardOpen Pycharm on your PC and create python file named Lab6.py. 1- Write the necessary code to initialize a numpy array (5,3,3) as follows: [[[6 2 6] [6 2 6] [6 2 6]] [[666] [666] [666]] [[666] [333] [666]] [[666] [666] [666]] [[7 6:6] [6 7 6] [667]]] 2- Generate a (7, 7) numpy array that consists of integer random values between 10 and 50 and answer the following: a. What is the minimum value in each column b. What is the mean for each row c. Generate the cumulative product of each column d. Count the number of elements in the array whose values are greater than 30 and smaller than 40 e. Display the elements in the arrays that equals to 20 f. Multiply by 5 the elements whose value is less than 30. g. Display the largest 5 elements in the array 3- Define two numpy 1D arrays X and Y; initialize them to random numbers between 0 and 100 and print the elements in X that do not exist Y.arrow_forwardGive the code asked in the question using the GNU Octave App. Do not type individual elements explicitly.arrow_forward
- PYTHON cannot use numpy, opencv, array, readline( ), or enumerate. can only use open, read, write, and close methods for files. please utilize split and append functionsarrow_forwardWhat is wrong with my code? use the IN300_Dataset2.txt file (https://kapextmediassl-a.akamaihd.net/IST/IN300/IN300_1905A/IN300_Dataset2.txt) Write a Java program that: A. Reads the text file. B. Using that data, create a two-dimensional array that is 2,500 rows by 100 columns. C. Slice the two-dimensional array using a starting column index of 2 and an ending column index of 5. Print the results of the arrays and slice. import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.io.File; import java.util.Scanner; import java.lang.Float; public class Main { public static void main(String args[]) { File file = new File("/Users/ahmedgasim/Desktop/IN300_Dataset2.txt"); String line; ArrayList<Long> data = new ArrayList<Long>(); try (BufferedReader br = new BufferedReader(new FileReader(file))) { while((line = br.readLine())) ! = null) {…arrow_forwardIntegers are read from input and stored into a vector until 0 is read. If the vector's last element is odd, output the odd elements in the vector. Otherwise, output the even elements in the vector. End each number with a newline. Ex: If the input is -9 12 -6 1 0, the vector's last element is 1. Thus, the output is: -9 1 Note: (x % 2 != 0) returns true if x is odd. int value; int i; bool isodd; 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 } cin >> value; while (value != 0) { } for (i = 0; i > value; Check return 0; 1 Next level 2 X 1: Compare output 3 4 For input -9 12 -6 1 0, the vector elements are -9, 12, -6, and 1. The last element, 1, is odd. The odd elements in the vector, -9 and 1, are output, each on a new line. Not all tests passed. 2 V 3arrow_forward
- Integers are read from input and stored into a vector until 0 is read. If the vector's last element is odd, output the odd elements in the vector. Otherwise, output the even elements in the vector. End each number with a newline. Ex: If the input is -9 12 -6 1 0, the vector's last element is 1. Thus, the output is: -9 1 Note: (x % 2!= 0) returns true if x is odd. 4 5 int main() { 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20} vector vect1; int value; int i; bool isodd; cin >> value; while (value != 0) { vect1.push_back(value); cin >> value; } V* Your code goes here */ return 0; 2 3arrow_forwardAn_array and a number kFind the max elements of each of its sub-arrays of length k. Keep indexes of good candidates in deque d.The indexes in d are from the current window, they're increasing,and their corresponding nums are decreasing.Then the first deque element is the index of the largest window value. For each index i: 1. Pop (from the end) indexes of smaller elements (they'll be useless).2. Append the current index.3. Pop (from the front) the index i - k, if it's still in the deque (it falls out of the window).4. If our window has reached size k, append the current window maximum to the output..arrow_forwardFor sorting a vector in the assignment below, use the simplest to code - bubble sort: https://en.wikipedia.org/wiki/Bubble_sort. Do Not Delete Any Existing Comments code underneath / where indicated. Any code submitted with comments missing, will not be graded for style and formatting. Do Not Delete Any Existing Starter Code unless directed by the instructions. Code to the given assignment, don't change the assignment to fit your code. 6.24 LAB - Sort a vector Define a function named SortVector that takes a vector of integers as a parameter. Function SortVector() modifies the vector parameter by sorting the elements in descending order (highest to lowest). Then write a main program that reads a list of integers from input, stores the integers in a vector, calls SortVector(), and outputs the sorted vector. Create a second function which sums the values stored in the vector. The first input integer indicates how many numbers are in the list. Ex: If the input is: 5 10 4 39 12 2 the…arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY





