Histogram.zip - (8.91 MB)
[
Histogram/Debug/
Histogram/Debug/cl.command.1.tlog
Histogram/Debug/CL.read.1.tlog
Histogram/Debug/CL.write.1.tlog
Histogram/Debug/Histogram.exe
Histogram/Debug/Histogram.exe.embed.manifest
Histogram/Debug/Histogram.exe.embed.manifest.res
Histogram/Debug/Histogram.exe.intermediate.manifest
Histogram/Debug/Histogram.ilk
Histogram/Debug/Histogram.lastbuildstate
Histogram/Debug/Histogram.log
Histogram/Debug/Histogram.obj
Histogram/Debug/Histogram.pdb
Histogram/Debug/Histogram.vcxprojResolveAssemblyReference.cache
Histogram/Debug/Histogram.write.1.tlog
Histogram/Debug/Histogram_manifest.rc
Histogram/Debug/link.5612.read.1.tlog
Histogram/Debug/link.5612.write.1.tlog
Histogram/Debug/link.5612-cvtres.read.1.tlog
Histogram/Debug/link.5612-cvtres.write.1.tlog
Histogram/Debug/link.command.1.tlog
Histogram/Debug/link.read.1.tlog
Histogram/Debug/link.write.1.tlog
Histogram/Debug/link-cvtres.read.1.tlog
Histogram/Debug/link-cvtres.write.1.tlog
Histogram/Debug/mt.command.1.tlog
Histogram/Debug/mt.read.1.tlog
Histogram/Debug/mt.write.1.tlog
Histogram/Debug/rc.command.1.tlog
Histogram/Debug/rc.read.1.tlog
Histogram/Debug/rc.write.1.tlog
Histogram/Debug/vc100.idb
Histogram/Debug/vc100.pdb
Histogram/Histogram.cpp
Histogram/Histogram.png
Histogram/Histogram.sdf
Histogram/Histogram.sln
Histogram/Histogram.suo
Histogram/Histogram.vcxproj
Histogram/Histogram.vcxproj.filters
Histogram/Histogram.vcxproj.user
Histogram/ipch/
Histogram/ipch/histogram-e202774/
Histogram/ipch/histogram-e202774/histogram-9e611e5a.ipch
Histogram/Question.txt
]
A popular method of displaying data is in a Histogram. A histogram counts how many items of data
fall in each of n equally sized intervals and displays the results as a bar chart in which each
bar is proportional in length to the number of data items falling in that interval.
Write a program that generates 10000 random integers in the range 0-99 and produces a Histogram
from the random data. Assume that we wish to count the number of numbers that lie in each of the
intervals 0-9, 10-19, 20-29, ………, 90- 99. This requires that we hold 10 counts, use an array
to hold the 10 counts. While it would be possible to check which range a value x lies in by using
if-else statements this would be pretty tedious. A much better way is to note that the value of
x/10 returns the index of the count array element to increment.
Having calculated the interval counts draw the Histogram by printing each bar of the Histogram as
an appropriately sized line of X’s across the screen as below
0 – 9 16 XXXXXXXXXXXXXXXX
10 – 19 13 XXXXXXXXXXXXX
20 – 29 17 XXXXXXXXXXXXXXXXX
etc.