1. Engineering
  2. Computer Science
  3. a ruby program problem ...

Question: a ruby program problem ...

Question details

a ruby program problem


Ruby These short language exercises are intended to help you to explore new languages with differing paradigms and syntax. In this assignment you will complete a Ruby program. I will give you help on where and what to look for in Ruby to assist you. Write a Ruby program to solve the following problem: Open a file that has a list of scores between 0 and 100. There may be as many as 100 scores in the file. The file is plain text and each score is on a separate line. Count the number of each score you find from 0 to 100. After you have counted all the scores, then print out a histogram using 10 buckets of size 10, that is, 0-9, 10-19,..., and 90-100. Then the histogram will print a for each score in the bucket. Example output Count17, Average 72.00, StdDev-15.07 0 . 10 . 20. 30. 40. 50 . 60 . 70 . 80.90.100 The input file scores.txt for this output looks like this 85 72 63 65 92 78 71 73 85 87 29 79 89 72 67 So, you read one score per line. Now you must use Ruby objects to solve this problem (you can do it without but solving the problem is not the point of this exercise). Create a class Histogram with the following methods: initialize(lowScore, hiscore, bucketsize) addScores (file) addScore(score) printWhere lowscore is the lowest score possible, hiscore is the highest possible, and bucketsize is the size of each bucket for the histogram. Using these will allow you to calculate the low and high limits of each bucket for building the histogram. file is the file name for a file that looks like the input above. score is just a single score from a test. The addscores can make use of the addscore method to read in the file scores into the object. The print method requires no parameters and just prints the statistics and histogram as above. You may add other methods as needed for your solution. I didnt need anymore since I kept a count, a sum and a sum of squares as I entered the scores so that I could easily compute the statistics. I used a Ruby array to keep the count in each bucket, which is flexible and dynamic. Explore Ruby and see what you can do to solve this program. Finally, here is what my program looks like after creating the Histogram class main h-Histogram.new h.addScores(scores.txt) h.print

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution