numbers to words

  • Thread starter Thread starter Frazer
  • Start date Start date
F

Frazer

hi,

I had to write a program in my exam to simulate a
cheque writing utility, that would take numbers as input and give me words
as output.

But i just got 9/10 . my lecturer said i could have used a design pattern.
and made it more efficient.


eg
956.23 should be nine hundred and fifty-six dollars and twenty three cents.

what i did was
had two functions one for single digits
eg 6 returns six

and one for double digits (5 in 2nd place returns fifty)

and then I started reading from the back 6 5 9
passed 6 and 9 to the single digit reader.
and passed 5 to the double digit reader.

and then spit out the output. it works fine. but he said it was inefficient.

how could i have improved this?


Thanx
 
hi,

I had to write a program in my exam to simulate a
cheque writing utility, that would take numbers as input and give me words
as output.

But i just got 9/10 . my lecturer said i could have used a design pattern.
and made it more efficient.


eg
956.23 should be nine hundred and fifty-six dollars and twenty three cents.

what i did was
had two functions one for single digits
eg 6 returns six

and one for double digits (5 in 2nd place returns fifty)

and then I started reading from the back 6 5 9
passed 6 and 9 to the single digit reader.
and passed 5 to the double digit reader.

and then spit out the output. it works fine. but he said it was inefficient.

how could i have improved this?

The only pattern I can think of which would be relevant is the State pattern
from GoF. Read up on that and think how you might apply it.
 
Back
Top