Click here to Skip to main content
15,901,373 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: How to initialize property page's dialog? Pin
Vaclav_24-Aug-13 5:08
Vaclav_24-Aug-13 5:08 
QuestionHow to make the camera rotate with the player? Pin
LittleJackFlash21-Aug-13 3:19
LittleJackFlash21-Aug-13 3:19 
AnswerRe: How to make the camera rotate with the player? Pin
pasztorpisti21-Aug-13 4:05
pasztorpisti21-Aug-13 4:05 
GeneralRe: How to make the camera rotate with the player? Pin
LittleJackFlash21-Aug-13 22:00
LittleJackFlash21-Aug-13 22:00 
GeneralRe: How to make the camera rotate with the player? Pin
Jonathan Davies21-Aug-13 22:38
Jonathan Davies21-Aug-13 22:38 
GeneralRe: How to make the camera rotate with the player? Pin
LittleJackFlash21-Aug-13 23:25
LittleJackFlash21-Aug-13 23:25 
GeneralRe: How to make the camera rotate with the player? Pin
Jonathan Davies21-Aug-13 23:46
Jonathan Davies21-Aug-13 23:46 
GeneralHow to write Benford’s Law in C++ Need Help Pin
Member 1022170020-Aug-13 16:55
Member 1022170020-Aug-13 16:55 
Here is the description:
Consider lists of numbers from real-life data
sources, for example, a list containing the number of students enrolled in different
course sections, the number of comments posted for different Facebook status
updates, the number of books in different library holdings, the number of votes per
precinct, etc. It might seem like the leading digit of each number in the list should
be 1–9 with an equally likely probability. However, Benford’s Law states that the
leading digit is 1 about 30% of the time and drops with larger digits. The leading
digit is 9 only about 5% of the time. Write a program that tests Benford’s Law. Collect a list of at least one hundred numbers from some real-life data source and enter them into 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 percentage 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]
.

And Here is how I got so far:
Programming Language C++ (I just take this class this F2013)

#include
#include
#include
#include
#include
#include

int main(int argc, char** [0])
{
std::string strNum
//this just a random # I put in here, I want digit 1-9 NOT ZERO
("15157,83049,1193049090,1289727392,9075,54984,5419981,231540,1498056");

std::map digit_frequency;

for(int i = 0; i < strNum.size(); ++i)
{
std::stringstream ss;
ss << strNum[i];
std::string str = ss.str();
if(isdigit(str[0]))
{
++digit_frequency[str[0]];
}
else if(isdigit(str[1]))
{
++digit_frequency[str[1]];
}
}

std::map::iterator it;
for(it = digit_frequency.begin(); it != digit_frequency.end(); it++)
{
std::cout << "Leading Digit " << it->first << ": repeated " << it->second << " time(s).\n";
}

return 0;
}


output:

click the link to see the output.

http://www.facebook.com/#!/photo.php?fbid=10200531325265379&set=a.1645092726942.2077529.1225598765&type=1&theater
KingLord

QuestionRe: How to write Benford’s Law in C++ Need Help Pin
Richard MacCutchan20-Aug-13 20:10
mveRichard MacCutchan20-Aug-13 20:10 
GeneralRe: How to write Benford’s Law in C++ Need Help Pin
BadKarma20-Aug-13 21:30
BadKarma20-Aug-13 21:30 
SuggestionRe: How to write Benford’s Law in C++ Need Help Pin
David Crow21-Aug-13 6:26
David Crow21-Aug-13 6:26 
QuestionCTabCtrl header colour anomaly in CPaneDialog Pin
D G McKay20-Aug-13 2:07
D G McKay20-Aug-13 2:07 
AnswerRe: CTabCtrl header colour anomaly in CPaneDialog Pin
D G McKay2-Sep-13 0:14
D G McKay2-Sep-13 0:14 
QuestionWindow Position Pin
john563218-Aug-13 19:44
john563218-Aug-13 19:44 
AnswerRe: Window Position Pin
Richard MacCutchan18-Aug-13 20:56
mveRichard MacCutchan18-Aug-13 20:56 
GeneralRe: Window Position Pin
john563219-Aug-13 4:11
john563219-Aug-13 4:11 
GeneralRe: Window Position Pin
Richard MacCutchan19-Aug-13 5:06
mveRichard MacCutchan19-Aug-13 5:06 
GeneralRe: Window Position Pin
pasztorpisti19-Aug-13 6:09
pasztorpisti19-Aug-13 6:09 
GeneralRe: Window Position Pin
Richard MacCutchan19-Aug-13 20:33
mveRichard MacCutchan19-Aug-13 20:33 
GeneralRe: Window Position Pin
pasztorpisti20-Aug-13 2:03
pasztorpisti20-Aug-13 2:03 
QuestionRe: Window Position Pin
pasztorpisti18-Aug-13 23:47
pasztorpisti18-Aug-13 23:47 
QuestionSometimes it can not draw out graph Pin
xieeevil18-Aug-13 17:04
xieeevil18-Aug-13 17:04 
AnswerRe: Sometimes it can not draw out graph Pin
Richard MacCutchan18-Aug-13 20:38
mveRichard MacCutchan18-Aug-13 20:38 
GeneralRe: Sometimes it can not draw out graph Pin
Rajesh R Subramanian18-Aug-13 21:57
professionalRajesh R Subramanian18-Aug-13 21:57 
GeneralRe: Sometimes it can not draw out graph Pin
Richard MacCutchan18-Aug-13 22:09
mveRichard MacCutchan18-Aug-13 22:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.