Question
In elementary school, you learned how to express a number in an English word format. For example: the number 1 is spelled as one, 2
In elementary school, you learned how to express a number in an English word format. For example: the number 1 is spelled as one, 2 is two, 3 is three, and so on. In this program, we are going to create a new class called WordedNumber which has the capability to produce a string with the English word of the number it is storing. To make this simple, we will only support the numbers from -999 to 999. If a number is negative, then the number should have negative as a prefix. Example: negative one, negative two hundred twenty three, etc.
Below is a chart of the words to use:
Below 20 Tens
0 zero 10 ten 20 twenty
1 one 11 eleven 30 thirty
2 two 12 twelve 40 forty
3 three 13 thirteen 50 fifty
4 four 14 fourteen 60 sixty
5 five 15 fifteen 70 seventy
6 six 16 sixteen 80 eighty
7 seven 17 seventeen 90 ninety
8 eight 18 eighteen
9 nine 19 nineteen
hundred x + hundred + x
Note: zero should only be used when the value is exactly 0.
Do NOT spell 20 as twenty zero, for example.
Class Design
class WordedNumber
-int number
+
+getNumber(): int
+setNumber(int): bool
+toWord(): string
Description of Methods
constructor either accepts an initial number or defaults to zero. Additionally, rejects any number outside the supported range as described in the instructions.
getNumber returns the numerical version of the number the object is storing.
setNumber sets a new number to be stored. Additionally, rejects any number outside the supported range as described in the instructions.
toWord generates the English word of the number being stored and returns it as a string.
Testing
To test your program, create a WordedNumber object in main. Write a for loop that does the following:
Loop from i = 0 to 999:
Set the WordedNumber objects value to i
Output i + : + conversion to English Word +
For negative numbers, loop from -1 to -999.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started