I need to write a C++ program to analyze three different data files, and try to confirm Benford’s law.I need to create a console application that opens each file, counts the number of values that start with ‘1’, ‘2’, ‘3’, etc., and then outputs the percentages of each digit. Based on the output, we can test the validity of Benford’s law.
Here is the link to following text files :-
- http://joehummel.net/uploads/citypopulations.txt
- http://joehummel.net/uploads/librarybooks.txt
- http://joehummel.net/uploads/sunspots.txt
Here’s what the output from your program should look like:
You are free to solve the problem as you see fit, but there are 2 requirements. First, you must use the
proper technique for opening files: check that the open was successful using the file object’s good( ) method,
and if not, output an error message and exit the program immediately with an error code. Second, the main
program MUST be written as follows:
int main()
{
analyzeData("citypopulations.txt");
analyzeData("librarybooks.txt");
analyzeData("sunspots.txt");
return 0;
}