The question should be done in C++, please give explanation and running result.  1. Let’s write a function that compares 2 strings and returns true if they were identical, false otherwise. The signature of this function should be: bool word_diff(std::string word1, std::string word2);  For example: std::string str1 = "Hello World"; std::string str2 = "hEllO World"; std::string str3 = "World"; std::string str4 = "Hello World"; bool result = word_diff(str1, str2); // False bool result = word_diff(str1, str3); // False bool result = word_diff(str1, str4); // True   2. Now let’s follow a classical approach to compare the content of 2 files. We should open each file, read their content word by word and compare them until a first mismatch occurs. Let’s implement a function called classical_file_diff that takes 2 arguments each of which is a file name and returns a boolean indicating whether the 2 files are identical or not. The signature of this function should be: bool classical_file_diff(std::string file1, std::string file2);  This function must use the helper function from Question 1 that compares 2 words. Example: Create a folder within the same directory where your executable resides and name it “txt_folder”. In it create 2 files: file1.txt and file2.txt. In file1.txt copy/paste the following lines: My dear C++ class. I hope that you enjoy this assignment. file2.txt copy/paste the following lines: My dear C++ class. I hope that you like this assignment. The following code should yield false in the variable result: std::string file1 = "./txt_folder/file1.txt"; std::string file2 = "./txt_folder/file2.txt"; bool result = classical_file_diff(file1, file2); // False  Please note that you may need to modify the slashes in the path name according to the expectations of your operating system.

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. Let’s write a function that compares 2 strings and returns true if they were identical, false otherwise. The signature of this function should be:

bool word_diff(std::string word1, std::string word2); 

For example:

std::string str1 = "Hello World";
std::string str2 = "hEllO World";
std::string str3 = "World";
std::string str4 = "Hello World";
bool result = word_diff(str1, str2); // False
bool result = word_diff(str1, str3); // False
bool result = word_diff(str1, str4); // True

 

2. Now let’s follow a classical approach to compare the content of 2 files. We should open each file, read their content word by word and compare them until a first mismatch occurs.
Let’s implement a function called classical_file_diff that takes 2 arguments each of which is a file name and returns a boolean indicating whether the 2 files are identical or not. The signature of this function should be:

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

This function must use the helper function from Question 1 that compares 2 words.
Example: Create a folder within the same directory where your executable resides and name it “txt_folder”. In it create 2 files: file1.txt and file2.txt.

In file1.txt copy/paste the following lines:

My dear C++ class.
I hope that you enjoy this assignment.

file2.txt copy/paste the following lines:

My dear C++ class.
I hope that you like this assignment.

The following code should yield false in the variable result:

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

Please note that you may need to modify the slashes in the path name according to the expectations of your operating system.

Expert Solution
steps

Step by step

Solved in 5 steps with 2 images

Blurred answer
Knowledge Booster
Algebraic Expressions
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