455,850 Members | 1,269 Online
Need help? Post your question and get tips & solutions from a community of 455,850 IT Pros & Developers. It's quick & easy.

# How to plot a histogram from an array

 P: 3 Dear All, I am new to perl. I need your help with processing the grade.dat file. I have a file containing a list of students with their varying scores from different type of assignments and tests. I have calculated the final grade and need to know the score distribution in a simple histogram like this: 78 xxxxxxx 79 xxxxxxxx 80 xxxxx 81 xxx where x indicates the number of students gaining the score that equals to the left string. Thanks for your prompt response. Regards, Jang Mar 16 '08 #1
5 Replies

 Expert 100+ P: 971 Please show us the code that you have done in tying to accomplish this on your own. Also, this sound like homework/coursework, is it? --Kevin Mar 16 '08 #2

 P: 3 Please show us the code that you have done in tying to accomplish this on your own. Also, this sound like homework/coursework, is it? --Kevin Yes, I've been working on my assignment (If this is not allowed, then I won't be asking questions anymore). Well, to be frank, I haven't been able to compute the final score since I'm still trying to find a way to target a specific column. For example, the mid-test scores are at column 20 and final-test scores at 21 and I have to add them in to get the overall score of each student. Below is what I had in mind: Expand|Select|Wrap|Line Numbers \$mid = \$i; for (\$i = 20) {       \$overall = \$overall + \$mid; } \$final = \$i; for (\$i = 21) {      \$overall = \$overall + \$final; } Are they correct? Anyone willing to help? Thanks. Mar 18 '08 #3

 Expert 100+ P: 971 Would you please show some sample data and the format of the file that the data is in? When it comes to school work we will make suggestions, but not offer complete solutions. That way you will still learn. --Kevin Mar 18 '08 #4

 P: 3 Would you please show some sample data and the format of the file that the data is in? When it comes to school work we will make suggestions, but not offer complete solutions. That way you will still learn. --Kevin 00569, Cindy, 40, 40, 40 ,38, 40, 40, 20, 25, 25, 10, 8, 9, 8, 8, 7, 8, 66, 82, 92 00580, Melina, 40, 39, 38, 40, 37, 40, 25, 25, 25, 10, 9, 9, 9, 8, 9, 70, 83, 93 The data contain the ID, name, scores of projects, quizzes, exercises, mid and final terms. I have to add up all scores for every student by first counting the percentage of each element of scoring and then assign a letter grade like A, B, and etc. Then i have to display a histogram like this. 90 xxxx 91 xxx 92 x 93 x which means four students got 90, 3 got 91 and so on. I'd really appreciate you would give me some clue. Thanks. Mar 19 '08 #5

 Expert 100+ P: 971 Expand|Select|Wrap|Line Numbers # This gets the last two elements the line. my (\$mid, \$final) = (split ', ')[-2,-1];   # This assumes that each line is the same fixed length. my (\$mid, \$final) = (split', ',)[19, 20]; Expand|Select|Wrap|Line Numbers open(my \$FILE, '<', \$file) || die "Can't open \$file: \$!\n";     while(<\$FILE>) {         chomp;               # This gets the last two elements the line.             my (\$mid, \$final) = (split ', ')[-2,-1];               # Do something with \$mid and \$final             print "Mid: \$mid\n";             print "Final: \$final\n";   } close(\$FILE); If you store each occurrence of the various grades in a hash you can access them like so. Expand|Select|Wrap|Line Numbers # \$keys are the grade and \$values would be the number of occurrences. while (my (\$keys, \$values) = each %scores_count) {     print "\$keys ", ('X' x \$values), "\n"; } --Kevin Mar 24 '08 #6