Writer a Program that tests Benford\'s Law. Collect a list of at least 100 numbe
ID: 441249 • Letter: W
Question
Writer a Program that tests Benford's Law. Collect a list of at least 100 numbers from some real-life data source and enter them inter a text file. Your program should loop through the list of numbers and count how many times 1 is the first digit, 2 is the first digit, etc. For each digit output the perent it appears as the first digit. If you read a number into the string variable named strNum then you can access the first digit as a char by using strNum[0]. This is described in more detail in chapter 9Explanation / Answer
std::string s = std::to_string(42); Now reading from a file is simple. Just apply the above function I gave you to the string[0] and check which digit it is.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.