Question: Given 2 files that contain integer data, the goal is to write a C++ program that detects if the files are identical. For example, suppose

Given 2 files that contain integer data, the goal is to write a C++ program that detects if the files are identical. For example, suppose we have two input files data1.txt and

data2.txt with the following data:

17 0

22 22

0 9

15 15

0 17

8 0

Are these files the same? Given the names of two files, your program should input the data into two separate arrays, sort each one, and then output the data side-by-

side followed by a summary. Given the files above:

0,0

0,0

8,9

15,15

17,17

22,22

# of lines: 6

Similarity: 83.3333%

Identical? NO

As you can see from the side-by-side output, the files differ by one pair of values --- data1.txt contains an 8 while data2.txt contains a 9, so one pair (8,9) differs. Since 5 out of 6 pairs are the same, the similarity is 83.3333%. Suppose we have a third input file data3.txt that contains the following data:

15

22

8

0

0

17

When we run the program and specify data1.txt and data3.txt, we get this output:

0,0

0,0

8,8

15,15

17,17

22,22

# of lines: 6

Similarity: 100%

Identical? YES

These files are identical since they contain the same data --- every pair is the same after sorting. Your program should input two filenames to start, and then perform the required computation and output. Assume the files are the same size, i.e. contain the same # of integers; assume at most 500 integers per file.

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!