Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need a c++ code that: 1- Read from a text file using C++ example: mytext.txt 2- a function that adds three letters to each

I need a c++ code that:

1- Read from a text file using C++ example: mytext.txt

2- a function that adds three letters to each latter in that text file

for example, if there is a "hello world" inside the text file

the function will make it look like "habcezyeloiulghtoiuy wnfroewqrmnilkitduyt" if you note the first latter h follow with three letters abc the e follow with another three zye .... etc

so the function is like hashing function that adds for each latter another three letters. print the hashing in this function in main.

3- a function that gives me the solution for the first function and prints the solve for the hashing which is the info inside the text file in the main.

example: hello" hxxxexxxlxxxlxxxoxxx- print h then delete the other three letters then print e then delete the other three letters ...etc at final it will look like original word inside the text file "hello".

the text file could include sentences no limit.

........................... or if you could fix the code down because one of the expert did it and it was not printing the original text.

#include using namespace std;

const int MAX = 26;

string addRandomString(int n) { char alphabet[MAX] = { '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' }; string res = ""; for (int i = 0; i < n; i++) res = res + alphabet[rand() % MAX]; return res; }

string getOriginalText (string hashedText) {

string originalText = "";

for (int i=0; i

return originalText;

}

int main() { srand(time(NULL));

string hashedText = "";

 char ch; fstream fin("mytext.txt", fstream::in); while (fin >> noskipws >> ch) { hashedText = hashedText + ch + addRandomString(3) ; 

}

cout << "Hashed Text " << hashedText << endl;

cout << "Original Text " << getOriginalText(hashedText) << endl;

return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Case Studies In Business Data Bases

Authors: James Bradley

1st Edition

0030141346, 978-0030141348

More Books

Students also viewed these Databases questions