CS 683 Emerging Technologies

Fall Semester, 2005

Assignment

Assignment Index

© 2005, All Rights Reserved, SDSU & Roger Whitney

 San Diego State University -- This page last updated 11/17/05

Ruby Assignment

Due Nov 29

1 Add the method to_english to the Fixnum class. The method converts numbers under 100 to the english equivalent. So for example we have

11.to_english returns eleven

45.to_english returns forty five

2 Create a OddStack class that has the methods pop and push. The push method throws an exception when its one argument is not an integer. When its one argument is an odd integer, the integer is placed on the stack. When the argument is an even integer, the integer is not placed on the stack and is ignored.

3. Write unit tests for your OddStack.

4 Write an iterator each_word for the String class. The iterator breaks the string into words separated by white space. Don't worry about punctuation. So for example:

'the cat      in the hat'.each_word {| word | puts '->' + word + '<-' }

results in:

->the<-

->cat<-

->in<-

->the<-

->hat<-

5. Let the character a represent 1, b represent 2, c represent 3 etc. The case (upper or lower) does not matter in this problem. The value of a word in the sum of the values of its characters. So 'abc' has the value 6. A dollar word is a word that has value 100. Add the method dollar_word to the string class that returns an array of the dollar words in the string. As in problem 4 words are separated by spaces.