Question: Please work on C++ Required function: bool cmp_files(const std::string& lhsFilename, const std::string& rhsFilename) Before writing functions to modify the files, you've created some test cases

Please work on C++

Required function: bool cmp_files(const std::string& lhsFilename, const std::string& rhsFilename)

Before writing functions to modify the files, you've created some test cases by hand and needed a way to automate the tests to determine if your works successfully. To do this, you decide to write a function to tell you if two files are identical, to compare your output files to the tests you created. Write a function cmp_files that takes two filenames as input and returns true if the two files are identical, and returns false otherwise. A suggested way to do this is:

- Open each file in binary mode. - Read the files into memory. - Compare if the two files are identical. - Return true if the files are equal and false otherwise.

Note: you should not modify the original file when doing this. Assumptions you can make for cmp_files(): - The files referred to by lhsFilename and rhsFilename exist. - The file referred to by filename is not empty. - The number of bytes in each of the files is divisible by 4. - You have read permission on the directory

working code:

#include #include #include

using namespace std; bool cmp_files(const std::string& lhsFilename, const std::string& rhsFilename) {

//TODO }

test code(You cannt change anything here)

#include

int main() { std::string testFilename;

// Tests your cmp_files function on test01 through test09 for (int i = 1; i <= 9; ++i) { testFilename = std::string("test0") + (char) (i + 48); if (cmp_files(testFilename, testFilename)) { std::cout << "cmp_files correctly checks that " << testFilename << " is equal to itself!" << std::endl; } else { std::cout << "Something went wrong comparing the file with itself. :(" << std::endl; return -1; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!