The question should be done in C++, please give explanation and running result. 1. Comparing word by word is time consuming. A better strategy would be to take advantage of hashing functions. Implementing a robust hash function is a tricky thing and out of scope for this assignment. To make things easier we’ll take advantage of C++ default hash object used by the standard library std::hash. You are invited to research std::hash in order to understand how it works. In its basic form std::hash can take a string as input and returns its hashed value.  Example: std::string mystr = "I love this assignment"; std::size_t h1 = std::hash{}(mystr); std::cout << h1 << std::endl; Don’t mind much of the weird syntax required for std::hash, just use it in a similar fashion to this example. Now let’s write a function called hash_it that takes a string as an input parameter and returns the hashed value. The signature of this function must be: std::size_t hash_it (std::string someString);  For example: std::string mystr = "I love this assignment"; std::size_t h1 = hash_it (mystr); std::cout << h1 << std::endl;   2. Let’s take advantage of the hashing function that you implemented in the previous question in order to use it in a smart way to check whether 2 files are identical or not without comparing the content of the 2 files word by word .  Write a function called enhanced_file_diff that takes 2 filenames as input parameters and returns true if the content of the 2 files were identical, false otherwise. Keep in mind that this time no content comparison should be used in your implementation (no word to word comparison is allowed). The signature of this function should be: bool enhanced_file_diff(std::string file1, std::string file2);  Example: Use the same files that you have created previously and run the following code:  std::string file1 = "./txt_folder/file1.txt"; std::string file2 = "./txt_folder/file2.txt"; bool result = enhanced_file_diff(file1, file2); // False  Modify the content on file2.txt to match exactly what’s in your file1.txt and rerun the code. It should yield true now.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

The question should be done in C++, please give explanation and running result.

1. Comparing word by word is time consuming. A better strategy would be to take advantage of hashing functions.

Implementing a robust hash function is a tricky thing and out of scope for this assignment. To make things easier we’ll take advantage of C++ default hash object used by the standard library std::hash.

You are invited to research std::hash in order to understand how it works. In its basic form std::hash can take a string as input and returns its hashed value. 

Example:
std::string mystr = "I love this assignment";
std::size_t h1 = std::hash<std::string>{}(mystr);
std::cout << h1 << std::endl;

Don’t mind much of the weird syntax required for std::hash, just use it in a similar fashion to this example.

Now let’s write a function called hash_it that takes a string as an input parameter and returns the hashed value. The signature of this function must be:

std::size_t hash_it (std::string someString); 

For example:

std::string mystr = "I love this assignment";
std::size_t h1 = hash_it (mystr);
std::cout << h1 << std::endl;

 

2. Let’s take advantage of the hashing function that you implemented in the previous question in order to use it in a smart way to check whether 2 files are identical or not without comparing the content of the 2 files word by word . 

Write a function called enhanced_file_diff that takes 2 filenames as input parameters and returns true if the content of the 2 files were identical, false otherwise. Keep in mind that this time no content comparison should be used in your implementation (no word to word comparison is allowed). The signature of this function should be:

bool enhanced_file_diff(std::string file1, std::string file2); 

Example: Use the same files that you have created previously and run the following code: 

std::string file1 = "./txt_folder/file1.txt";
std::string file2 = "./txt_folder/file2.txt";
bool result = enhanced_file_diff(file1, file2); // False 

Modify the content on file2.txt to match exactly what’s in your file1.txt and rerun the code. It should yield true now. 

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
ADT and Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education