Explore BrainMass
Share

C++ Numbers Class to Translate Number to English Description

This content was STOLEN from BrainMass.com - View the original, and get the already-completed solution here!

Need help with this C++ program code: Numbers Class
I need the source.cpp code and explanation on how you got it.

Numbers Class

Design a class Numbers that can be used to translate whole dollar amounts in the range 0 through 9999 into an English description of the number. For example, the number 713 would be translated into the string seven hundred thirteen, and 8203 would be translated into eight thousand two hundred three. The class should have a
single integer member variable: int number; and a static array of string objects that specify how to translate key dollar amounts into the desired format. For example, you might use static strings such as string lessThan20[20] = {"zero", "one", ..., "eighteen", "nineteen"}; string hundred = "hundred"; string thousand = "thousand";

The class should have a constructor that accepts a nonnegative integer and uses it to initialize the Numbers object. It should have a member function print() that prints the English description of the Numbers object. Demonstrate the class by writing a main program that asks the user to enter a number in the proper range and then prints out its English description.

Below is how the code would display:

This program translates whole dollar amount into words for the purpose of writing checks.
Entering a negative number terminatesthe program.
Enter an amount for be translated into words:<0-9999>1234
One thousand two hundred thirty four
Enter another number 0-9999:<negative number to stop> -3456
Press any key to continue.........

© BrainMass Inc. brainmass.com October 25, 2018, 9:46 am ad1c9bdddf
https://brainmass.com/computer-science/cpp/c-numbers-class-to-translate-number-to-english-description-585914

Solution Preview

Please go through the attached 585914.cpp thoroughly and read the code along with detailed comments there explaining what is done.

As nothing is specified in your posting, this solution assumes that you do not want conversions reading like "one hundred zero", "one thousand zero", "one thousand one hundred zero", so it is aimed at generating conversions reading like "one hundred", "one thousand", "one thousand one hundred".

Please find the output of a sample run below.

This program translates whole dollar amount into words for the purpose of writing checks.
Entering a negative number terminates ...

Solution Summary

As nothing is specified in the posting, this solution assumes that you want conversions reading like "one hundred", "one thousand", "one thousand one", "one thousand one hundred"; and not like "zero thousand one hundred zero", "one thousand zero hundred zero", "one thousand zero", "one thousand one hundred zero", "one thousand zero hundred one", and so on.

$2.19
See Also This Related BrainMass Solution

productivity based solutions

Microsoft has expended a lot of effort into developing productivity tools for the Web, particularly with the .NET strategy. However, there are many other tools for creating Web solutions, eg. PHP, ColdFusion etc... The .NET strategy is extremely comprehensive, and yet there is always the continuing us versus Microsoft argument. Discuss the merits of adopting such an approach as a business strategy, and do you think it's wise given the enormous productivity gains offered by the .NET solutions? Compare any other productivity based solutions you may have come across in your readings.

Must provide all references.

View Full Posting Details