
Concept explainers
C++
The program read Bin.bin file from ASCII to hex, then convert to binary string (0 and 1), store in tuple. Then read csv file to translate from binary to Morse code (dot-10 and dash-01, space-00). The output can be readable. Can change MyCode.cpp if you want.
Tuple Fields:
ASCII Character:
The ASCII character_ ‘M’
Morse Code:
The Morse Code string_ “- -”
Morse Binary:
Morse Code binary string_ “0101”
And:
foreach tup in tupleList
if tup.binary == binchar
return tup
return null
Algorithm Decrypt( encryptedstring ) // “RI…‰”
decryptedstring = Empty
for chr in encryptedstring
found = tupleList.Search(chr) // “0101”
decryptedstring.append(found.ascii)
Mycode.cpp
#include <iostream>
#include <fstream>
#include <sstream>
#include <tuple>
#include <
using namespace std;
int main() {
ifstream input_file("Bin.bin", ios::binary);
stringstream buffer;
buffer << input_file.rdbuf();
string contents = buffer.str();
input_file.close();
stringstream hex_stream;
hex_stream << hex;
for (char c : contents) {
hex_stream << static_cast<int>(static_cast<unsigned char>(c));
}
string hex_string = hex_stream.str();
string binary_string;
for (char c : hex_string) {
switch (c) {
case '0':
binary_string += "0000";
break;
case '1':
binary_string += "0001";
break;
case '2':
binary_string += "0010";
break;
case '3':
binary_string += "0011";
break;
case '4':
binary_string += "0100";
break;
case '5':
binary_string += "0101";
break;
case '6':
binary_string += "0110";
break;
case '7':
binary_string += "0111";
break;
case '8':
binary_string += "1000";
break;
case '9':
binary_string += "1001";
break;
case 'A':
binary_string += "1010";
break;
case 'B':
binary_string += "1011";
break;
case 'C':
binary_string += "1100";
break;
case 'D':
binary_string += "1101";
break;
case 'E':
binary_string += "1110";
break;
case 'F':
binary_string += "1111";
break;
}
}
vector<vector<string>> content;
vector<string> row;
string line;
string word;
fstream file ("data.csv", ios::in);
if(file.is_open()) {
while(getline(file, line)) {
stringstream str(line)
while(getline(str, word, ','))
row.push_back(word);
content.push_back(row);
}
}
else
cout<<"Could not open the file\n";
for(int i=0;i<content.size();i++) {
for(int j=0;j<content[i].size();j++) {
cout<<content[i][j]<<" ";
}
cout<<"\n";
}
return 0;
}
csv:
,,--..--
.,.-.-.-
0,-----
1,.----
2,..---
3,...--
4,....-
5,.....
6,-....
7,--...
8,---..
9,----.
:,---...
A,.-
B,-...
C,-.-.
D,-..
E,.
F,..-.
G,--.
H,....
I,..
J,.---
K,-.-
L,.-..
M,--
N,-.
O,---
P,.--.
Q,--.-
R,.-.
S,...
T,-
U,..-
V,...-
W,.--
X,-..-
Y,-.--
Z,--..
Bin.bin:
RI…‰&!:¢E(šQ…¥9‰Š‰Ù…E%ŠD‰Ž¡˜¢J*”ª9I*5F#T¦4ª#¦(˜¨M˜TRX¤H˜ê)„”’b9baQbbE‰Š‰™:Š¢6bb$HhÒ¨"aN¡R˜II&#†(b"cEM¢*‰Šˆêˆ˜å&&dê*ˆêˆš%ˆhå&(HÒ¨˜TRX¤H˜Ù…Fˆé…I*ˆÙ…E‘†ŽF9¢‘‰&5)&ˆ¨é*!£TcJ¢9%…I¢hTÔ¢¢¢…F*4TÒ¨EEF:Ò¨Žh‘#•EXj…T¨äa£‰&&†SZ…T¨™“”ª(š#¨JF†R†5$J¢‘(f*9h劢‰¡R¡RXªNDâI‰¢¨‘M˜Tš&ˆXކ9ŠŠ¡EF”èa¢‰‘iN¢¨HNT‘H¨ê‰¢hEF”äa£J¢N¢‘¨¨…’’I¡”Ô’bbˆh™“’˜H˜Ö&$h¤‘(ac¡ŽUbª¡iN¢¨$¤Xªª(Xª:†b¨TTš5$J¢‘(f*:aRc“¨ª&J‰™4ª#f)%‰¢4ª!EJ’4TÚ…J„TbfNI¡*…JEŠ£RI…‰&!9bh‘†!£EN¡)NF¢¡&$fRDª!I†b£‘6¢bF"ŠŽ‘Š*H˜¨¡E¥:Š¢9†b%„†ŽNTTj9J¢5$¨¨‘˜ª)*!£¡Š„¡)5JcHf*†&…E†S”ª(š#ª"cª)*‰häD†!£ª$˜©$˜hæ‰%:†b¨TTš&däMJ¨ª#j!bF9baQbbE¡…Ž¡R˜II&#ENX˜†Š„Ò¨ŽR$J¢&9hÚ(hå…J„X˜‘¢’DŽQRa“¡HHT˜TšI™:Ò¨Ž$˜šNUaªR£ª$R‰¡åEJ†J£š(a˜T𿉅I‰Ra”ZS”ª"b:Š¢9I*:©&Š’:Ò¨Ž¢EˆáŠ’‰…F†–&%HfiM*ˆéŠ&*¤™’¢fNJ&6ˆ¦!ŠˆêJ„…&dê*ˆØTI‰¡”å&:…Ja%$˜Ž˜T˜ä剅E‰‰ÑS¡¢J)†S†!FS’‰†bbJa&dꉢhEF6!¤NQRa’9R„¨èb¡&)†D¡QŽh‘¨T˜‘&E¥9J¢†b¨å‰…J’†ˆh䉅F$¤J‰&!˜ªTšN˜T˜Ø’¢I™:Š¢9¢94‰Ò¨‘9I*4’¡’9J¨Ú"¤‰¡RX¡…*ˆê)„”’b:aRcJ¢5ŠJ$a˜ŽF6aQ„˜Tš:†R¡!JR˜Ò¨Ž†
bh¡b¨M˜TQIhäa£š)’cQQ¢’hŠR˜Ò¨ŽIaRhš5(¨¨¡QЉ™9J¢4¡HZSaS¨f*…EI¢£I)*„ê)„”’b8ab†"&(aaiN¡SJ¢4‰Ô…ˆ˜¨ê‰4Tå&5JDäa”剅F¢h…*5F4ª"‰RQ‰™:¢E(šQލ‰Šˆš)Ž¢X†bŠb†bI¢he6aQ†bI‰5F:…Ja%$˜6ˆHf¨e*âbaRb£‘†9ˆf*H˜èb˜T˜RD¡Qކ96aQIb‘"cf&$¨ª&dÚ…Dª4ª*#‰¢†£”‰ˆÙ‰ŠFb‰&¢’b†4ª#’XTš&…NU%SRŠŠŠZS”ª(f*9*aQ‰)£b(š9&¨I…F9hÚŠE¡häš&(cEM*ˆÔTTbfN¨‘J&„Tcš"˜MJ¡*ˆÔ¡£•EXZ…T¨ÑS”T˜dècJ¢9bbŠ’DŽ¢„T˜™“¨ª#f)…JF!£J¢6aQIbFN¨¡b¨‰Ra¢&:…Ja%$˜Ž†9TU…¨jŽF8¨I‰¢ŠŠ¢:¢E(šQ!˜ªTš(ŠŽUSe"IŠŽh‘"bfOª$R‰¡å$¨Ò¨ŽbŠ%Š!„Õ)ޤ’b…JJލTaRb¡iN†‰¢‘¢†6$¨’£†‘˜‰a(TbI£¨–$f#‘˜NII&&d剈¨™“j$˜‘˜dÕ‰“–&"¢Hhꈘå(J£J¢9bb*(h†‰&Hh’hÕ)Ž˜˜ˆhTS¡Ž•RU¢f@

Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 1 images

- C PROGRAM!!!! How do I code the C code for the main.c file to accomplish the following tasks outlined in the assignment (see images) to produce a similar palindromes output?arrow_forwardAttached Files: sample.txt (11.069 KB) You will only get one submission. I need a python program, so file ends in ".py". Please ensure program runs and prints a result. Use the attached sample file to write a program that counts how many words: 1) begin with the letter "a" or "A" 2) end with the letters "ed" 3) contain the sequence "ous"arrow_forwardComputer Science C++ Create a text file "input.txt" with a certain amount of integers (you decide how many). Write a program that reads these numbers from the file, adds them, and when you have reached the end of the file, calculates the average of these numbers. Print a message and the average to the console. Code this program twice, demonstrating the two methods to detect the end of the file, part A: reading a value from Instream and storing it (boolean expression) in the while loop part B: using the eof() member functionarrow_forward
- Please modify the following code using getline(cin,strObj) with cout<<strObj<<endl; or getline(infile,strObj) with outfile<<strObj<<endl; #include <iostream>#include <fstream>#include <cstdlib> #include <string> int main(){string fileOne = "info.txt"; // put the filename up frontstring fileTwo = "info.bak";char ch;ifstream inFile;ofstream outfile;try //this block tries to open the input file{// open a basic input streaminFile.open(fileOne.c_str());if (inFile.fail()) throw fileOne;} // end of outer try blockcatch (string in) // catch for outer try block{cout << "The input file " << in<< " was not successfully opened." << endl<< " No backup was made." << endl;exit(1);}try // this block tries to open the output file and{ // perform all file processingoutfile.open(fileTwo.c_str());if (outfile.fail())throw fileTwo;while ((ch = inFile.get())!= EOF)outfile.put(ch);inFile.close();outfile.close();}catch…arrow_forwardcan you do it pythonarrow_forward-all-occurrences-of-a-substring-in-a-string/.arrow_forward
- USING C++ PLEASE CREATE THREE FILES! IntCollection.h (or IntCollection.hpp): class definition IntCollection.cpp: class implementation main.cpp, including sample output and your answer to question 6 at the bottom. : main program to run the code The following code creates an IntCollection object named ‘c’. It adds seven integers to ‘c’, then uses a for loop to display the seven integers: int main() { IntCollection c; c.add(45); c.add(-210); c.add(77); c.add(2); c.add(-21); c.add(42); c.add(7); for (int i = 0; i < c.getSize(); i++) { cout << c.get(i) << endl; } } For this assignment you will add a copy constructor, a destructor, and three overloaded operators to the IntCollection class. In the design diagram below, the black member functions represent code that has already been implemented. You will be implementing the green items. Each item that you will be adding to the class is described below the diagram. private: int size // the number of ints currently stored in…arrow_forwardwordCountDistinct.py: Write a program that reads words from a file (filename given as a command-line argument) and prints the number of distinct words. Words that differ only in case should be considered to be equivalent.For example, using the input: If there's a problem yo I'll solve itCheck out the hook while my DJ revolves itIce ice baby The program should print 18.arrow_forwardpython please! the first answer i received didn't check out. it is graded by a computer on autolab. im so confusedarrow_forward
- Create a C++ Program to do the following: Create a .txt file with up to 10 double numbers. Then in your code, create an array to hold 10 doubles. Openthe file. Read each number from the file into a place in the array. Count how many numbers you read. Close thefile.Now, go through the data in the array twice. Don’t go through all 10 elements in the array, only the elementsfor which you have read data. On the first pass, calculate the average of the numbers in the array. (Calculate thetotal, divide by count, that is µ).On the second pass through the data, for each number you should calculate how far it is from the average(number - average), square that, and keep a sum of the squares, that is S.When you’re done, calculate the average of that sum of squares, A. The square root of that number, σ is yourstandard deviation.Print out the average µ and standard deviation σarrow_forwardC++ formatting please Write a program (not a function) that reads from a file named "data.csv". This file consists of a list of countries and gold medals they have won in various Olympic events. Write to standard out, the top 5 countries with the most gold medals. You can assume there will be no ties. Expected Output: 1: United States with 1022 gold medals 2: Soviet Union with 440 gold medals 3: Germany with 275 gold medals 4: Great Britain with 263 gold medals 5: China with 227 gold medalsarrow_forwardPlz use c programming to solve this question. Plz don't use a library other than # include < stdio. h > and # include math . h and # define n 100arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





